SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the 'subscriptionPolicyType' XSD simple-type definition and subsequently, all Subscription policy enumeration restrictions on SDG Region elements in the SDG XML namespace (e.g. gfe:partitioned-region) that declare and define a Subscription policy. Renamed SubscriptionType to InterestPolicyType along with the associated test suite class. Renamed the SubscriptionTypeConverter class to InterestPolicyConverter along with the associated test suite class. Created the RegionSubscriptionAttributesNamespaceTest class to test the configuration of Subscription on GemFire Regions in the SDG XML namespace using various settings and property placeholders.
This commit is contained in:
@@ -50,6 +50,7 @@ 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.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.TransactionListener;
|
||||
import com.gemstone.gemfire.cache.TransactionWriter;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
@@ -921,7 +922,7 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
|
||||
beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexMaintenanceType.class, IndexMaintenanceTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(SubscriptionType.class, SubscriptionTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.InterestPolicy;
|
||||
|
||||
/**
|
||||
* The InterestPolicyConverter class is a Spring Converter implementation and Java PropertyEditor handling
|
||||
* the conversion between Strings and GemFire InterestPolicy values.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class InterestPolicyConverter extends AbstractPropertyEditorConverterSupport<InterestPolicy> {
|
||||
|
||||
/**
|
||||
* Converts the given String into a GemFire InterestPolicy value.
|
||||
*
|
||||
* @param source the String value to convert into a GemFire InterestPolicy value.
|
||||
* @return a GemFire InterestPolicy value for the given String description of the GemFire InterestPolicy
|
||||
* @throws java.lang.IllegalArgumentException if the String is not a valid GemFire InterestPolicy.
|
||||
* @see org.springframework.data.gemfire.InterestPolicyType#getInterestPolicy(InterestPolicyType)
|
||||
* @see org.springframework.data.gemfire.InterestPolicyType#valueOfIgnoreCase(String)
|
||||
* @see #assertConverted(String, Object, Class)
|
||||
*/
|
||||
@Override
|
||||
public InterestPolicy convert(final String source) {
|
||||
return assertConverted(source, InterestPolicyType.getInterestPolicy(
|
||||
InterestPolicyType.valueOfIgnoreCase(source)), InterestPolicy.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.InterestPolicy;
|
||||
|
||||
/**
|
||||
* The InterestPolicyType enum is an enumeration of all the GemFire Subscription, InterestPolicy values.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum InterestPolicyType {
|
||||
ALL(InterestPolicy.ALL),
|
||||
CACHE_CONTENT(InterestPolicy.CACHE_CONTENT);
|
||||
|
||||
public static final InterestPolicyType DEFAULT = InterestPolicyType.valueOf(InterestPolicy.DEFAULT);
|
||||
|
||||
private final InterestPolicy interestPolicy;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the SubscriptionType enum initialized with the matching GemFire InterestPolicy.
|
||||
*
|
||||
* @param interestPolicy a GemFire InterestPolicy corresponding to this SubscriptionType.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
*/
|
||||
InterestPolicyType(final InterestPolicy interestPolicy) {
|
||||
this.interestPolicy = interestPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe operation to extract the GemFire InterestPolicy from the InterPolicyType enumerated value.
|
||||
*
|
||||
* @param interestPolicyType the InterestPolicyType enum from which to extract GemFire's InterestPolicy
|
||||
* @return a GemFire InterestPolicy for the given InterestPolicyType enumerated value
|
||||
* or null if InterestPolicyType is null.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
*/
|
||||
public static InterestPolicy getInterestPolicy(final InterestPolicyType interestPolicyType) {
|
||||
return (interestPolicyType != null ? interestPolicyType.getInterestPolicy() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SubscriptionType enumerated value for the given GemFire InterestPolicy.
|
||||
*
|
||||
* @param interestPolicy the GemFire InterestPolicy used to lookup and match a SubscriptionType.
|
||||
* @return a SubscriptionType enumerated value matching the given GemFire InterestPolicy
|
||||
* or null if no matching value was found.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @see #getInterestPolicy()
|
||||
*/
|
||||
public static InterestPolicyType valueOf(final InterestPolicy interestPolicy) {
|
||||
for (InterestPolicyType interestPolicyType : values()) {
|
||||
if (interestPolicyType.getInterestPolicy().equals(interestPolicy)) {
|
||||
return interestPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SubscriptionType enumerated value for the case-insensitive, named Subscription (InterestsPolicy).
|
||||
*
|
||||
* @param value a String name used to look and match the SubscriptionType.
|
||||
* @return a SubscriptionType enumerated value for the given case-insensitive named Subscription
|
||||
* or null if no match was found.
|
||||
* @see java.lang.String#equalsIgnoreCase(String)
|
||||
* @see #name()
|
||||
*/
|
||||
public static InterestPolicyType valueOfIgnoreCase(final String value) {
|
||||
for (InterestPolicyType interestPolicyType : values()) {
|
||||
if (interestPolicyType.name().equalsIgnoreCase(value)) {
|
||||
return interestPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GemFire InterestPolicy corresponding to this SubscriptionType enumerated value.
|
||||
*
|
||||
* @return the GemFire InterestPolicy corresponding to this SubscriptionType.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
*/
|
||||
public InterestPolicy getInterestPolicy() {
|
||||
return interestPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,24 +22,31 @@ import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
|
||||
/**
|
||||
* Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans.
|
||||
* The SubscriptionAttributesFactoryBean class is a Spring FactoryBean used for defining and constructing
|
||||
* a GemFire SubscriptionAttributes object, which determines the Subscription policy used by Regions to
|
||||
* declared their data interests.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @see com.gemstone.gemfire.cache.SubscriptionAttributes
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class SubscriptionAttributesFactoryBean implements FactoryBean<SubscriptionAttributes>, InitializingBean {
|
||||
|
||||
private InterestPolicy interestPolicy;
|
||||
|
||||
private SubscriptionAttributes subscriptionAttributes;
|
||||
|
||||
private SubscriptionType type;
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
subscriptionAttributes = new SubscriptionAttributes(getPolicy());
|
||||
subscriptionAttributes = new SubscriptionAttributes(getInterestPolicy());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -69,20 +76,40 @@ public class SubscriptionAttributesFactoryBean implements FactoryBean<Subscripti
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setType(SubscriptionType type) {
|
||||
this.type = type;
|
||||
/**
|
||||
* Sets GemFire's InterestPolicy specified on the SubscriptionAttributes in order to define/declare
|
||||
* the data interests and distribution of changes.
|
||||
*
|
||||
* @param interestPolicy the GemFire InterestsPolicy to set for Subscription.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @see com.gemstone.gemfire.cache.SubscriptionAttributes#SubscriptionAttributes(com.gemstone.gemfire.cache.InterestPolicy)
|
||||
*/
|
||||
public void setInterestPolicy(final InterestPolicy interestPolicy) {
|
||||
this.interestPolicy = interestPolicy;
|
||||
}
|
||||
|
||||
public SubscriptionType getType() {
|
||||
return (type != null ? type : SubscriptionType.DEFAULT);
|
||||
/**
|
||||
* Gets GemFire's InterestPolicy specified on the SubscriptionAttributes which defines data interests
|
||||
* and distribution of changes.
|
||||
*
|
||||
* @return the GemFire InterestsPolicy set for Subscription.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @see com.gemstone.gemfire.cache.SubscriptionAttributes#getInterestPolicy()
|
||||
*/
|
||||
public InterestPolicy getInterestPolicy() {
|
||||
return (interestPolicy != null ? interestPolicy : InterestPolicy.DEFAULT);
|
||||
}
|
||||
|
||||
/* non-Javadoc */
|
||||
@Deprecated
|
||||
public void setPolicy(InterestPolicy policy) {
|
||||
setType(SubscriptionType.valueOf(policy));
|
||||
setInterestPolicy(policy);
|
||||
}
|
||||
|
||||
/* non-Javadoc */
|
||||
@Deprecated
|
||||
public InterestPolicy getPolicy() {
|
||||
return getType().getInterestPolicy();
|
||||
return getInterestPolicy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,94 +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 com.gemstone.gemfire.cache.InterestPolicy;
|
||||
|
||||
/**
|
||||
* Simple enumeration for the various GemFire Subscription types.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @since 1.3.0
|
||||
*/
|
||||
// TODO consider renaming this enum to InterestPolicyType
|
||||
@SuppressWarnings("unused")
|
||||
public enum SubscriptionType {
|
||||
ALL(InterestPolicy.ALL),
|
||||
DEFAULT(InterestPolicy.DEFAULT),
|
||||
CACHE_CONTENT(InterestPolicy.CACHE_CONTENT);
|
||||
|
||||
private final InterestPolicy interestPolicy;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the SubscriptionType enum initialized with the corresponding GemFire
|
||||
* InterestPolicy instance.
|
||||
*
|
||||
* @param interestPolicy a GemFire InterestPolicy corresponding to this SubscriptionType.
|
||||
*/
|
||||
SubscriptionType(final InterestPolicy interestPolicy) {
|
||||
this.interestPolicy = interestPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the value of the given GemFire InterestPolicy as a SubscriptionType enumerated value.
|
||||
*
|
||||
* @param interestPolicy the GemFire InterestPolicy to evaluate.
|
||||
* @return a SubscriptionType enumerated value for the given GemFire InterestPolicy or null
|
||||
* if the GemFire InterestPolicy does not correspond to a SubscriptionType enumerated value.
|
||||
* @see #getInterestPolicy()
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
*/
|
||||
public static SubscriptionType valueOf(final InterestPolicy interestPolicy) {
|
||||
for (SubscriptionType subscriptionType : values()) {
|
||||
if (subscriptionType.getInterestPolicy().equals(interestPolicy)) {
|
||||
return subscriptionType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the value of the given String as a SubscriptionType enumerated value. The String value's case
|
||||
* is ignored.
|
||||
*
|
||||
* @param value a String value specifying the desired SubscriptionType enumerated value.
|
||||
* @return a SubscriptionType enumerated value for the given String or null if the String value
|
||||
* does not evaluate to a SubscriptionType enumerated value.
|
||||
* @see java.lang.Enum#name()
|
||||
*/
|
||||
public static SubscriptionType valueOfIgnoreCase(final String value) {
|
||||
for (SubscriptionType subscriptionType : values()) {
|
||||
if (subscriptionType.name().equalsIgnoreCase(value)) {
|
||||
return subscriptionType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GemFire InterestPolicy corresponding to this SubscriptionType enumerated value.
|
||||
*
|
||||
* @return the GemFire InterestPolicy corresponding to this SubscriptionType enumerated value.
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
*/
|
||||
public InterestPolicy getInterestPolicy() {
|
||||
return interestPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +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;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The SubscriptionTypeConverter class is a Spring Converter implementation and Java PropertyEditor handling
|
||||
* the conversion between Strings and SubscriptionType enumerated values.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.beans.PropertyEditorSupport
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
* @see org.springframework.data.gemfire.SubscriptionType
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class SubscriptionTypeConverter extends PropertyEditorSupport implements Converter<String, SubscriptionType> {
|
||||
|
||||
/* non-Javadoc */
|
||||
private SubscriptionType assertConverted(final String source, final SubscriptionType subscriptionType) {
|
||||
Assert.notNull(subscriptionType, String.format("Source (%1$s) is not a valid SubscriptionType!", source));
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given String into a SubscriptionType enumerated value.
|
||||
*
|
||||
* @param source the String value to convert into a corresponding SubscriptionType enumerated value.
|
||||
* @return a SubscriptionType enumerated value given a String representation.
|
||||
* @throws java.lang.IllegalArgumentException if the String does not represent a valid SubscriptionType.
|
||||
* @see #assertConverted(String, SubscriptionType)
|
||||
* @see org.springframework.data.gemfire.SubscriptionType#valueOfIgnoreCase(String)
|
||||
*/
|
||||
@Override
|
||||
public SubscriptionType convert(final String source) {
|
||||
return assertConverted(source, SubscriptionType.valueOfIgnoreCase(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SubscriptionType 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 a SubscriptionType.
|
||||
*
|
||||
* @param text the String value to express as (convert to) a SubscriptionType.
|
||||
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid SubscriptionType.
|
||||
* @see #convert(String)
|
||||
* @see #setValue(Object)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(final String text) throws IllegalArgumentException {
|
||||
setValue(convert(text));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,8 +28,8 @@ import org.springframework.core.Conventions;
|
||||
import org.springframework.data.gemfire.EvictionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.ExpirationAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.InterestPolicyType;
|
||||
import org.springframework.data.gemfire.SubscriptionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.SubscriptionType;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
@@ -230,12 +230,7 @@ abstract class ParsingUtils {
|
||||
BeanDefinitionBuilder subscriptionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
SubscriptionAttributesFactoryBean.class);
|
||||
|
||||
// do manual conversion since the enum is not public
|
||||
String type = subscriptionElement.getAttribute("type");
|
||||
|
||||
if (StringUtils.hasText(type)) {
|
||||
subscriptionAttributesBuilder.addPropertyValue("type", SubscriptionType.valueOfIgnoreCase(type));
|
||||
}
|
||||
setPropertyValue(subscriptionElement, subscriptionAttributesBuilder, "type", "interestPolicy");
|
||||
|
||||
regionAttributesBuilder.addPropertyValue("subscriptionAttributes",
|
||||
subscriptionAttributesBuilder.getBeanDefinition());
|
||||
|
||||
Reference in New Issue
Block a user