SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.

Removed the XSD enumeration restriction on the 'action' attribute of the 'expirationType' XSD complex-type definition used by the 'region-ttl', 'region-tti', 'entry-ttl', and 'entry-tti' elements in the 'baseReadOnlyRegionType' inside the Spring GemFire XML Schema (XSD).
This commit is contained in:
John Blum
2014-12-09 16:27:25 -08:00
parent 4a1a3bf64d
commit 844c630614
6 changed files with 334 additions and 49 deletions

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import com.gemstone.gemfire.cache.ExpirationAction;
/**
* The ExpirationActionType enum is a enumeration of GemFire Expiration Actions on expired Cache Region entries.
*
* @author John Blum
* @see com.gemstone.gemfire.cache.ExpirationAction
* @since 1.6.0
*/
@SuppressWarnings("unused")
public enum ExpirationActionType {
DESTROY(ExpirationAction.DESTROY),
INVALIDATE(ExpirationAction.INVALIDATE),
LOCAL_DESTROY(ExpirationAction.LOCAL_DESTROY),
LOCAL_INVALIDATE(ExpirationAction.LOCAL_INVALIDATE);
private final ExpirationAction expirationAction;
/**
* Constructs an instance of the ExpirationActionType enum initialized with the corresponding GemFire
* ExpirationAction value.
*
* @param expirationAction the GemFire ExpirationAction value.
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
ExpirationActionType(final ExpirationAction expirationAction) {
this.expirationAction = expirationAction;
}
/**
* Returns the corresponding SDG ExpirationActionType enumerated value given a GemFire ExpirationAction.
*
* @param expirationAction the GemFire ExpirationAction instance used to determine the ExpirationActionType.
* @return a ExpirationActionType enumerated value given a GemFire ExpirationAction.
* @see com.gemstone.gemfire.cache.ExpirationAction
* @see #getExpirationAction()
*/
public static ExpirationActionType valueOf(final ExpirationAction expirationAction) {
for (ExpirationActionType expirationActionType : values()) {
if (expirationActionType.getExpirationAction().equals(expirationAction)) {
return expirationActionType;
}
}
return null;
}
/**
* Returns an ExpirationActionType for the given String value describing the enumerated value.
*
* @param value a String value describing the desired ExpirationActionType that is returned.
* @return an ExpirationActionType for the given String.
* @see java.lang.Enum#name()
* @see java.lang.String#equalsIgnoreCase(String)
*/
public static ExpirationActionType valueOfIgnoreCase(final String value) {
for (ExpirationActionType expirationActionType : values()) {
if (expirationActionType.name().equalsIgnoreCase(value)) {
return expirationActionType;
}
}
return null;
}
/**
* Gets the corresponding GemFire ExpirationAction for this enumerated value.
*
* @return a GemFire ExpirationAction instance corresponding to this enumerated value.
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
public ExpirationAction getExpirationAction() {
return expirationAction;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import java.beans.PropertyEditorSupport;
import org.springframework.core.convert.converter.Converter;
/**
* The ExpirationActionTypeConverter class is a Spring Converter used to convert a String value into
* a corresponding ExpirationActionType enumerated value.
*
* @author John Blum
* @see java.beans.PropertyEditorSupport
* @see org.springframework.core.convert.converter.Converter
* @see org.springframework.data.gemfire.ExpirationActionType
* @since 1.6.0
*/
public class ExpirationActionTypeConverter extends PropertyEditorSupport implements Converter<String, ExpirationActionType> {
/* non-Javadoc */
private ExpirationActionType assertConverted(final String source, final ExpirationActionType expirationActionType) {
if (expirationActionType == null) {
throw new IllegalArgumentException(String.format("Source (%1$s) is not a valid ExpirationActionType!",
source));
}
return expirationActionType;
}
/**
* Sets the ExpirationActionType by parsing a given String. May raise a java.lang.IllegalArgumentException
* if either the String is badly formatted or the text cannot be expressed as a ExpirationActionType.
*
* @param text the String value to express as (convert to) a ExpirationActionType.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid ExpirationActionType.
* @see #convert(String)
* @see #setValue(Object)
*/
@Override
public void setAsText(final String text) throws IllegalArgumentException {
setValue(convert(text));
}
/**
* Converts the given String value into an appropriate ExpirationActionType.
*
* @param source the String value to convert into an ExpirationActionType.
* @return an ExpirationActionType for the given String value.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid ExpirationActionType.
* @see org.springframework.data.gemfire.ExpirationActionType#valueOfIgnoreCase(String)
*/
@Override
public ExpirationActionType convert(final String source) {
return assertConverted(source, ExpirationActionType.valueOfIgnoreCase(source));
}
}

View File

@@ -27,6 +27,8 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.core.Conventions;
import org.springframework.data.gemfire.EvictionAttributesFactoryBean;
import org.springframework.data.gemfire.EvictionType;
import org.springframework.data.gemfire.ExpirationActionType;
import org.springframework.data.gemfire.ExpirationActionTypeConverter;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.SubscriptionAttributesFactoryBean;
import org.springframework.data.gemfire.SubscriptionType;
@@ -290,6 +292,7 @@ abstract class ParsingUtils {
// turn on statistics
regionAttributesBuilder.addPropertyValue("statisticsEnabled", Boolean.TRUE);
}
return result;
}
@@ -380,24 +383,13 @@ abstract class ParsingUtils {
if (expirationElement != null) {
String timeoutAttribute = expirationElement.getAttribute("timeout");
String expirationTimeout = (StringUtils.hasText(timeoutAttribute) ? timeoutAttribute : null);
String expirationTimeout = (StringUtils.hasText(timeoutAttribute) ? timeoutAttribute : "0");
String actionAttribute = StringUtils.trimAllWhitespace(expirationElement.getAttribute("action"));
ExpirationAction expirationAction;
// TODO refactor this using an Enum and ExpirationActionConverter!
if ("DESTROY".equalsIgnoreCase(actionAttribute)) {
expirationAction = ExpirationAction.DESTROY;
}
else if ("LOCAL_DESTROY".equalsIgnoreCase(actionAttribute)) {
expirationAction = ExpirationAction.LOCAL_DESTROY;
}
else if ("LOCAL_INVALIDATE".equalsIgnoreCase(actionAttribute)) {
expirationAction = ExpirationAction.LOCAL_INVALIDATE;
}
else {
expirationAction = ExpirationAction.INVALIDATE;
}
ExpirationActionType expirationActionType = new ExpirationActionTypeConverter().convert(actionAttribute);
ExpirationAction expirationAction = (expirationActionType != null
? expirationActionType.getExpirationAction() : ExpirationAction.INVALIDATE);
BeanDefinitionBuilder expirationAttributes = BeanDefinitionBuilder.genericBeanDefinition(
ExpirationAttributes.class);