diff --git a/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java b/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java new file mode 100644 index 00000000..6684727b --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java @@ -0,0 +1,172 @@ +/* + * Copyright 2010-2011 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.io.File; +import java.util.List; + +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; + +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.DiskStoreFactory; +import com.gemstone.gemfire.cache.GemFireCache; + +/** + * FactoryBean for creating a DiskStore + * @author David Turanski + */ +public class DiskStoreFactoryBean implements FactoryBean, InitializingBean, BeanNameAware { + + private DiskStoreFactory diskStoreFactory; + + private Boolean autoCompact; + + private Boolean allowForceCompaction; + + private Integer maxOplogSize; + + private Integer timeInterval; + + private Integer queueSize; + + private Integer compactionThreshold; + + private Integer writeBufferSize; + + private GemFireCache cache; + + private String name; + + private List diskDirs; + + @Override + public DiskStore getObject() throws Exception { + return diskStoreFactory.create(name == null ? DiskStoreFactory.DEFAULT_DISK_STORE_NAME : name); + } + + @Override + public Class getObjectType() { + return DiskStore.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public void afterPropertiesSet() throws Exception { + Assert.notNull(cache, "Cache property must be set"); + diskStoreFactory = cache.createDiskStoreFactory(); + + if (allowForceCompaction != null) { + diskStoreFactory.setAllowForceCompaction(allowForceCompaction); + } + if (compactionThreshold != null) { + diskStoreFactory.setCompactionThreshold(compactionThreshold); + } + if (autoCompact != null) { + diskStoreFactory.setAutoCompact(autoCompact); + } + if (queueSize != null) { + diskStoreFactory.setQueueSize(queueSize); + } + if (writeBufferSize != null) { + diskStoreFactory.setWriteBufferSize(writeBufferSize); + } + if (timeInterval != null) { + diskStoreFactory.setTimeInterval(timeInterval); + } + if (maxOplogSize != null) { + diskStoreFactory.setMaxOplogSize(maxOplogSize); + } + + if (!CollectionUtils.isEmpty(diskDirs)) { + File[] diskDirFiles = new File[diskDirs.size()]; + int[] diskDirSizes = new int[diskDirs.size()]; + for (int i = 0; i < diskDirs.size(); i++) { + DiskDir diskDir = diskDirs.get(i); + diskDirFiles[i] = new File(diskDir.location); + diskDirSizes[i] = diskDir.maxSize == null ? DiskStoreFactory.DEFAULT_DISK_DIR_SIZE : diskDir.maxSize; + } + diskStoreFactory.setDiskDirsAndSizes(diskDirFiles, diskDirSizes); + } + + } + + public void setCache(GemFireCache cache) { + this.cache = cache; + } + + public void setAutoCompact(Boolean autoCompact) { + this.autoCompact = autoCompact; + } + + public void setAllowForceCompaction(Boolean allowForceCompaction) { + this.allowForceCompaction = allowForceCompaction; + } + + public void setMaxOplogSize(Integer maxOplogSize) { + this.maxOplogSize = maxOplogSize; + } + + public void setTimeInterval(Integer timeInterval) { + this.timeInterval = timeInterval; + } + + public void setQueueSize(Integer queueSize) { + this.queueSize = queueSize; + } + + public void setCompactionThreshold(Integer compactionThreshold) { + this.compactionThreshold = compactionThreshold; + } + + public void setWriteBufferSize(Integer writeBufferSize) { + this.writeBufferSize = writeBufferSize; + } + + public void setDiskDirs(List diskDirs) { + this.diskDirs = diskDirs; + } + + @Override + public void setBeanName(String name) { + this.name = name; + } + + public static class DiskDir { + final String location; + + final Integer maxSize; + + public DiskDir(String location, int maxSize) { + this.location = location; + this.maxSize = maxSize; + } + + public DiskDir(String location) { + this.location = location; + this.maxSize = null; + } + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java index f81c2909..51a4438b 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java @@ -29,7 +29,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; import com.gemstone.gemfire.cache.AttributesFactory; -import com.gemstone.gemfire.cache.AttributesMutator; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheClosedException; import com.gemstone.gemfire.cache.CacheListener; @@ -43,11 +42,14 @@ import com.gemstone.gemfire.cache.RegionFactory; import com.gemstone.gemfire.cache.Scope; /** - * FactoryBean for creating generic GemFire {@link Region}s. Will try to first locate the region (by name) - * and, in case none if found, proceed to creating one using the given settings. + * FactoryBean for creating generic GemFire {@link Region}s. Will try to first + * locate the region (by name) and, in case none if found, proceed to creating + * one using the given settings. * - * Note that this factory bean allows for very flexible creation of GemFire {@link Region}. For "client" regions - * however, see {@link ClientRegionFactoryBean} which offers easier configuration and defaults. + * Note that this factory bean allows for very flexible creation of GemFire + * {@link Region}. For "client" regions however, see + * {@link ClientRegionFactoryBean} which offers easier configuration and + * defaults. * * @author Costin Leau */ @@ -56,18 +58,26 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple protected final Log log = LogFactory.getLog(getClass()); private boolean destroy = false; + private boolean close = true; + private Resource snapshot; private CacheListener cacheListeners[]; - private CacheLoader cacheLoader; - private CacheWriter cacheWriter; - private RegionAttributes attributes; - private Scope scope; - private DataPolicy dataPolicy; - private Region region; - private List> subRegions; + private CacheLoader cacheLoader; + + private CacheWriter cacheWriter; + + private RegionAttributes attributes; + + private Scope scope; + + private DataPolicy dataPolicy; + + private Region region; + + private List> subRegions; @Override public void afterPropertiesSet() throws Exception { @@ -85,9 +95,8 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple if (attributes != null) AttributesFactory.validateAttributes(attributes); - final RegionFactory regionFactory = (attributes != null ? c.createRegionFactory(attributes) - : c. createRegionFactory()); - + final RegionFactory regionFactory = (attributes != null ? c.createRegionFactory(attributes) : c + . createRegionFactory()); if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener listener : cacheListeners) { @@ -113,13 +122,13 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple // get underlying AttributesFactory postProcess(findAttrFactory(regionFactory)); - + Region reg = regionFactory.create(regionName); log.info("Created new cache region [" + regionName + "]"); if (snapshot != null) { reg.loadSnapshot(snapshot.getInputStream()); } - + if (subRegions != null) { System.out.println("**********************************************" + subRegions.get(0)); } @@ -134,24 +143,24 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple return (AttributesFactory) ReflectionUtils.getField(attrField, regionFactory); } - /** - * Post-process the attribute factory object used for configuring the region of this factory bean during the initialization process. - * The object is already initialized and configured by the factory bean before this method + * Post-process the attribute factory object used for configuring the region + * of this factory bean during the initialization process. The object is + * already initialized and configured by the factory bean before this method * is invoked. * * @param attrFactory attribute factory - * @deprecated as of GemFire 6.5, the use of {@link AttributesFactory} has been deprecated + * @deprecated as of GemFire 6.5, the use of {@link AttributesFactory} has + * been deprecated */ @Deprecated protected void postProcess(AttributesFactory attrFactory) { } - /** - * Post-process the region object for this factory bean during the initialization process. - * The object is already initialized and configured by the factory bean before this method - * is invoked. + * Post-process the region object for this factory bean during the + * initialization process. The object is already initialized and configured + * by the factory bean before this method is invoked. * * @param region */ @@ -159,13 +168,15 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple // do nothing } + @Override public void destroy() throws Exception { if (region != null) { if (close) { if (!region.getCache().isClosed()) { try { region.close(); - } catch (CacheClosedException cce) { + } + catch (CacheClosedException cce) { // nothing to see folks, move on. } } @@ -178,9 +189,9 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Indicates whether the region referred by this factory bean, - * will be destroyed on shutdown (default false). - * Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other. + * Indicates whether the region referred by this factory bean, will be + * destroyed on shutdown (default false). Note: destroy and close are + * mutually exclusive. Enabling one will automatically disable the other. * * @param destroy whether or not to destroy the region * @@ -195,9 +206,9 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Indicates whether the region referred by this factory bean, - * will be closed on shutdown (default true). - * Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other. + * Indicates whether the region referred by this factory bean, will be + * closed on shutdown (default true). Note: destroy and close are mutually + * exclusive. Enabling one will automatically disable the other. * * @param close whether to close or not the region * @see #setDestroy(boolean) @@ -210,9 +221,9 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Sets the snapshots used for loading a newly created region. - * That is, the snapshot will be used only when a new region is created - if the region - * already exists, no loading will be performed. + * Sets the snapshots used for loading a newly created region. That + * is, the snapshot will be used only when a new region is created - + * if the region already exists, no loading will be performed. * * @see #setName(String) * @param snapshot the snapshot to set @@ -222,9 +233,9 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Sets the cache listeners used for the region used by this factory. - * Used only when a new region is created.Overrides the settings - * specified through {@link #setAttributes(RegionAttributes)}. + * Sets the cache listeners used for the region used by this factory. Used + * only when a new region is created.Overrides the settings specified + * through {@link #setAttributes(RegionAttributes)}. * * @param cacheListeners the cacheListeners to set on a newly created region */ @@ -237,11 +248,10 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple this.subRegions = subRegions; } - /** - * Sets the cache loader used for the region used by this factory. - * Used only when a new region is created.Overrides the settings - * specified through {@link #setAttributes(RegionAttributes)}. + * Sets the cache loader used for the region used by this factory. Used only + * when a new region is created.Overrides the settings specified through + * {@link #setAttributes(RegionAttributes)}. * * @param cacheLoader the cacheLoader to set on a newly created region */ @@ -250,9 +260,9 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Sets the cache writer used for the region used by this factory. - * Used only when a new region is created. Overrides the settings - * specified through {@link #setAttributes(RegionAttributes)}. + * Sets the cache writer used for the region used by this factory. Used only + * when a new region is created. Overrides the settings specified through + * {@link #setAttributes(RegionAttributes)}. * * @param cacheWriter the cacheWriter to set on a newly created region */ @@ -261,8 +271,8 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Sets the data policy. Used only when a new region is created. - * Overrides the settings specified through {@link #setAttributes(RegionAttributes)}. + * Sets the data policy. Used only when a new region is created. Overrides + * the settings specified through {@link #setAttributes(RegionAttributes)}. * * @param dataPolicy the region data policy */ @@ -271,8 +281,8 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple } /** - * Sets the region scope. Used only when a new region is created. - * Overrides the settings specified through {@link #setAttributes(RegionAttributes)}. + * Sets the region scope. Used only when a new region is created. Overrides + * the settings specified through {@link #setAttributes(RegionAttributes)}. * * @see Scope * @param scope the region scope @@ -283,8 +293,8 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple /** * Sets the region attributes used for the region used by this factory. - * Allows maximum control in specifying the region settings. - * Used only when a new region is created. + * Allows maximum control in specifying the region settings. Used only when + * a new region is created. * * @param attributes the attributes to set on a newly created region */ diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java index 55930f14..877edc85 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java @@ -22,8 +22,6 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.data.gemfire.RegionFactoryBean; -import org.springframework.data.gemfire.SubRegionFactoryBean; import org.springframework.util.StringUtils; import org.w3c.dom.Element; @@ -34,35 +32,26 @@ import org.w3c.dom.Element; */ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { protected final Log log = LogFactory.getLog(getClass()); - - protected Class getBeanClass(Element element) { - if (element.hasAttribute("subregion")) { - return SubRegionFactoryBean.class; - } - else { - return RegionFactoryBean.class; - } - } @Override - protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder){ + protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); - boolean subRegion = element.hasAttribute("subregion"); - + boolean subRegion = isSubRegion(element); + doParseRegion(element, parserContext, builder, subRegion); - + if (subRegion) { - builder.addPropertyValue("parent", parserContext.getContainingBeanDefinition().getAttribute("parent")); + builder.addPropertyValue("parent", parserContext.getContainingBeanDefinition().getAttribute("parent")); builder.addPropertyValue("regionName", element.getAttribute(NAME_ATTRIBUTE)); } } - + protected abstract void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion); protected void doParseSubRegion(Element element, Element subElement, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion) { - + String regionPath = null; String parentBeanName = null; if (subRegion) { @@ -71,28 +60,26 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { else { parentBeanName = getRegionNameFromElement(element); } - regionPath = StringUtils - .arrayToDelimitedString( - new String[] { parentBeanName, getRegionNameFromElement(subElement) }, "/"); + regionPath = StringUtils.arrayToDelimitedString(new String[] { parentBeanName, + getRegionNameFromElement(subElement) }, "/"); if (!regionPath.startsWith("/")) { regionPath = "/" + regionPath; } - /* - * The Region parser needs some context to handle recursion correctly + * The Region parser needs some context to handle recursion correctly */ builder.getBeanDefinition().setAttribute("parent", new BeanDefinitionHolder(builder.getBeanDefinition(), parentBeanName)); - builder.getBeanDefinition().setAttribute("regionPath",regionPath); + builder.getBeanDefinition().setAttribute("regionPath", regionPath); // Make recursive call BeanDefinition subRegionDef = this.parseSubRegion(subElement, parserContext, builder); - //TODO: Is there a better work-around? + // TODO: Is there a better work-around? /* * This setting prevents the BF from generating a name for this been */ subRegionDef.setScope(BeanDefinition.SCOPE_PROTOTYPE); - + if (log.isDebugEnabled()) { log.debug("registering subregion as " + regionPath); } @@ -100,17 +87,13 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { } private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - /* - * Easy way to mark this element as a subregion - */ - element.setAttribute("subregion", "true"); BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(element, builder.getBeanDefinition()); return beanDefinition; } - - private String getRegionNameFromElement(Element element){ + + private String getRegionNameFromElement(Element element) { String name = element.getAttribute(NAME_ATTRIBUTE); - return StringUtils.hasText(name)? name: element.getAttribute(ID_ATTRIBUTE); + return StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java index 2ef4259c..e8d2f951 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java @@ -26,36 +26,43 @@ import org.springframework.data.gemfire.SubRegionFactoryBean; import org.w3c.dom.Element; /** - * Extension class dealing with the attribute clash (name) that triggers the region name to - * be considered a bean alias. Overrides the automatic alias detection and replaces it with its own - * using meta attributes (since the parsing method is final). + * Extension class dealing with the attribute clash (name) that triggers the + * region name to be considered a bean alias. Overrides the automatic alias + * detection and replaces it with its own using meta attributes (since the + * parsing method is final). * * @author Costin Leau */ abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { + @Override protected Class getBeanClass(Element element) { - if (element.hasAttribute("subregion")){ - System.out.println("building subregion " + element.getAttribute(NAME_ATTRIBUTE)); + + if (isSubRegion(element)) { return SubRegionFactoryBean.class; - } else { + } + else { return RegionFactoryBean.class; } } @Override protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - + ParsingUtils.addBeanAliasAsMetadata(element, builder); - + doParseInternal(element, parserContext, builder); } @Override protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry) { - // add the aliases from the metadata + // add the aliases from the metadata super.registerBeanDefinition(ParsingUtils.replaceBeanAliasAsMetadata(definition), registry); } + protected boolean isSubRegion(Element element) { + return element.getParentNode().getLocalName().endsWith("region"); + } + protected abstract void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder); } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java b/src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java new file mode 100644 index 00000000..7444b28d --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java @@ -0,0 +1,68 @@ +/* + * Copyright 2010-2012 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.config; + +import java.util.List; + +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.DiskStoreFactoryBean; +import org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir; +import org.springframework.util.CollectionUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +/** + * @author David Turanski + * + */ +public class DiskStoreParser extends AbstractSingleBeanDefinitionParser { + @Override + protected Class getBeanClass(Element element) { + return DiskStoreFactoryBean.class; + } + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + super.doParse(element, parserContext, builder); + ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache"); + ParsingUtils.setPropertyValue(element, builder, "auto-compact"); + ParsingUtils.setPropertyValue(element, builder, "allow-force-compaction"); + ParsingUtils.setPropertyValue(element, builder, "max-oplog-size"); + ParsingUtils.setPropertyValue(element, builder, "time-interval"); + ParsingUtils.setPropertyValue(element, builder, "queue-size"); + ParsingUtils.setPropertyValue(element, builder, "compaction-threshold"); + ParsingUtils.setPropertyValue(element, builder, "write-buffer-size"); + + List diskDirElements = DomUtils.getChildElementsByTagName(element, "disk-dir"); + + if (!CollectionUtils.isEmpty(diskDirElements)) { + ManagedList diskDirs = new ManagedList(); + for (Element diskDirElement : diskDirElements) { + BeanDefinitionBuilder diskDirBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskDir.class); + diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("location")); + if (diskDirElement.hasAttribute("max-size")) { + diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("max-size")); + } + diskDirs.add(diskDirBuilder.getBeanDefinition()); + } + builder.addPropertyValue("diskDirs", diskDirs); + } + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java b/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java index 32ada080..493dc356 100644 --- a/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java @@ -23,27 +23,35 @@ import com.gemstone.gemfire.cache.DiskWriteAttributes; import com.gemstone.gemfire.cache.DiskWriteAttributesFactory; /** - * Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans. + * Simple utility class used for defining nested factory-method like definitions + * w/o polluting the container with useless beans. * * @author Costin Leau + * @deprecated */ +@Deprecated class DiskWriteAttributesFactoryBean implements FactoryBean, InitializingBean { private DiskWriteAttributes attributes; + private DiskWriteAttributesFactory attrFactory; + @Override public void afterPropertiesSet() { attributes = attrFactory.create(); } + @Override public DiskWriteAttributes getObject() throws Exception { return attributes; } + @Override public Class getObjectType() { return (attributes != null ? attributes.getClass() : DiskWriteAttributes.class); } + @Override public boolean isSingleton() { return true; } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java index 68f52bfa..ca69e83a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java @@ -23,9 +23,11 @@ import org.springframework.data.gemfire.repository.config.GemfireRepositoryParse * Namespace handler for GemFire definitions. * * @author Costin Leau + * @author David Turanski */ class GemfireNamespaceHandler extends NamespaceHandlerSupport { + @Override public void init() { registerBeanDefinitionParser("cache", new CacheParser()); registerBeanDefinitionParser("client-cache", new ClientCacheParser()); @@ -33,15 +35,14 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("lookup-region", new LookupRegionParser()); registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser()); registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser()); + registerBeanDefinitionParser("local-region", new LocalRegionParser()); registerBeanDefinitionParser("client-region", new ClientRegionParser()); registerBeanDefinitionParser("pool", new PoolParser()); registerBeanDefinitionParser("index", new IndexParser()); + registerBeanDefinitionParser("disk-store", new DiskStoreParser()); registerBeanDefinitionParser("cache-server", new CacheServerParser()); - registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser()); - registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser()); - registerBeanDefinitionParser("repositories", new GemfireRepositoryParser()); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java new file mode 100644 index 00000000..0111be65 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java @@ -0,0 +1,116 @@ +/* + * Copyright 2010-2012 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.config; + +import java.util.List; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.RegionAttributesFactoryBean; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +import com.gemstone.gemfire.cache.Scope; + +/** + * Parser for <replicated-region;gt; definitions. + * + * @author Costin Leau + * @author David Turanski + */ +class LocalRegionParser extends AbstractRegionParser { + @Override + protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, + boolean subRegion) { + + // set the data policy + String attr = element.getAttribute("persistent"); + // if (Boolean.parseBoolean(attr)) { + // builder.addPropertyValue("dataPolicy", + // DataPolicy.PERSISTENT_REPLICATE); + // } + // else { + // builder.addPropertyValue("dataPolicy", DataPolicy.REPLICATE); + // } + + builder.addPropertyValue("scope", Scope.LOCAL); + + ParsingUtils.setPropertyValue(element, builder, "name", "name"); + + BeanDefinitionBuilder attrBuilder = builder; + + if (!subRegion) { + attr = element.getAttribute("cache-ref"); + // add cache reference (fallback to default if nothing is specified) + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache")); + attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); + } + // add attributes + + ParsingUtils.parseStatistics(element, attrBuilder); + + attr = element.getAttribute("publisher"); + if (StringUtils.hasText(attr)) { + attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr)); + } + + ParsingUtils.parseExpiration(parserContext, element, attrBuilder); + ParsingUtils.parseEviction(parserContext, element, attrBuilder); + ParsingUtils.parseDiskStorage(element, attrBuilder); + + if (!subRegion) { + builder.addPropertyValue("attributes", attrBuilder.getBeanDefinition()); + } + + List subElements = DomUtils.getChildElements(element); + + // parse nested elements + for (Element subElement : subElements) { + String name = subElement.getLocalName(); + + if ("cache-listener".equals(name)) { + builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); + } + + else if ("cache-loader".equals(name)) { + builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); + } + + else if ("cache-writer".equals(name)) { + builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); + } + // subregion + else if (name.endsWith("region")) { + doParseSubRegion(element, subElement, parserContext, builder, subRegion); + } + } + } + + private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } + + private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } + + private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } + +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java index 0c32d54b..00affd19 100644 --- a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 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. @@ -30,12 +30,13 @@ import org.w3c.dom.Element; * Parser for <lookup-region;gt; definitions. * * @author Costin Leau + * @author David Turanski */ class LookupRegionParser extends AbstractRegionParser { @Override protected Class getBeanClass(Element element) { - if (element.hasAttribute("subregion")) { + if (isSubRegion(element)) { return SubRegionFactoryBean.class; } else { diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java index 14def796..ad809893 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -27,11 +27,13 @@ import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.core.Conventions; +import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import com.gemstone.gemfire.cache.DiskWriteAttributesFactory; +import com.gemstone.gemfire.cache.DiskStoreFactory; import com.gemstone.gemfire.cache.ExpirationAction; import com.gemstone.gemfire.cache.ExpirationAttributes; @@ -44,14 +46,20 @@ abstract class ParsingUtils { private static final String ALIASES_KEY = ParsingUtils.class.getName() + ":aliases"; - static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attrName, String propertyName) { - String attr = element.getAttribute(attrName); + static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName, + String propertyName) { + String attr = element.getAttribute(attributeName); if (StringUtils.hasText(attr)) { builder.addPropertyValue(propertyName, attr); } } - static void setPropertyReference(Element element, BeanDefinitionBuilder builder, String attrName, String propertyName) { + static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName) { + setPropertyValue(element, builder, attributeName, Conventions.attributeNameToPropertyName(attributeName)); + } + + static void setPropertyReference(Element element, BeanDefinitionBuilder builder, String attrName, + String propertyName) { String attr = element.getAttribute(attrName); if (StringUtils.hasText(attr)) { builder.addPropertyReference(propertyName, attr); @@ -59,9 +67,11 @@ abstract class ParsingUtils { } /** - * Utility for parsing bean aliases. Normally parsed by AbstractBeanDefinitionParser however due to the attribute clash - * (bean uses 'name' for aliases while region use it to indicate their name), the parser needs to handle this differently by - * storing them as metadata which gets deleted just before registration. + * Utility for parsing bean aliases. Normally parsed by + * AbstractBeanDefinitionParser however due to the attribute clash (bean + * uses 'name' for aliases while region use it to indicate their name), the + * parser needs to handle this differently by storing them as metadata which + * gets deleted just before registration. * * @param element * @param builder @@ -87,10 +97,13 @@ abstract class ParsingUtils { /** * Utility method handling parsing of nested definition of the type: + * *
 	 *   
 	 * 
- * or + * + * or + * *
 	 *   
 	 *     
@@ -100,11 +113,13 @@ abstract class ParsingUtils {
 	 * @param element
 	 * @return
 	 */
-	static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, BeanDefinitionBuilder builder) {
+	static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element,
+			BeanDefinitionBuilder builder) {
 		return parseRefOrNestedBeanDeclaration(parserContext, element, builder, "ref");
 	}
 
-	static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, BeanDefinitionBuilder builder, String refAttrName) {
+	static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element,
+			BeanDefinitionBuilder builder, String refAttrName) {
 		String attr = element.getAttribute(refAttrName);
 		boolean hasRef = StringUtils.hasText(attr);
 
@@ -142,10 +157,12 @@ abstract class ParsingUtils {
 	}
 
 	/**
-	 * Parses disk store sub-element. Populates the given attribute factory with the proper attributes.
+	 * Parses disk store sub-element. Populates the given attribute factory with
+	 * the proper attributes.
 	 * 
 	 * @param element - element enclosing the disk-store definition
-	 * @param beanBuilder - beanbuilder for a RegionAttributesFactoryBean instance
+	 * @param beanBuilder - beanbuilder for a RegionAttributesFactoryBean
+	 * instance
 	 * @return true if parsing actually occured, false otherwise
 	 */
 	static boolean parseDiskStorage(Element element, BeanDefinitionBuilder beanBuilder) {
@@ -154,14 +171,16 @@ abstract class ParsingUtils {
 		if (diskStoreElement == null)
 			return false;
 
-		BeanDefinitionBuilder diskDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskWriteAttributesFactory.class);
-		setPropertyValue(diskStoreElement, diskDefBuilder, "synchronous-write", "synchronous");
+		if (diskStoreElement.getParentNode().getLocalName().endsWith("region")) {
+			System.out.println("This is a nested disk-store");
+		}
+
+		BeanDefinitionBuilder diskDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactory.class);
 		setPropertyValue(diskStoreElement, diskDefBuilder, "auto-compact", "rollOplogs");
 		setPropertyValue(diskStoreElement, diskDefBuilder, "max-oplog-size", "maxOplogSize");
 		setPropertyValue(diskStoreElement, diskDefBuilder, "time-interval", "timeInterval");
 		setPropertyValue(diskStoreElement, diskDefBuilder, "queue-size", "bytesThreshold");
 
-
 		// parse nested disk-dir
 		List list = DomUtils.getChildElementsByTagName(diskStoreElement, "disk-dir");
 		ManagedList locations = new ManagedList(list.size());
@@ -176,7 +195,7 @@ abstract class ParsingUtils {
 
 		// wrap up the disk attributes factory to call 'create'
 
-		BeanDefinitionBuilder factoryWrapper = BeanDefinitionBuilder.genericBeanDefinition(DiskWriteAttributesFactoryBean.class);
+		BeanDefinitionBuilder factoryWrapper = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactoryBean.class);
 		factoryWrapper.addPropertyValue("diskAttributesFactory", diskDefBuilder.getBeanDefinition());
 		beanBuilder.addPropertyValue("diskWriteAttributes", factoryWrapper.getBeanDefinition());
 		beanBuilder.addPropertyValue("diskDirs", locations);
@@ -186,7 +205,8 @@ abstract class ParsingUtils {
 	}
 
 	/**
-	 * Parses the eviction sub-element. Populates the given attribute factory with the proper attributes.
+	 * Parses the eviction sub-element. Populates the given attribute factory
+	 * with the proper attributes.
 	 * 
 	 * @param parserContext
 	 * @param element
@@ -199,7 +219,8 @@ abstract class ParsingUtils {
 		if (evictionElement == null)
 			return false;
 
-		BeanDefinitionBuilder evictionDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(EvictionAttributesFactoryBean.class);
+		BeanDefinitionBuilder evictionDefBuilder = BeanDefinitionBuilder
+				.genericBeanDefinition(EvictionAttributesFactoryBean.class);
 
 		// do manual conversion since the enum is not public
 		String attr = evictionElement.getAttribute("type");
@@ -210,7 +231,6 @@ abstract class ParsingUtils {
 		setPropertyValue(evictionElement, evictionDefBuilder, "threshold", "threshold");
 		setPropertyValue(evictionElement, evictionDefBuilder, "action", "action");
 
-
 		// get object sizer (if declared)
 		Element objectSizerElement = DomUtils.getChildElementByTagName(evictionElement, "object-sizer");
 
@@ -223,13 +243,13 @@ abstract class ParsingUtils {
 		return true;
 	}
 
-
 	static void parseStatistics(Element element, BeanDefinitionBuilder attrBuilder) {
 		setPropertyValue(element, attrBuilder, "statistics", "statisticsEnabled");
 	}
 
 	/**
-	 * Parses the expiration sub-elements. Populates the given attribute factory with proper attributes. 
+	 * Parses the expiration sub-elements. Populates the given attribute factory
+	 * with proper attributes.
 	 * 
 	 * @param parserContext
 	 * @param element
@@ -250,7 +270,25 @@ abstract class ParsingUtils {
 		return result;
 	}
 
-	private static boolean parseExpiration(Element rootElement, String elementName, String propertyName, BeanDefinitionBuilder attrBuilder) {
+	static void parseAdditionalAttributes(ParserContext parserContext, Element element,
+			BeanDefinitionBuilder attrBuilder) {
+		setPropertyValue(element, attrBuilder, "persistent", "persistBackup");
+		setPropertyValue(element, attrBuilder, "ignore-jta", "ignoreJTA");
+		setPropertyValue(element, attrBuilder, "key-constraint", "keyConstraint");
+		setPropertyValue(element, attrBuilder, "value-constraint", "valueConstraint");
+		setPropertyValue(element, attrBuilder, "lock-grantor", "lockGrantor");
+		setPropertyValue(element, attrBuilder, "enable-subscription-conflation", "enableSubscriptionConflation");
+		setPropertyValue(element, attrBuilder, "enable-async-conflation", "enableAsyncConflation");
+		setPropertyValue(element, attrBuilder, "initial-capacity", "initialCapacity");
+		String indexUpdateType = element.getAttribute("index-update-type");
+		if (StringUtils.hasText(indexUpdateType)) {
+			attrBuilder.addPropertyValue("indexMaintenanceSynchronous", "synchronous".equals(indexUpdateType));
+		}
+
+	}
+
+	private static boolean parseExpiration(Element rootElement, String elementName, String propertyName,
+			BeanDefinitionBuilder attrBuilder) {
 		Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
 
 		if (expirationElement == null)
@@ -259,7 +297,6 @@ abstract class ParsingUtils {
 		String expirationTime = null;
 		ExpirationAction action = ExpirationAction.INVALIDATE;
 
-
 		// do manual conversion since the enum is not public
 		String attr = expirationElement.getAttribute("timeout");
 		if (StringUtils.hasText(attr)) {
@@ -284,7 +321,8 @@ abstract class ParsingUtils {
 				action = ExpirationAction.LOCAL_INVALIDATE;
 			}
 		}
-		BeanDefinitionBuilder expirationAttributes = BeanDefinitionBuilder.genericBeanDefinition(ExpirationAttributes.class);
+		BeanDefinitionBuilder expirationAttributes = BeanDefinitionBuilder
+				.genericBeanDefinition(ExpirationAttributes.class);
 		expirationAttributes.addConstructorArgValue(expirationTime);
 		expirationAttributes.addConstructorArgValue(action);
 		attrBuilder.addPropertyValue(propertyName, expirationAttributes.getBeanDefinition());
diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java
index aec50710..78e504c3 100644
--- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java
+++ b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010-2011 the original author or authors.
+ * Copyright 2010-2012 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.
diff --git a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java
index 830f85ea..bb40f29a 100644
--- a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java
+++ b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java
@@ -61,7 +61,7 @@ class ReplicatedRegionParser extends AbstractRegionParser {
 			attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class);
 		}
 		// add attributes
-
+		ParsingUtils.parseAdditionalAttributes(parserContext, element, attrBuilder);
 		ParsingUtils.parseStatistics(element, attrBuilder);
 
 		attr = element.getAttribute("publisher");
diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd
index 1a2fe21d..0f351362 100644
--- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd
+++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd
@@ -1,90 +1,76 @@
 
-
-    
-    
-    
-    
-    
-        
+
+	
+	
+	
+	
+	
+		
-    
-    
-    
-        
-            
-                
+	
+	
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				 namespace and its 'properties' element.
 				]]>
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-    
-    
-    
-        
-            
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
-                                
-                                    
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
+								
+									
+								
+							
+						
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                
-            
-        
-    
-    
-    
-        
-            
+					
+				
+			
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
-                        
-                    
-                
-            
-        
-    
-    
-    
-        
-            
+					
+				
+			
+		
+	
+	
+	
+		
+			
-        
-        
-            
-                
-                    
+		
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                    
+			
+		
+	
+	
+	
+		
+			
+				
+					
-                
-            
-        
-        
-            
-                
+			
+		
+		
+			
+				
-            
-        
-    
-    
-    
-        
-            
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                        
-                            
+				
+					
+				
+			
+		
+		
+			
+				
+			
+		
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                    
-                
-            
-        
-
-
-    
-
-
-    
-    
-        
-            
-                
-                    
-                        
-                            
+				
+			
+		
+	
+	
+		
+			
+				
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+							
-                            
-                                
-                                    
-                                
-                            
-                        
-                        
-                            
-                                
-                                    
-                                        
+								
+									
+								
+							
+						
+						
+							
+								
+									
+										
-                                    
-                                
-                            
-                            
-                                
-                                    
+								
+							
+							
+								
+									
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+							
+						
+					
+					
+						
+							
-                        
-                    
-                
-                
-                    
-                        
+					
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
+					
+				
+				
+					
+						
+					
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                        
-                            
+				
+				
+					
+						
+					
+				
+				
+					
+						
+					
+				
+				
+					
+						
+					
+				
+				
+					
+						
+					
+				
+				
+					
+						
+					
+					
+						
+							
+							
+						
+					
+				
+				
+					
+						
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-
-    
-    
-        
-            
-                
-                    
-                        
-                            
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+							
-                            
-                                
-                                    
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+								
+									
+								
+							
+						
+					
+					
+						
+							
-                            
-                                
-                                    
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+								
+									
+								
+							
+						
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-            
-        
-    
-    
-     
-        
-            
-               
-                    
-                        
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+		
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-            
-        
-    
-     
-        
-            
-               
-                    
-                        
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+		
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-            
-            
-        
-    
-    
-    
-        
-            
-                
+				
+			
+		
+	
+	
+	
+		
+			
+			
+			
+			
+		
+	
+	
+	
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-    
-    
-    
-    
-    
-        
-            
+		
+	
+	
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
-                        
-                        
-                            
-                                
-                                    
-                                        
-                                            
+						
+							
+								
+									
+										
+											
-                                        
-                                    
-                                
-                            
-                        
-                    
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-            
-        
-    
-    
-      
-        
-            
-                   
-                    
-                        
+									
+								
+							
+						
+					
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-
-    
-    
-    
-    
-        
-            
+				
+			
+		
+	
+	
+	
+	
+	
+		
+			
+			
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
+						
+						
+							
+								
+									
+										
+											
+										
+									
+								
+							
+						
+					
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+					
+				
+			
+		
+	
+	
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
-                            
-                                
-                                    
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+								
+									
+								
+							
+						
+					
+					
+						
+							
-                        
-                        
-                            
-                                
-                                    
-                                        
-                                            
+						
+							
+								
+									
+										
+											
-                                        
-                                    
-                                
-                            
-                        
-                    
-                
-                
-                    
-                        
+									
+								
+							
+						
+					
+				
+				
+					
+						
+					
+					
+						
+							
+							
+							
+						
+					
+				
+				
+					
+						
-                    
-                    
-                        
-                            
-                            
-                        
-                    
-                
-                
-                    
-                        
+					
+						
+							
+							
+						
+					
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-                
-                    
-                        
+				
+				
+					
+						
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                
-            
-        
-    
-    
-      
-        
-            
-                
-                      
-                    
-                        
+				
+			
+		
+	
+	
+	
+		
+			
+				
+			
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
-                    
-                
-            
-        
-    
-
-    
-    
-    
-    
-        
-            
-                
+				
+			
+			
+		
+	
+	
+	
+	
+	
+		
+			
+				
-            
-        
-        
-            
-                
-                    
-                        
-                            
+		
+		
+			
+				
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                    
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
-                    
-                        
-                            
-                        
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
+						
+							
+						
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                
-            
-        
-        
-            
-                
+					
+				
+			
+		
+		
+			
+				
-            
-        
-    
-    
-    
-        
-            
-                
-                    
+		
+	
+	
+	
+		
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-        
-    
-    
-        
-            
-                
-                    
-                        
-                            
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                
-            
-        
-        
-            
-                
-            
-        
-        
-            
-                
+					
+				
+			
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-    
-    
-    
-        
-            
+			
+			
+				
+					
+					
+				
+			
+		
+		
+			
+				
+			
+		
+		
+			
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+					
+				
+			    
+				  
+					 
+				 
+							
+			
+		
+	
+	
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                            
-                                
-                                    
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
+							
+								
+									
-                                
-                                
-                                    
-                                        
-                                            
-                                                
-                                                    
-                                                        
+								
+									
+										
+											
+												
+													
+														
-                                                    
-                                                
-                                            
-                                            
-                                                
-                                                    
+												
+											
+											
+												
+													
-                                                
-                                            
-                                        
-                                    
-                                
-                            
-                            
-                                
-                                    
+											
+										
+									
+								
+							
+							
+								
+									
-                                
-                                
-                                    
-                                        
-                                            
-                                        
-                                    
-                                
-                            
-                        
-                        
-                            
-                                
+								
+									
+										
+											
+										
+									
+								
+							
+						
+						
+							
+								
-                            
-                            
-                                
-                                    
-                                        
-                                            
-                                                
+							
+								
+									
+										
+											
+												
-                                            
-                                        
-                                    
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+										
+									
+								
+							
+						
+					
+					
+						
+							
-                        
-                        
-                            
-                                
-                                
-                            
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                    
-                    
-                        
-                            
+					
+					
+						
+							
-                        
-                        
-                            
-                                
-                                
-                                
-                                
-                                
-                                
-                                
-                                
-                                
-                            
-                        
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
+						
+							
+								
+								
+								
+								
+								
+								
+								
+								
+								
+							
+						
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-            
-                
-            
-        
-    
-    
-    
-        
-            
-                
+			
+				
+			
+		
+	
+	
+	
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-            
-                
-                    
-                    
-                    
-                
-            
-        
-        
-            
-                
+			
+				
+					
+					
+					
+				
+			
+		
+		
+			
+				
-            
-        
-    
-    
-    
-        
-            
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                
-            
-            
-                
-                    
+				
+					
+				
+			
+		
+		
+			
+				
+				
+			
+			
+				
+					
-                
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-        
-    
-    
-    
-        
-            
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
+				
+					
+				
+			
+		
+		
+			
+				
+					
+						
-                    
-                    
-                        
-                            
-                                
-                                    
-                                    
-                                    
-                                
-                            
-                        
-                        
-                        
-                    
-                
-            
-            
-                
-                    
-                
-            
-            
-            
-            
-                
-                    
-                
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-            
-                
-                    
+					
+						
+							
+								
+									
+									
+									
+								
+							
+						
+						
+						
+					
+				
+			
+			
+				
+					
+				
+			
+			
+			
+			
+				
+					
+				
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+				
+					
-                
-            
-            
-                
-                    
-                
-            
-            
-                
-                    
-                
-            
-        
-    
-    
-    
-        
-            
+			
+			
+				
+					
+				
+			
+			
+				
+					
+				
+			
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-            
-            
-                
-                    
+				
+					
+				
+			
+		
+		
+			
+				
+			
+			
+				
+					
-                    
-                        
-                            
-                        
-                    
-                
-            
-            
-                
-                    
+						
+							
+						
+					
+				
+			
+			
+				
+					
-                    
-                        
-                            
-                        
-                    
-                
-            
-            
-                
-                    
+						
+							
+						
+					
+				
+			
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-        
-    
-    
-    
-        
-            
-                
+			
+		
+	
+	
+	
+		
+			
+				
-                
-                    
-                
-            
-        
-        
-            
-                
+					
+				
+			
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-        
-            
-                
+		
+		
+			
+				
-            
-        
-    
-    
-    
-        
-            
+		
+	
+	
+	
+		
+			
-            
-                
-                    
-                
-            
-        
-        
-            
-                
-                    
-                
-            
-            
-                
-                    
-                        
-                        
-                    
-                
-            
-            
-                
-                    
+				
+					
+				
+			
+		
+		
+			
+				
+					
+				
+			
+			
+				
+					
+						
+						
+					
+				
+			
+			
+				
+					
-                
-            
-            
-            
-            
-            
-                
-                    
+			
+			
+			
+			
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-            
-                
-                    
+			
+			
+				
+					
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                    
-                        
-                    
-                    
-                    
-                
-            
-        
-    
-    
-    
-        
-            
-                
-                
-            
-        
-    
-    
-    
-        
-            
-                
+				
+			
+		
+	
+	
+	
+		
+			
+				
+					
+						
+					
+					
+					
+				
+			
+		
+	
+	
+	
+		
+			
+				
+				
+			
+		
+	
+	
+	
+		
+			
+				
                     The reference to a GemfireTemplate.
                     Will default to 'gemfireTemplate'.
                 
-            
-        
-    
-    
-    
-        
-            
-                
-                    
-                
-            
-        
-        
-    
-    
-    
-        
-            
-        
-        
-        
-            
-                
-                    
-                    
-                    
-                    
-                
-            
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-    
-    
-    
-        
-            
-            
-            
-        
-    
+			
+		
+	
+	
+	
+		
+			
+				
+					
+				
+			
+		
+		
+	
+	
+	
+		
+			
+		
+		
+		
+			
+				
+					
+					
+					
+					
+				
+			
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+	
+	
+	
+		
+			
+			
+			
+		
+	
+	
+	
+		
+			
+			
+			
+			
+		
+	
 
diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java
new file mode 100644
index 00000000..dff269dc
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2010-2012 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.config;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.gemstone.gemfire.cache.DiskStore;
+import com.gemstone.gemfire.cache.DiskStoreFactory;
+
+/**
+ * @author David Turanski
+ * 
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("diskstore-ns-new.xml")
+public class DiskStoreNamespaceTest {
+	private static File diskStoreDir;
+
+	@Autowired
+	DiskStore diskStore1;
+
+	@Test
+	public void testDiskStore() {
+		assertEquals("diskStore1", diskStore1.getName());
+		assertEquals(50, diskStore1.getQueueSize());
+		assertEquals(true, diskStore1.getAutoCompact());
+		assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold());
+		assertEquals(9999, diskStore1.getTimeInterval());
+		assertEquals(10, diskStore1.getMaxOplogSize());
+		assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]);
+	}
+
+	@BeforeClass
+	public static void setUp() {
+		String path = "./build/tmp";
+		diskStoreDir = new File(path);
+		if (!diskStoreDir.exists()) {
+			diskStoreDir.mkdir();
+		}
+	}
+
+	@AfterClass
+	public static void tearDown() {
+		for (File file : diskStoreDir.listFiles()) {
+			file.delete();
+		}
+		diskStoreDir.delete();
+	}
+}
diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java
new file mode 100644
index 00000000..3d93d42f
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010-2012 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.config;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.data.gemfire.RegionFactoryBean;
+import org.springframework.data.gemfire.RegionLookupFactoryBean;
+import org.springframework.data.gemfire.TestUtils;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.util.ObjectUtils;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheListener;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.Scope;
+
+/**
+ * @author Costin Leau
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("local-ns.xml")
+public class LocalRegionNamespaceTest {
+
+	@Autowired
+	private ApplicationContext context;
+
+	@Test
+	public void testBasicReplica() throws Exception {
+		assertTrue(context.containsBean("simple"));
+	}
+
+	@Test
+	public void testPublishingReplica() throws Exception {
+		assertTrue(context.containsBean("pub"));
+		RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
+		assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
+		assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
+		assertEquals("publisher", TestUtils.readField("name", fb));
+		RegionAttributes attrs = TestUtils.readField("attributes", fb);
+		assertFalse(attrs.getPublisher());
+	}
+
+	@Test
+	public void testComplexReplica() throws Exception {
+		assertTrue(context.containsBean("complex"));
+		RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class);
+		CacheListener[] listeners = TestUtils.readField("cacheListeners", fb);
+		assertFalse(ObjectUtils.isEmpty(listeners));
+		assertEquals(2, listeners.length);
+		assertSame(listeners[0], context.getBean("c-listener"));
+
+		assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", fb));
+		assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb));
+	}
+
+	@Test
+	public void testRegionLookup() throws Exception {
+		Cache cache = context.getBean(Cache.class);
+		Region existing = cache.createRegionFactory().create("existing");
+		assertTrue(context.containsBean("lookup"));
+		RegionLookupFactoryBean lfb = context.getBean("&lookup", RegionLookupFactoryBean.class);
+		assertEquals("existing", TestUtils.readField("name", lfb));
+		assertEquals(existing, context.getBean("lookup"));
+	}
+}
\ No newline at end of file
diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml
index f2a229e8..bce2ec77 100644
--- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml
+++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml
@@ -33,13 +33,13 @@
 	
 
 	
-		
+		
 			
 		
 	
 	
 	
-		
+		
 			
 		
 
diff --git a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml
new file mode 100644
index 00000000..0ce704d0
--- /dev/null
+++ b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml
@@ -0,0 +1,29 @@
+
+
+
+	
+    
+        ./build/tmp
+        50
+        true
+        10
+        9999
+        1
+    
+    
+    
+
+	
+		
+	
+
\ No newline at end of file
diff --git a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml
index a91f7f85..ba11cf0c 100644
--- a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml
+++ b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml
@@ -24,7 +24,7 @@
     
 	
 	
-		
+		
 			
 		
 
@@ -39,7 +39,7 @@
  	
  	
 	
-		
+		
 			
 		 
 
diff --git a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml
new file mode 100644
index 00000000..7fc7f302
--- /dev/null
+++ b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml
@@ -0,0 +1,31 @@
+
+
+
+	
+	
+	
+	
+	
+	
+	
+		
+			
+			
+		
+		
+		
+	
+	
+	
+	
+	
+	
+	
+
\ No newline at end of file
diff --git a/src/test/resources/org/springframework/data/gemfire/config/subregion-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/subregion-ns.xml
index d8cf4560..d0803639 100644
--- a/src/test/resources/org/springframework/data/gemfire/config/subregion-ns.xml
+++ b/src/test/resources/org/springframework/data/gemfire/config/subregion-ns.xml
@@ -18,7 +18,7 @@
     
      
         
-                        
+