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

Removed the 'evictionActionType' XSD simple-type definition and subsequently, all EvictionAction enumeration restrictions on all SDG Region element types in the SDG XML namespace (e.g. gfe:partitioned-region) that define and declare an eviction policy and corresponding 'action'.  In addition, performed refactoring and cleanup on serveral new SDG enumeration types, like EvictionType and ExpirationActionType, along with the corresponding Converter implementations and bean properties on their respective FactoryBeans (EvictionAttributesFactoryBean and ExpirationAttributesFactoryBean).
This commit is contained in:
John Blum
2015-01-22 21:53:58 -08:00
parent 3f72ab8928
commit 319442b446
22 changed files with 767 additions and 300 deletions

View File

@@ -47,6 +47,8 @@ import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.DynamicRegionFactory;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.TransactionListener;
import com.gemstone.gemfire.cache.TransactionWriter;
@@ -914,8 +916,9 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) getBeanFactory();
beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class);
beanFactory.registerCustomEditor(EvictionType.class, EvictionTypeConverter.class);
beanFactory.registerCustomEditor(ExpirationActionType.class, ExpirationActionTypeConverter.class);
beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class);
beanFactory.registerCustomEditor(IndexMaintenanceType.class, IndexMaintenanceTypeConverter.class);
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
beanFactory.registerCustomEditor(SubscriptionType.class, SubscriptionTypeConverter.class);

View File

@@ -0,0 +1,51 @@
/*
* 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 org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
import com.gemstone.gemfire.cache.EvictionAction;
/**
* The EvictionActionConverter class is a Spring Converter and JavaBeans PropertyEditor that converts
* an Object value into an instance of GemFire EvictionAction.
*
* @author John Blum
* @see org.springframework.data.gemfire.EvictionActionType
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
* @see com.gemstone.gemfire.cache.EvictionAction
* @since 1.6.0
*/
@SuppressWarnings("unused")
public class EvictionActionConverter extends AbstractPropertyEditorConverterSupport<EvictionAction> {
/**
* Converts the given String into a GemFire EvictionAction value.
*
* @param source the String to convert.
* @return the GemFire EvictionAction value matching the given String.
* @throws java.lang.IllegalArgumentException if the String could not be converted into
* an instance of GemFire EvictionAction.
* @see com.gemstone.gemfire.cache.EvictionAction
*/
@Override
public EvictionAction convert(final String source) {
return assertConverted(source, EvictionActionType.getEvictionAction(
EvictionActionType.valueOfIgnoreCase(source)), EvictionAction.class);
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.EvictionAction;
/**
* The EvictionActionType enum is an enumeration of all the GemFire EvictionAction values.
*
* @author John Blum
* @see com.gemstone.gemfire.cache.EvictionAction
* @since 1.6.0
*/
@SuppressWarnings("unused")
public enum EvictionActionType {
LOCAL_DESTROY(EvictionAction.LOCAL_DESTROY),
NONE(EvictionAction.NONE),
OVERFLOW_TO_DISK(EvictionAction.OVERFLOW_TO_DISK);
public static final EvictionActionType DEFAULT = EvictionActionType.valueOf(EvictionAction.DEFAULT_EVICTION_ACTION);
private final EvictionAction evictionAction;
/**
* Constructs an instance of the EvictionActionType enum initialized with the matching GemFire EvictionAction.
*
* @param evictionAction the matching GemFire EvictionAction value for this enumerated value.
* @see com.gemstone.gemfire.cache.EvictionAction
*/
EvictionActionType(final EvictionAction evictionAction) {
this.evictionAction = evictionAction;
}
/**
* A null-safe operation to extract the GemFire EvictionAction from the EvictionActionType enumerated value.
*
* @param evictionActionType the EvictionActionType enumerated value from which to extract
* the matching GemFire EvictionAction value.
* @return a GemFire EvictionAction given a EvictionActionType enumerated value.
* @see #getEvictionAction()
*/
public static EvictionAction getEvictionAction(final EvictionActionType evictionActionType) {
return (evictionActionType != null ? evictionActionType.getEvictionAction() : null);
}
/**
* Returns an EvictionActionType enumerated value matching the given GemFire EvictionAction.
*
* @param evictionAction the GemFire EvictionAction used to lookup and match the appropriate EvictionActionType.
* @return an EvictionActionType enumerated value matching the given GemFire EvictionAction
* or null if no match was found.
* @see com.gemstone.gemfire.cache.EvictionAction
* @see #getEvictionAction()
*/
public static EvictionActionType valueOf(final EvictionAction evictionAction) {
for (EvictionActionType evictionActionType : values()) {
if (evictionActionType.getEvictionAction().equals(evictionAction)) {
return evictionActionType;
}
}
return null;
}
/**
* Returns an EvictionActionType enumerated value given the named, case-insensitive eviction action.
*
* @param name a String value indicating the name the eviction action used to match EvictionActionType.
* @return an EvictionActionType enumerated value matching the given named, case-insensitive eviction action
* or null if not match was found.
* @see java.lang.String#equalsIgnoreCase(String)
* @see #name()
*/
public static EvictionActionType valueOfIgnoreCase(final String name) {
for (EvictionActionType evictionActionType : values()) {
if (evictionActionType.name().equalsIgnoreCase(name)) {
return evictionActionType;
}
}
return null;
}
/**
* Gets the matching GemFire EvictionAction represented by this enumerated value.
*
* @return the GemFire EvictionAction represented by this enum.
* @see com.gemstone.gemfire.cache.EvictionAction
*/
public EvictionAction getEvictionAction() {
return evictionAction;
}
}

View File

@@ -54,7 +54,6 @@ public class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttrib
private ObjectSizer objectSizer = null;
public void afterPropertiesSet() {
this.action = (this.action != null ? action : EvictionAction.DEFAULT_EVICTION_ACTION);
evictionAttributes = createAttributes();
}
@@ -62,86 +61,113 @@ public class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttrib
switch (type) {
case HEAP_PERCENTAGE:
if (threshold != null) {
throw new IllegalArgumentException(
"The HEAP_PERCENTAGE (LRU_HEAP algorithm) does not support threshold (a.k.a. maximum)!");
throw new IllegalArgumentException("HEAP_PERCENTAGE (LRU_HEAP algorithm) does not support threshold (a.k.a. maximum)!");
}
return EvictionAttributes.createLRUHeapAttributes(objectSizer, action);
return EvictionAttributes.createLRUHeapAttributes(getObjectSizer(), getAction());
case MEMORY_SIZE:
return (threshold != null ? EvictionAttributes.createLRUMemoryAttributes(threshold, objectSizer, action)
: EvictionAttributes.createLRUMemoryAttributes(objectSizer, action));
return (threshold != null ? EvictionAttributes.createLRUMemoryAttributes(getThreshold(), getObjectSizer(), getAction())
: EvictionAttributes.createLRUMemoryAttributes(getObjectSizer(), getAction()));
case ENTRY_COUNT:
default:
return (threshold != null ? EvictionAttributes.createLRUEntryAttributes(threshold, action)
: EvictionAttributes.createLRUEntryAttributes(DEFAULT_LRU_MAXIMUM_ENTRIES, action));
return (threshold != null ? EvictionAttributes.createLRUEntryAttributes(getThreshold(), getAction())
: EvictionAttributes.createLRUEntryAttributes(DEFAULT_LRU_MAXIMUM_ENTRIES, getAction()));
}
}
/* non-Javadoc */
public EvictionAttributes getObject() {
return evictionAttributes;
}
/* non-Javadoc */
public Class<?> getObjectType() {
return (evictionAttributes != null ? evictionAttributes.getClass() : EvictionAttributes.class);
}
/* non-Javadoc */
public boolean isSingleton() {
return true;
}
/**
* @return the action
* Sets the action to perform on the Region when Eviction occurs.
*
* @param action the specified EvictionAction taken on the Region.
* @see com.gemstone.gemfire.cache.EvictionAction
*/
public EvictionAction getAction() {
return action;
}
/**
* @param action the action to set
*/
public void setAction(EvictionAction action) {
public void setAction(final EvictionAction action) {
this.action = action;
}
/**
* @return the objectSizer
* Gets the action performed on the Region when Eviction occurs.
*
* @return the EvictionAction taken on the Region.
* @see com.gemstone.gemfire.cache.EvictionAction
*/
public EvictionAction getAction() {
return (action != null ? action : EvictionAction.DEFAULT_EVICTION_ACTION);
}
/**
* Sets the GemFire ObjectSizer used in determining object sizes of data stored in the Cache.
*
* @param objectSizer the ObjectSizer used in sizing object data stored in the Cache.
* @see com.gemstone.gemfire.cache.util.ObjectSizer
*/
public void setObjectSizer(final ObjectSizer objectSizer) {
this.objectSizer = objectSizer;
}
/**
* Gets the GemFire ObjectSizer used in determining object sizes of data stored in the Cache.
*
* @return the ObjectSizer used in sizing object data stored in the Cache.
* @see com.gemstone.gemfire.cache.util.ObjectSizer
*/
public ObjectSizer getObjectSizer() {
return objectSizer;
}
/**
* @param objectSizer the objectSizer to set
* Set the threshold used by the LRU algorithm in ENTRY_COUNT and MEMORY_SIZE eviction policy.
*
* @param threshold an Integer value specifying the threshold used by the LRU algorithm
* when enforcing the eviction policy.
*/
public void setObjectSizer(ObjectSizer objectSizer) {
this.objectSizer = objectSizer;
public void setThreshold(final Integer threshold) {
this.threshold = threshold;
}
/**
* @return the threshold
* Get the threshold used by the LRU algorithm in ENTRY_COUNT and MEMORY_SIZE eviction policy.
*
* @return an Integer value specifying the threshold used by the LRU algorithm when enforcing the eviction policy.
*/
public Integer getThreshold() {
return threshold;
}
/**
* @param threshold the threshold to set
* Sets the type of eviction policy and algorithm (e.g. LRU on Entry Count, Heap % or Memory Size)
* to implement on the Region.
*
* @param type the type of eviction policy/algorithm to implement on the Region.
* @see org.springframework.data.gemfire.EvictionType
*/
public void setThreshold(Integer threshold) {
this.threshold = threshold;
public void setType(final EvictionType type) {
this.type = type;
}
/**
* @return the type
* Gets the eviction policy and algorithm used by the Region.
*
* @return the eviction policy and algorithm in use by the Region.
* @see org.springframework.data.gemfire.EvictionType
*/
public EvictionType getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(EvictionType type) {
this.type = type;
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.data.gemfire;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
/**
* Simple enumeration for the various GemFire Eviction types.
* The EvictionType enum is an enumeration of all GemFire Eviction policy types.
*
* @author Costin Leau
* @author John Blum
@@ -35,10 +35,9 @@ public enum EvictionType {
private final EvictionAlgorithm evictionAlgorithm;
/**
* Constructs an instance (enumeration) of the EvictionType enumerated type initialized with the corresponding
* GemFire EvictionAlgorithm.
* Constructs an instance of the EvictionType enum initialized with the matching GemFire EvictionAlgorithm.
*
* @param evictionAlgorithm the GemFire EvictionAlgorithm represented by this EvictionType.
* @param evictionAlgorithm the GemFire EvictionAlgorithm represented by this EvictionType enumerated value.
* @see com.gemstone.gemfire.cache.EvictionAlgorithm
*/
EvictionType(final EvictionAlgorithm evictionAlgorithm) {
@@ -46,13 +45,23 @@ public enum EvictionType {
}
/**
* Returns the corresponding SDG EvictionType enumerated value for the GemFire EvictionAlgorithm.
* A null-safe operation to extract the GemFire EvictionAlgorithm from the given EvictionType enumerated value.
*
* @param evictionAlgorithm the GemFire EvictionAlgorithm used to lookup the corresponding EvictionType.
* @return a EvictionType representing the specified GemFire EvictionAlgorithm. Returns null if no EvictionType
* represents the given GemFire EvictionAlgorithm.
* @param evictionType the EvictionType from which to extract the GemFire EvictionAlgorithm.
* @return the GemFire EvictionAlgorithm for the corresponding EvictionType or null if evictionType is null.
* @see #getEvictionAlgorithm()
*/
public static EvictionAlgorithm getEvictionAlgorithm(final EvictionType evictionType) {
return (evictionType != null ? evictionType.getEvictionAlgorithm() : null);
}
/**
* Returns an EvictionType enumerated value matching the given GemFire EvictionAlgorithm.
*
* @param evictionAlgorithm the GemFire EvictionAlgorithm used to lookup and match the EvictionType.
* @return an EvictionType matching the specified GemFire EvictionAlgorithm or null if no match was found.
* @see com.gemstone.gemfire.cache.EvictionAlgorithm
* @see #getEvictionAlgorithm()
*/
public static EvictionType valueOf(final EvictionAlgorithm evictionAlgorithm) {
for (EvictionType evictionType : values()) {
@@ -65,15 +74,16 @@ public enum EvictionType {
}
/**
* Returns an EvictionType enumerated value for the given, named EvictionType, ignoring case.
* Returns an EvictionType enumerated value given the named, case-insensitive eviction policy.
*
* @param value a String value indicating the name of the desired EvictionType enumerated value.
* @return an EvictionType corresponding to the given, named enumerated value.
* @see java.lang.Enum#name()
* @param name a String indicating the name of the eviction policy used to match EvictionType.
* @return an EvictionType matching the given the named, case-insensitive eviction policy.
* @see java.lang.String#equalsIgnoreCase(String)
* @see #name()
*/
public static EvictionType valueOfIgnoreCase(final String value) {
public static EvictionType valueOfIgnoreCase(final String name) {
for (EvictionType evictionType : values()) {
if (evictionType.name().equalsIgnoreCase(value)) {
if (evictionType.name().equalsIgnoreCase(name)) {
return evictionType;
}
}
@@ -84,7 +94,7 @@ public enum EvictionType {
/**
* Gets the GemFire EvictionAlgorithm represented by this enumerated value.
*
* @return the corresponding GemFire EvictionAlgorithm.
* @return the GemFire EvictionAlgorithm represented by this enum.
* @see com.gemstone.gemfire.cache.EvictionAlgorithm
*/
public EvictionAlgorithm getEvictionAlgorithm() {

View File

@@ -16,54 +16,31 @@
package org.springframework.data.gemfire;
import java.beans.PropertyEditorSupport;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.Assert;
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
/**
* The EvictionTypeConverter class is a Spring Converter used to convert a String value into
* a corresponding EvictionType enumerated value.
*
* @author John Blum
* @see java.beans.PropertyEditorSupport
* @see org.springframework.core.convert.converter.Converter
* @see org.springframework.data.gemfire.EvictionType
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
* @since 1.6.0
*/
public class EvictionTypeConverter extends PropertyEditorSupport implements Converter<String, EvictionType> {
/* non-javadoc */
private EvictionType assertConverted(final String source, final EvictionType evictionType) {
Assert.notNull(evictionType, String.format("Source (%1$s) is not a valid EvictionType!", source));
return evictionType;
}
public class EvictionTypeConverter extends AbstractPropertyEditorConverterSupport<EvictionType> {
/**
* Converts the given String value into an appropriate ExpirationActionType.
* Converts the given String into a matching EvictionType.
*
* @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.
* @param source the String value to convert into an EvictionType.
* @return the EvictionType matching the given String.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid EvictionType.
* @see org.springframework.data.gemfire.EvictionType#valueOfIgnoreCase(String)
* @see #assertConverted(String, Object, Class)
*/
@Override
public EvictionType convert(final String source) {
return assertConverted(source, EvictionType.valueOfIgnoreCase(source));
}
/**
* Sets the EvictionType by parsing the given text String. May throw a java.lang.IllegalArgumentException
* if either the text is badly formatted or the text cannot be expressed as an EvictionType.
*
* @param text the String value to express as (convert to) an EvictionType.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid EvictionType.
* @see #convert(String)
* @see #setValue(Object)
*/
@Override
public void setAsText(final String text) throws IllegalArgumentException {
setValue(convert(text));
return assertConverted(source, EvictionType.valueOfIgnoreCase(source), EvictionType.class);
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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 org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
import com.gemstone.gemfire.cache.ExpirationAction;
/**
* 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 ExpirationActionConverter extends AbstractPropertyEditorConverterSupport<ExpirationAction> {
/**
* Converts the given String into an appropriate GemFire ExpirationAction.
*
* @param source the String to convert into an GemFire ExpirationAction.
* @return an GemFire ExpirationAction value for the given String.
* @throws java.lang.IllegalArgumentException if the String is not a valid GemFire ExpirationAction.
* @see org.springframework.data.gemfire.ExpirationActionType#valueOfIgnoreCase(String)
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
@Override
public ExpirationAction convert(final String source) {
return assertConverted(source, ExpirationActionType.getExpirationAction(
ExpirationActionType.valueOfIgnoreCase(source)), ExpirationAction.class);
}
}

View File

@@ -19,7 +19,7 @@ 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.
* The ExpirationActionType enum is a enumeration of GemFire ExpirationActions on expired Cache Region entries.
*
* @author John Blum
* @see com.gemstone.gemfire.cache.ExpirationAction
@@ -37,10 +37,9 @@ public enum ExpirationActionType {
private final ExpirationAction expirationAction;
/**
* Constructs an instance of the ExpirationActionType enum initialized with the corresponding GemFire
* ExpirationAction value.
* Constructs an instance of the ExpirationActionType enum initialized with the matching GemFire ExpirationAction.
*
* @param expirationAction the GemFire ExpirationAction value.
* @param expirationAction the matching GemFire ExpirationAction for this enumerated value.
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
ExpirationActionType(final ExpirationAction expirationAction) {
@@ -48,10 +47,23 @@ public enum ExpirationActionType {
}
/**
* Returns the corresponding SDG ExpirationActionType enumerated value given a GemFire ExpirationAction.
* A null-safe operation to extract the corresponding GemFire ExpirationAction for the ExpirationActionType.
*
* @param expirationAction the GemFire ExpirationAction instance used to determine the ExpirationActionType.
* @return a ExpirationActionType enumerated value given a GemFire ExpirationAction.
* @param expirationActionType the ExpirationActionType enumerated value from which to extract
* the corresponding GemFire ExpirationAction.
* @return a GemFire ExpirationAction given the ExpirationActionType enumerated value.
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
public static ExpirationAction getExpirationAction(final ExpirationActionType expirationActionType) {
return (expirationActionType != null ? expirationActionType.getExpirationAction() : null);
}
/**
* Returns the ExpirationActionType enumerated value matching the given GemFire ExpirationAction.
*
* @param expirationAction the GemFire ExpirationAction used to match the ExpirationActionType.
* @return a matching ExpirationActionType enumerated value given a GemFire ExpirationAction
* or null if no match was found.
* @see com.gemstone.gemfire.cache.ExpirationAction
* @see #getExpirationAction()
*/
@@ -66,16 +78,17 @@ public enum ExpirationActionType {
}
/**
* Returns an ExpirationActionType for the given String value describing the enumerated value.
* Returns an ExpirationActionType enumerated value given a named, case-insensitive expiration action.
*
* @param value a String value describing the desired ExpirationActionType that is returned.
* @return an ExpirationActionType for the given String.
* @see java.lang.Enum#name()
* @param name a String name for the expiration action matching the ExpirationActionType.
* @return a matching ExpirationActionType for the named, case-insensitive expiration action
* or null if no match could be found.
* @see java.lang.String#equalsIgnoreCase(String)
* @see #name()
*/
public static ExpirationActionType valueOfIgnoreCase(final String value) {
public static ExpirationActionType valueOfIgnoreCase(final String name) {
for (ExpirationActionType expirationActionType : values()) {
if (expirationActionType.name().equalsIgnoreCase(value)) {
if (expirationActionType.name().equalsIgnoreCase(name)) {
return expirationActionType;
}
}
@@ -84,9 +97,9 @@ public enum ExpirationActionType {
}
/**
* Gets the corresponding GemFire ExpirationAction for this enumerated value.
* Gets the matching GemFire ExpirationAction for this enumerated value.
*
* @return a GemFire ExpirationAction instance corresponding to this enumerated value.
* @return the GemFire ExpirationAction instance corresponding to this enumerated value.
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
public ExpirationAction getExpirationAction() {

View File

@@ -1,72 +0,0 @@
/*
* 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

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
/**
@@ -37,14 +38,15 @@ public class ExpirationAttributesFactoryBean implements FactoryBean<ExpirationAt
protected static final int DEFAULT_TIMEOUT = 0;
protected static final ExpirationActionType DEFAULT_EXPIRATION_ACTION = ExpirationActionType.DEFAULT;
protected static final ExpirationAction DEFAULT_EXPIRATION_ACTION =
ExpirationActionType.DEFAULT.getExpirationAction();
private ExpirationAction action;
private ExpirationAttributes expirationAttributes;
private Integer timeout;
private ExpirationActionType action;
/* non-Javadoc */
@Override
public ExpirationAttributes getObject() throws Exception {
@@ -67,9 +69,9 @@ public class ExpirationAttributesFactoryBean implements FactoryBean<ExpirationAt
* Sets the action to perform when a Region or an Entry expire.
*
* @param action the type of action to perform on expiration
* @see org.springframework.data.gemfire.ExpirationActionType
* @see com.gemstone.gemfire.cache.ExpirationAction
*/
public void setAction(ExpirationActionType action) {
public void setAction(final ExpirationAction action) {
this.action = action;
}
@@ -80,7 +82,7 @@ public class ExpirationAttributesFactoryBean implements FactoryBean<ExpirationAt
* @see org.springframework.data.gemfire.ExpirationActionType
* @see com.gemstone.gemfire.cache.ExpirationAttributes#getAction()
*/
public ExpirationActionType getAction() {
public ExpirationAction getAction() {
return (action != null ? action : DEFAULT_EXPIRATION_ACTION);
}
@@ -114,7 +116,7 @@ public class ExpirationAttributesFactoryBean implements FactoryBean<ExpirationAt
*/
@Override
public void afterPropertiesSet() throws Exception {
expirationAttributes = new ExpirationAttributes(getTimeout(), getAction().getExpirationAction());
expirationAttributes = new ExpirationAttributes(getTimeout(), getAction());
}
}

View File

@@ -26,8 +26,6 @@ import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.core.Conventions;
import org.springframework.data.gemfire.EvictionAttributesFactoryBean;
import org.springframework.data.gemfire.ExpirationActionType;
import org.springframework.data.gemfire.ExpirationActionTypeConverter;
import org.springframework.data.gemfire.ExpirationAttributesFactoryBean;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.SubscriptionAttributesFactoryBean;
@@ -36,8 +34,6 @@ import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.LossAction;
import com.gemstone.gemfire.cache.MembershipAttributes;
import com.gemstone.gemfire.cache.ResumptionAction;
@@ -197,19 +193,14 @@ abstract class ParsingUtils {
setPropertyValue(evictionElement, evictionAttributesBuilder, "action");
setPropertyValue(evictionElement, evictionAttributesBuilder, "threshold");
String typeAttributeValue = evictionElement.getAttribute("type");
if (StringUtils.hasText(typeAttributeValue)) {
evictionAttributesBuilder.addPropertyValue("type", StringUtils.trimWhitespace(typeAttributeValue));
}
setPropertyValue(evictionElement, evictionAttributesBuilder, "type");
Element objectSizerElement = DomUtils.getChildElementByTagName(evictionElement, "object-sizer");
if (objectSizerElement != null) {
Object sizer = parseRefOrNestedBeanDeclaration(parserContext, objectSizerElement,
evictionAttributesBuilder);
evictionAttributesBuilder.addPropertyValue("ObjectSizer", sizer);
evictionAttributesBuilder.addPropertyValue("objectSizer", sizer);
}
regionAttributesBuilder.addPropertyValue("evictionAttributes",
@@ -384,14 +375,11 @@ abstract class ParsingUtils {
Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
if (expirationElement != null) {
String actionAttributeValue = expirationElement.getAttribute("action");
String timeoutAttributeValue = expirationElement.getAttribute("timeout");
BeanDefinitionBuilder expirationAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
ExpirationAttributesFactoryBean.class);
expirationAttributesBuilder.addPropertyValue("action", actionAttributeValue);
expirationAttributesBuilder.addPropertyValue("timeout", timeoutAttributeValue);
setPropertyValue(expirationElement, expirationAttributesBuilder, "action");
setPropertyValue(expirationElement, expirationAttributesBuilder, "timeout");
regionAttributesBuilder.addPropertyValue(propertyName, expirationAttributesBuilder.getBeanDefinition());
return true;

View File

@@ -0,0 +1,66 @@
/*
* 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.support;
import java.beans.PropertyEditorSupport;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.Assert;
/**
* The AbstractPropertyEditorConverterSupport class is an abstract base class for Spring Converter implementations
* that also implement the JavaBeans PropertyEditor interface.
*
* @author John Blum
* @see java.beans.PropertyEditorSupport
* @see org.springframework.core.convert.converter.Converter
* @since 1.6.0
*/
@SuppressWarnings("unused")
public abstract class AbstractPropertyEditorConverterSupport<T> extends PropertyEditorSupport
implements Converter<String, T> {
/**
* Asserts that the given String was successfully converted into an instance of Class type T.
*
* @param source the String to convert.
* @param convertedValue the value of the String converted into instance of Class type T.
* @param type the target Class type of the converted value.
* @return the converted value of Class type T if not null.
* @throws java.lang.IllegalArgumentException if the String could not be converted into
* an instance of Class type T.
*/
protected T assertConverted(final String source, final T convertedValue, final Class<T> type) {
Assert.notNull(convertedValue, String.format("(%1$s) is not a valid %2$s!", source, type.getSimpleName()));
return convertedValue;
}
/**
* Sets the value of this PropertyEditor with the given String converted to the appropriate Class type.
*
* @param text the String to convert.
* @throws java.lang.IllegalArgumentException if the String could not be converted into
* an instance of Class type T.
* @see #convert(Object)
* @see #setValue(Object)
*/
@Override
public void setAsText(final String text) throws IllegalArgumentException {
setValue(convert(text));
}
}