JBoss Cache SVN: r5995 - in core/trunk/src: main/java/org/jboss/cache/config and 19 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-17 11:36:31 -0400 (Tue, 17 Jun 2008)
New Revision: 5995
Added:
core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/
core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
core/trunk/src/test/java/org/jboss/cache/config/XmlConfigurationParserTest.java
core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml
core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml
core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml
Removed:
core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java
core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/xml/XmlHelper.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
core/trunk/src/main/java/org/jboss/cache/config/XmlParsingConfigurationRegistry.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java
Log:
first draft for new configuration file
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -8,9 +8,9 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.ComponentRegistry;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.invocation.CacheInvocationDelegate;
import java.io.InputStream;
@@ -62,7 +62,7 @@
public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
Configuration c = parser.parseFile(configFileName);
return createCache(c, start);
}
@@ -141,14 +141,14 @@
public Cache<K, V> createCache(InputStream is) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
Configuration c = parser.parseStream(is);
return createCache(c);
}
public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
Configuration c = parser.parseStream(is);
return createCache(c, start);
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -798,21 +798,7 @@
// Try to establish a default region if there isn't one already
boolean needDefault;
List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
-
- // APPROACH 1: Scan for a default region, try to add if not there.
- // This will try to add the region if it is missing but seems to break
- // some unit tests that configure one or more non-default regions and
- // no default region (e.g. the eviction.minttl tests). So, doing this
- // seems to add a new semantic. For now comment this out and use APPROACH 2
-// for (EvictionRegionConfig erc : ercs)
-// {
-// if (DEFAULT_REGION.equals(erc.getRegionFqn()))
-// {
-// needDefault = false;
-// break;
-// }
-// }
- // APPROACH 2: Only add a default region if there are no regions. This is
+ // Only add a default region if there are no regions. This is
// contrary to the idea that there *must* be a default region, but some
// unit tests fail w/ APPROACH 1, so for now we go with this approach.
needDefault = ercs.size() == 0;
@@ -856,7 +842,7 @@
*/
public void startEvictionThread()
{
- evictionTimerTask.init(evictionConfig.getWakeupIntervalSeconds());
+ evictionTimerTask.init(evictionConfig.getWakeupInterval());
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,7 +7,7 @@
package org.jboss.cache.config;
import org.jboss.cache.Version;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.marshall.Marshaller;
@@ -15,6 +15,8 @@
import java.net.URL;
import java.util.Locale;
+import java.util.List;
+import java.util.Collections;
/**
* Encapsulates the configuration of a Cache.
@@ -194,6 +196,7 @@
private boolean useLazyDeserialization = false;
private int objectInputStreamPoolSize = 50;
private int objectOutputStreamPoolSize = 50;
+ private List<CustomInterceptorConfig> customInterceptors = Collections.EMPTY_LIST;
// ------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
@@ -204,7 +207,7 @@
*/
public void setClusterConfig(Element config)
{
- setClusterConfig(XmlConfigurationParser.parseClusterConfigXml(config));
+ setClusterConfig(XmlConfigurationParserOld.parseClusterConfigXml(config));
}
public void setClusterName(String clusterName)
@@ -319,7 +322,6 @@
* See the user guide for details on how this is handled.
* <p/>
*/
- @Deprecated
public void setUseRegionBasedMarshalling(boolean useRegionBasedMarshalling)
{
testImmutability("useRegionBasedMarshalling");
@@ -875,4 +877,25 @@
return getBuddyReplicationConfig() != null && getBuddyReplicationConfig().isEnabled() &&
getCacheMode() != Configuration.CacheMode.LOCAL;
}
+
+ public String getMuxStackName()
+ {
+ return muxStackName;
+ }
+
+ public void setMuxStackName(String muxStackName)
+ {
+ this.muxStackName = muxStackName;
+ }
+
+ public List<CustomInterceptorConfig> getCustomInterceptors()
+ {
+ return customInterceptors;
+ }
+
+ public void setCustomInterceptors(List<CustomInterceptorConfig> customInterceptors)
+ {
+ testImmutability("customInterceptors");
+ this.customInterceptors = customInterceptors;
+ }
}
Added: core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,132 @@
+package org.jboss.cache.config;
+
+import net.jcip.annotations.Immutable;
+
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Holds information about the custom interceptors defined in the configuration file.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Immutable
+public class CustomInterceptorConfig implements Cloneable, Serializable
+{
+ private String interceptorClass;
+ private boolean isFirst;
+ private boolean isLast;
+ private int index = -1;
+ private String afterClass;
+ private String beforeClass;
+ private Map properties;
+
+ public CustomInterceptorConfig(String interceptorClass, boolean first, boolean last, int index, String afterClass, String beforeClass, Properties props)
+ {
+ this.interceptorClass = interceptorClass;
+ isFirst = first;
+ isLast = last;
+ this.index = index;
+ this.afterClass = afterClass;
+ this.beforeClass = beforeClass;
+ this.properties = Collections.unmodifiableMap(props);
+ }
+
+ public String getInterceptorClass()
+ {
+ return interceptorClass;
+ }
+
+ public boolean isFirst()
+ {
+ return isFirst;
+ }
+
+ public boolean isLast()
+ {
+ return isLast;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public String getAfterClass()
+ {
+ return afterClass;
+ }
+
+ public String getBeforeClass()
+ {
+ return beforeClass;
+ }
+
+ /**
+ * Returns an unmodifiable map of set properties.
+ */
+ public Map getProperties()
+ {
+ return properties;
+ }
+
+ public String toString()
+ {
+ return "CustomInterceptorConfig{" +
+ "interceptorClass='" + interceptorClass + '\'' +
+ ", isFirst=" + isFirst +
+ ", isLast=" + isLast +
+ ", index=" + index +
+ ", afterClass='" + afterClass + '\'' +
+ ", beforeClass='" + beforeClass + '\'' +
+ '}';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof CustomInterceptorConfig)) return false;
+
+ CustomInterceptorConfig that = (CustomInterceptorConfig) o;
+
+ if (index != that.index) return false;
+ if (isFirst != that.isFirst) return false;
+ if (isLast != that.isLast) return false;
+ if (afterClass != null ? !afterClass.equals(that.afterClass) : that.afterClass != null) return false;
+ if (beforeClass != null ? !beforeClass.equals(that.beforeClass) : that.beforeClass != null) return false;
+ if (interceptorClass != null ? !interceptorClass.equals(that.interceptorClass) : that.interceptorClass != null)
+ return false;
+ if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (interceptorClass != null ? interceptorClass.hashCode() : 0);
+ result = 31 * result + (isFirst ? 1 : 0);
+ result = 31 * result + (isLast ? 1 : 0);
+ result = 31 * result + index;
+ result = 31 * result + (afterClass != null ? afterClass.hashCode() : 0);
+ result = 31 * result + (beforeClass != null ? beforeClass.hashCode() : 0);
+ result = 31 * result + (properties != null ? properties.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ CustomInterceptorConfig dolly = (CustomInterceptorConfig) super.clone();
+ dolly.interceptorClass = interceptorClass;
+ dolly.isFirst = isFirst;
+ dolly.isLast = isLast;
+ dolly.afterClass = afterClass;
+ dolly.beforeClass = beforeClass;
+ dolly.properties = properties;
+ return dolly;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -48,8 +48,13 @@
private String defaultEvictionPolicyClass;
+ @Deprecated
private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
+ /** value expressed in millis */
+ @Dynamic
+ private long wakeupInterval = WAKEUP_DEFAULT * 1000;
+
private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT;
// Dynamic to support runtime adds/removes of regions
@@ -158,40 +163,65 @@
this.evictionRegionConfigs = evictionRegionConfigs;
}
+ /** value expressed in millis */
+ public long getWakeupInterval()
+ {
+ return wakeupInterval;
+ }
+
+ /** value expressed in millis */
+ public void setWakeupInterval(long wakeupInterval)
+ {
+ testImmutability("WakeupInterval");
+ this.wakeupInterval = wakeupInterval;
+ }
+
+ /**
+ * Use {@link #getWakeupIntervalSeconds()}.
+ */
+ @Deprecated
public int getWakeupIntervalSeconds()
{
return wakeupIntervalSeconds;
}
+ /**
+ * Use {@link #setWakeupInterval(long)}.
+ */
+ @Deprecated
public void setWakeupIntervalSeconds(int wakeupIntervalSeconds)
{
testImmutability("wakeupIntervalSeconds");
this.wakeupIntervalSeconds = wakeupIntervalSeconds;
+ setWakeupInterval(wakeupIntervalSeconds * 1000);
}
- @Override
- public boolean equals(Object obj)
+ public boolean equals(Object o)
{
- if (this == obj)
- return true;
+ if (this == o) return true;
+ if (!(o instanceof EvictionConfig)) return false;
- if (obj instanceof EvictionConfig)
- {
- EvictionConfig other = (EvictionConfig) obj;
- return (this.wakeupIntervalSeconds == other.wakeupIntervalSeconds)
- && Util.safeEquals(this.defaultEvictionPolicyClass, other.defaultEvictionPolicyClass)
- && Util.safeEquals(this.evictionRegionConfigs, other.evictionRegionConfigs);
- }
- return false;
+ EvictionConfig that = (EvictionConfig) o;
+
+ if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
+ if (wakeupInterval != that.wakeupInterval) return false;
+ if (wakeupIntervalSeconds != that.wakeupIntervalSeconds) return false;
+ if (defaultEvictionPolicyClass != null ? !defaultEvictionPolicyClass.equals(that.defaultEvictionPolicyClass) : that.defaultEvictionPolicyClass != null)
+ return false;
+ if (evictionRegionConfigs != null ? !evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs != null)
+ return false;
+
+ return true;
}
- @Override
public int hashCode()
{
- int result = 17;
- result = 37 * result + wakeupIntervalSeconds;
- result = 37 * result + (defaultEvictionPolicyClass == null ? 0 : defaultEvictionPolicyClass.hashCode());
- result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode());
+ int result;
+ result = (defaultEvictionPolicyClass != null ? defaultEvictionPolicyClass.hashCode() : 0);
+ result = 31 * result + wakeupIntervalSeconds;
+ result = 31 * result + (int) (wakeupInterval ^ (wakeupInterval >>> 32));
+ result = 31 * result + defaultEventQueueSize;
+ result = 31 * result + (evictionRegionConfigs != null ? evictionRegionConfigs.hashCode() : 0);
return result;
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,6 +1,6 @@
package org.jboss.cache.config;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -47,7 +47,7 @@
testImmutability("properties");
// JBCACHE-531: escape all backslash characters
// replace any "\" that is not preceded by a backslash with "\\"
- properties = XmlHelper.escapeBackslashes(properties);
+ properties = XmlConfigHelper.escapeBackslashes(properties);
ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
this.properties = new Properties();
this.properties.load(is);
Modified: core/trunk/src/main/java/org/jboss/cache/config/XmlParsingConfigurationRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/XmlParsingConfigurationRegistry.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/config/XmlParsingConfigurationRegistry.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,7 +7,7 @@
package org.jboss.cache.config;
-import org.jboss.cache.factories.CacheConfigsXmlParser;
+import org.jboss.cache.config.parsing.CacheConfigsXmlParser;
import java.util.HashSet;
import java.util.Hashtable;
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,56 @@
+package org.jboss.cache.config.parsing;
+
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.w3c.dom.Element;
+
+import java.util.Properties;
+
+/**
+ * Utility class for parsing 'buddyReplication' element in the .xml configuration file.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class BuddyReplicationElementParser extends XmlParserBase
+{
+ public BuddyReplicationConfig parseBuddyReplicationElement(Element element)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ String enabled = element.getAttribute("enabled");
+ if (existsAttribute(enabled)) brc.setEnabled(getBoolean(enabled));
+ String buddyPoolName = element.getAttribute("buddyPoolName");
+ if (existsAttribute(buddyPoolName)) brc.setBuddyPoolName(buddyPoolName);
+ String buddyCommunicationTimeout = element.getAttribute("buddyCommunicationTimeout");
+ if (existsAttribute(buddyCommunicationTimeout))
+ brc.setBuddyCommunicationTimeout(getInt(buddyCommunicationTimeout));
+
+ parseDataGravitationElement(getSingleElement("dataGravitation", element), brc);
+ BuddyReplicationConfig.BuddyLocatorConfig blc = parseBuddyLocatorConfig(getSingleElement("buddyLocator", element));
+ brc.setBuddyLocatorConfig(blc);
+ return brc;
+ }
+
+ private BuddyReplicationConfig.BuddyLocatorConfig parseBuddyLocatorConfig(Element element)
+ {
+ if (element == null) return null;
+ BuddyReplicationConfig.BuddyLocatorConfig result = new BuddyReplicationConfig.BuddyLocatorConfig();
+ String buddyLocatorClass = element.getAttribute("class");
+ if (existsAttribute(buddyLocatorClass)) result.setBuddyLocatorClass(buddyLocatorClass);
+ Properties props = null;
+ props = XmlConfigHelper.readPropertiesContents(element, "properties");
+ result.setBuddyLocatorClass(buddyLocatorClass);
+ result.setBuddyLocatorProperties(props);
+ return result;
+ }
+
+ private void parseDataGravitationElement(Element element, BuddyReplicationConfig brc)
+ {
+ if (element == null) return;
+ String auto = element.getAttribute("auto");
+ if (existsAttribute(auto)) brc.setAutoDataGravitation(getBoolean(auto));
+ String removeOnFind = element.getAttribute("removeOnFind");
+ if (existsAttribute(removeOnFind)) brc.setDataGravitationRemoveOnFind(getBoolean(removeOnFind));
+ String searchBackupTrees = element.getAttribute("searchBackupTrees");
+ if (existsAttribute(searchBackupTrees)) brc.setDataGravitationSearchBackupTrees(getBoolean(searchBackupTrees));
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java (from rev 5987, core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.config.parsing;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Parser able to parse a series of cache configurations stored in an
+ * XML document with the following structure:
+ * <pre>
+ * <cache-configs>
+ * <cache-config name="configA">
+ * ....
+ * </cache-config>
+ * <cache-config name="configB">
+ * ....
+ * </cache-config>
+ * </cache-configs>
+ * </pre>
+ * <p/>
+ * The '....' represents the normal content of the mbean element in a
+ * JBC -service.xml config file.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class CacheConfigsXmlParser
+ {
+ /** Name of the root element in a cache configs XML document*/
+ public static final String DOCUMENT_ROOT = "cache-configs";
+ /**
+ * Name of the element that represents an individual cache configuration
+ * in a cache configs XML document.
+ */
+ public static final String CONFIG_ROOT = "cache-config";
+ /**
+ * Name of the attribute in a {@link #CONFIG_ROOT cache-config} element that specifies
+ * the name of the configuration.
+ */
+ public static final String CONFIG_NAME = "name";
+
+ private static final Log log = LogFactory.getLog(CacheConfigsXmlParser.class);
+
+ private final XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+
+ public Map<String, Configuration> parseConfigs(String fileName) throws CloneNotSupportedException
+ {
+ InputStream is = getAsInputStreamFromClassLoader(fileName);
+ if (is == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unable to find configuration file " + fileName + " in classpath; searching for this file on the filesystem instead.");
+ try
+ {
+ is = new FileInputStream(fileName);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ConfigurationException("Unable to find config file " + fileName + " either in classpath or on the filesystem!", e);
+ }
+ }
+
+ return parseConfigs(is);
+ }
+
+ public Map<String, Configuration> parseConfigs(InputStream stream) throws CloneNotSupportedException
+ {
+ // loop through all elements in XML.
+ Element root = XmlConfigHelper.getDocumentRoot(stream);
+ NodeList list = root.getElementsByTagName(CONFIG_ROOT);
+ if (list == null || list.getLength() == 0)
+ throw new ConfigurationException("Can't find " + CONFIG_ROOT + " tag");
+
+ Map<String, Configuration> result = new HashMap<String, Configuration>();
+
+ for (int i = 0; i < list.getLength(); i++)
+ {
+ Node node = list.item(i);
+ if (node.getNodeType() != Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+
+ Element element = (Element) node;
+ String name = element.getAttribute(CONFIG_NAME);
+ if (name == null || name.trim().length() == 0)
+ throw new ConfigurationException("Element " + element + " has no name attribute");
+
+ Configuration c = parser.parseConfiguration(element);
+ // Prove that we can successfully clone it
+ c = c.clone();
+ result.put(name.trim(), c);
+ }
+
+ return result;
+ }
+
+ protected InputStream getAsInputStreamFromClassLoader(String filename)
+ {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+ if (is == null)
+ {
+ // check system class loader
+ is = getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ return is;
+ }
+ }
\ No newline at end of file
Property changes on: core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,103 @@
+package org.jboss.cache.config.parsing;
+
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.ConfigurationException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.Properties;
+
+/**
+ * Utility class for parsing the 'caceheloaders' element in the .xml configuration file.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class CacheLoadersElementParser extends XmlParserBase
+{
+
+ public CacheLoaderConfig parseCacheLoadersElement(Element element)
+ {
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ String passivation = element.getAttribute("passivation");
+ if (existsAttribute(passivation)) cacheLoaderConfig.setPassivation(getBoolean(passivation));
+ String shared = element.getAttribute("shared");
+ if (existsAttribute(shared)) cacheLoaderConfig.setShared(getBoolean(shared));
+ String preload = getPreloadString(getSingleElement("preload", element));
+ if (preload != null) cacheLoaderConfig.setPreload(preload);
+
+ NodeList cacheLoaderNodes = element.getElementsByTagName("cacheLoader");
+ for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
+ {
+ Element indivElement = (Element) cacheLoaderNodes.item(i);
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = parseIndividualCacheLoaderConfig(indivElement);
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(iclc);
+ }
+
+ return cacheLoaderConfig;
+ }
+
+ private CacheLoaderConfig.IndividualCacheLoaderConfig parseIndividualCacheLoaderConfig(Element indivElement)
+ {
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+
+ String async = indivElement.getAttribute("async");
+ if (existsAttribute(async)) iclc.setAsync(getBoolean(async));
+ String fetchPersistentState = indivElement.getAttribute("fetchPersistentState");
+ if (existsAttribute(fetchPersistentState)) iclc.setFetchPersistentState(getBoolean(fetchPersistentState));
+ String ignoreModifications = indivElement.getAttribute("ignoreModifications");
+ if (existsAttribute(ignoreModifications)) iclc.setIgnoreModifications(getBoolean(ignoreModifications));
+ String purgeOnStartup = indivElement.getAttribute("purgeOnStartup");
+ if (existsAttribute(purgeOnStartup)) iclc.setPurgeOnStartup(getBoolean(purgeOnStartup));
+ String clClass = indivElement.getAttribute("class");
+ if (!existsAttribute(clClass)) throw new ConfigurationException("Missing 'class' attribute for cache loader configuration");
+ iclc.setClassName(clClass);
+ iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = parseSingletonStoreConfig(indivElement);
+ if (ssc != null)
+ {
+ iclc.setSingletonStoreConfig(ssc);
+ }
+ return iclc;
+ }
+
+ private String getPreloadString(Element preloadElement)
+ {
+ if (preloadElement == null) return null; //might be no preload
+ NodeList nodesToPreload = preloadElement.getElementsByTagName("node");
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < nodesToPreload.getLength(); i++)
+ {
+ Element node = (Element) nodesToPreload.item(i);
+ String fqn2preload = node.getAttribute("fqn");
+ if (!existsAttribute(fqn2preload)) throw new ConfigurationException("Missing 'fqn' attribute in 'preload\\norde' tag");
+ if (i > 0) result.append(",");
+ result.append(fqn2preload);
+ }
+ return result.toString();
+ }
+
+ static CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig parseSingletonStoreConfig(Element cacheLoaderelement)
+ {
+ /* singletonStore element can only appear once in a cacheloader, so we just take the first one ignoring any
+ subsequent definitions in cacheloader element*/
+ Node singletonStoreNode = cacheLoaderelement.getElementsByTagName("singletonStore").item(0);
+ if (singletonStoreNode != null && singletonStoreNode.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element singletonStoreElement = (Element) singletonStoreNode;
+ boolean singletonStoreEnabled = XmlConfigHelper.readBooleanContents(singletonStoreElement, "enabled");
+ String singletonStoreClass = XmlConfigHelper.readStringContents(singletonStoreElement, "class");
+ Properties singletonStoreproperties;
+ singletonStoreproperties = XmlConfigHelper.readPropertiesContents(singletonStoreElement, "properties");
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
+ ssc.setSingletonStoreEnabled(singletonStoreEnabled);
+ ssc.setSingletonStoreClass(singletonStoreClass);
+ ssc.setSingletonStoreproperties(singletonStoreproperties);
+
+ return ssc;
+ }
+
+ return null;
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,110 @@
+package org.jboss.cache.config.parsing;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.util.Util;
+import org.jboss.cache.RegionManager;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Knows how to parse the <b>eviction</b> element uder a parser.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class EvictionElementParser extends XmlParserBase
+{
+ public EvictionConfig getEvictionConfig(Element evictionElement)
+ {
+ EvictionConfig evictionConfig = new EvictionConfig();
+ String wakeUpInterval = evictionElement.getAttribute("wakeUpInterval");
+ if (existsAttribute(wakeUpInterval)) evictionConfig.setWakeupInterval(getInt(wakeUpInterval));
+ String defaultPolicyClass = evictionElement.getAttribute("defaultPolicyClass");
+ if (existsAttribute(defaultPolicyClass)) evictionConfig.setDefaultEvictionPolicyClass(defaultPolicyClass);
+ String defaultEventQueueSize = evictionElement.getAttribute("defaultEventQueueSize");
+ if (existsAttribute(defaultEventQueueSize)) evictionConfig.setDefaultEventQueueSize(getInt(defaultEventQueueSize));
+ List<EvictionRegionConfig> evictionRegionConfigs = new ArrayList<EvictionRegionConfig>(3);
+ Element defaultRegion = getSingleElement("default", evictionElement);
+ if (defaultRegion != null)
+ {
+ EvictionRegionConfig erc = getEvictionRegionConfig(defaultRegion, defaultPolicyClass, getInt(defaultEventQueueSize));
+ erc.setRegionName(RegionManager.DEFAULT_REGION.toString());
+ evictionRegionConfigs.add(erc);
+ }
+ NodeList regions = evictionElement.getElementsByTagName("region");
+ for (int i = 0; i < regions.getLength(); i++)
+ {
+ Element regionConfig = (Element) regions.item(i);
+ EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig, defaultPolicyClass, getInt(defaultEventQueueSize));
+ evictionRegionConfigs.add(erc);
+ }
+ evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
+ return evictionConfig;
+ }
+
+ private EvictionRegionConfig getEvictionRegionConfig(Element element, String defaultPolicyClass, int defaultEventQueueSize)
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionName(element.getAttribute("name"));
+ String queueSize = element.getAttribute("eventQueueSize");
+ if (existsAttribute(queueSize))
+ {
+ erc.setEventQueueSize(getInt(queueSize));
+ }
+ else
+ {
+ erc.setEventQueueSize(defaultEventQueueSize);
+ }
+ String policyClass = element.getAttribute("policyClass");
+ if (!existsAttribute(policyClass))
+ {
+ if (defaultPolicyClass == null)
+ {
+ throw new MissingPolicyException("There is no Eviction Policy Class specified on the region or for the entire cache!");
+ }
+ else
+ {
+ policyClass = defaultPolicyClass;
+ }
+ }
+ EvictionPolicy policy;
+ try
+ {
+ policy = (EvictionPolicy) Util.loadClass(policyClass).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
+ }
+
+ EvictionPolicyConfig epc;
+ try
+ {
+ epc = policy.getEvictionConfigurationClass().newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate eviction configuration of class " +
+ policy.getEvictionConfigurationClass(), e);
+ }
+ parseEvictionPolicyConfig(element, epc);
+ erc.setEvictionPolicyConfig(epc);
+ return erc;
+ }
+
+ public static void parseEvictionPolicyConfig(Element element, EvictionPolicyConfig target)
+ {
+ target.reset();
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
+ XmlConfigHelper.setValues(target, attributes.stringAttribs, false);
+ XmlConfigHelper.setValues(target, attributes.xmlAttribs, true);
+ target.validate();
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,70 @@
+package org.jboss.cache.config.parsing;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Attr;
+
+/**
+ * The purpose of this class is to parse the jgroups configuration from the config file into an compact string
+ * that can be passed as a config to the channel.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class JGroupsStackParser
+{
+
+ //todo - further refine in smaller methods and make not-static
+ /**
+ * Parses the cluster config which is used to start a JGroups channel
+ *
+ * @param config an old-style JGroups protocol config String
+ */
+ public static String parseClusterConfigXml(Element config)
+ {
+ StringBuffer buffer = new StringBuffer();
+ NodeList stack = config.getChildNodes();
+ int length = stack.getLength();
+
+ for (int s = 0; s < length; s++)
+ {
+ org.w3c.dom.Node node = stack.item(s);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+
+ Element tag = (Element) node;
+ String protocol = tag.getTagName();
+ buffer.append(protocol);
+ NamedNodeMap attrs = tag.getAttributes();
+ int attrLength = attrs.getLength();
+ if (attrLength > 0)
+ {
+ buffer.append('(');
+ }
+ for (int a = 0; a < attrLength; a++)
+ {
+ Attr attr = (Attr) attrs.item(a);
+ String name = attr.getName();
+ String value = attr.getValue();
+ buffer.append(name);
+ buffer.append('=');
+ buffer.append(value);
+ if (a < attrLength - 1)
+ {
+ buffer.append(';');
+ }
+ }
+ if (attrLength > 0)
+ {
+ buffer.append(')');
+ }
+ buffer.append(':');
+ }
+ // Remove the trailing ':'
+ buffer.setLength(buffer.length() - 1);
+ return buffer.toString();
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,21 @@
+package org.jboss.cache.config.parsing;
+
+import org.w3c.dom.Element;
+
+import java.util.Map;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+* @since 3.0
+*/
+public class ParsedAttributes
+{
+ public final Map<String, String> stringAttribs;
+ public final Map<String, Element> xmlAttribs;
+
+ ParsedAttributes(Map strings, Map elements)
+ {
+ this.stringAttribs = strings;
+ this.xmlAttribs = elements;
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java (from rev 5987, core/trunk/src/main/java/org/jboss/cache/xml/XmlHelper.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,542 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.config.parsing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.util.StringPropertyReplacer;
+import org.jboss.cache.util.BeanUtils;
+import org.jboss.cache.config.ConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Method;
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+
+/**
+ * A simple XML utility class for reading configuration elements
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ */
+public class XmlConfigHelper
+{
+ private static final Log log = LogFactory.getLog(XmlConfigHelper.class);
+
+ /**
+ * The root of a JBoss Cache configuration XML file. This is the <tt><mbean></tt> tag.
+ */
+ public static final String ROOT = "mbean";
+
+ /**
+ * The <tt><attribute></tt> tag which forms the bulk of JBoss Cache configuration elements
+ */
+ public static final String ATTR = "attribute";
+
+ /**
+ * The <tt><config></tt> tag may be embedded in the contents of an <tt><attribute></tt>, to specify more
+ * complex configuration for certain parameters.
+ */
+ public static final String CONFIG_ATTR = "config";
+
+ /**
+ * The <tt><name></tt> attribute to an <tt><attribute></tt> tag.
+ */
+ public static final String NAME = "name";
+
+
+ /**
+ * Returns the contents of a specific node of given element name, provided a certain attribute exists and is set to value.
+ * E.g., if you have a {@link Element} which represents the following XML snippet:
+ * <pre>
+ * <ItemQuantity Colour="Red">100</ItemQuantity>
+ * <ItemQuantity Colour="Blue">30</ItemQuantity>
+ * <ItemQuantity Colour="Black">10</ItemQuantity>
+ * <pre>
+ * <p/>
+ * The following results could be expected:
+ * </p>
+ * <pre>
+ * getTagContents(element, "Red", "ItemQuantity", "Colour"); // 100
+ * getTagContents(element, "Black", "ItemQuantity", "Colour"); // 10
+ * getTagContents(element, "Blah", "ItemQuantity", "Colour"); // null
+ * getTagContents(element, "Red", "Blah", "Colour"); // null
+ * getTagContents(element, "Black", "ItemQuantity", "Blah"); // null
+ * </pre>
+ * <p/>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ * </p>
+ *
+ * @param elem - element to search through.
+ * @param value - expected value to match against
+ * @param elementName - element name
+ * @param attributeName - attribute name of the element that would contain the expected value.
+ * @return the contents of the matched element, or null if not found/matched
+ */
+ public static String getTagContents(Element elem, String value, String elementName, String attributeName)
+ {
+ NodeList list = elem.getElementsByTagName(elementName);
+
+ for (int s = 0; s < list.getLength(); s++)
+ {
+ org.w3c.dom.Node node = list.item(s);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ continue;
+
+ Element element = (Element) node;
+ String name = element.getAttribute(attributeName);
+ if (name.equals(value))
+ {
+ return getElementContent(element, true);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Retrieves the value of a given attribute for the first encountered instance of a tag in an element.
+ * <p/>
+ * E.g., if you have a {@link Element} which represents the following XML snippet:
+ * </p>
+ * <pre>
+ * <ItemQuantity Colour="Red">100</ItemQuantity>
+ * <ItemQuantity Colour="Blue">30</ItemQuantity>
+ * <ItemQuantity Colour="Black">10</ItemQuantity>
+ * <pre>
+ * <p/>
+ * The following results could be expected:
+ * </p>
+ * <pre>
+ * getAttributeValue(element, "ItemQuantity", "Colour"); // "Red"
+ * getTagContents(element, "Blah", "Colour"); // null
+ * getTagContents(element, "ItemQuantity", "Blah"); // null
+ * </pre>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ *
+ * @param elem - element to search through.
+ * @param elementName - element name
+ * @param attributeName - attribute name of the element that would contain the expected value.
+ * @return the contents of the matched attribute, or null if not found/matched
+ */
+ public static String getAttributeValue(Element elem, String elementName, String attributeName)
+ {
+ NodeList list = elem.getElementsByTagName(elementName);
+
+ for (int s = 0; s < list.getLength(); s++)
+ {
+ org.w3c.dom.Node node = list.item(s);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ continue;
+
+ Element element = (Element) node;
+ String value = element.getAttribute(attributeName);
+ return value == null ? null : StringPropertyReplacer.replaceProperties(value);
+
+ }
+ return null;
+ }
+
+ /**
+ * Convenience method, equivalent to calling <tt>getSubElement(element, "config");</tt>
+ */
+ public static Element getConfigSubElement(Element element)
+ {
+ return getSubElement(element, CONFIG_ATTR);
+ }
+
+ /**
+ * Returns a named sub-element of the current element passed in.
+ * <p/>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ *
+ * @param element - element to search through.
+ * @param subElementName - the name of a sub element to look for
+ * @return the first matching sub element, if found, or null otherwise.
+ */
+ public static Element getSubElement(Element element, String subElementName)
+ {
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node node = nl.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE && subElementName.equals(((Element) node).getTagName()))
+ {
+ return (Element) node;
+ }
+ }
+
+ if (log.isDebugEnabled()) log.debug("getSubElement(): Does not exist for " + subElementName);
+ return null;
+ }
+
+ /**
+ * Reads the contents of the element passed in.
+ * <p/>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ *
+ * @param element - element to search through.
+ * @param trim - if true, whitespace is trimmed before returning
+ * @return the contents of the element passed in. Will return an empty String if the element is empty.
+ */
+ public static String getElementContent(Element element, boolean trim)
+ {
+ NodeList nl = element.getChildNodes();
+ String attributeText = "";
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+ if (n instanceof Text)
+ {
+ attributeText += StringPropertyReplacer.replaceProperties(((Text) n).getData());
+ }
+ } // end of for ()
+ if (trim)
+ attributeText = attributeText.trim();
+ return attributeText;
+ }
+
+ /**
+ * Reads the contents of the first occurence of elementName under the given element, trimming results of whitespace.
+ * <p/>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ *
+ * @param element - element to search through.
+ * @param elementName - name of the element to find within the element passed in
+ * @return may return an empty String of not found.
+ */
+ public static String readStringContents(Element element, String elementName)
+ {
+ NodeList nodes = element.getElementsByTagName(elementName);
+ if (nodes.getLength() > 0)
+ {
+ Node node = nodes.item(0);
+ Element ne = (Element) node;
+ NodeList nl2 = ne.getChildNodes();
+ Node node2 = nl2.item(0);
+ if (node2 != null)
+ {
+ String value = node2.getNodeValue();
+ if (value == null)
+ return "";
+ return StringPropertyReplacer.replaceProperties(value.trim());
+ }
+ else
+ {
+ return "";
+ }
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+ /**
+ * Escapes backslashes ('\') with additional backslashes in a given String, returning a new, escaped String.
+ *
+ * @param value String to escape. Cannot be null.
+ * @return escaped String. Never is null.
+ */
+ public static String escapeBackslashes(String value)
+ {
+ StringBuffer buf = new StringBuffer(value);
+ for (int looper = 0; looper < buf.length(); looper++)
+ {
+ char curr = buf.charAt(looper);
+ char next = 0;
+ if (looper + 1 < buf.length())
+ next = buf.charAt(looper + 1);
+
+ if (curr == '\\')
+ {
+ if (next != '\\')
+ { // only if not already escaped
+ buf.insert(looper, '\\'); // escape backslash
+ }
+ looper++; // skip past extra backslash (either the one we added or existing)
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Reads the contents of a named sub element within a given element, and attempts to parse the contents as a Java
+ * properties file.
+ * <p/>
+ * E.g., if you have a {@link Element} which represents the following XML snippet:
+ * <p/>
+ * <pre>
+ * <props>
+ * my.attrib.1 = blah
+ * my.attrib.2 = blahblah
+ * </props>
+ * <pre>
+ * <p/>
+ * The following results could be expected:
+ * <p/>
+ * <pre>
+ * Properties p = readPropertiesContents(element, "props");
+ * p.getProperty("my.attrib.1"); // blah
+ * p.getProperty("my.attrib.2"); // blahblah
+ * </pre>
+ * None of the parameters should be null - otherwise the method may throw a NullPointerException.
+ *
+ * @param element - element to search through.
+ * @param elementName - name of the element to find within the element passed in
+ * @return a {@link Properties} object, never null.
+ * @throws IOException if unable to parse the contents of the element
+ */
+ public static Properties readPropertiesContents(Element element, String elementName)
+ {
+ String stringContents = readStringContents(element, elementName);
+ if (stringContents == null) return new Properties();
+ // JBCACHE-531: escape all backslash characters
+ stringContents = escapeBackslashes(stringContents);
+ ByteArrayInputStream is = null;
+ Properties properties = null;
+ try
+ {
+ is = new ByteArrayInputStream(stringContents.trim().getBytes("ISO8859_1"));
+ properties = new Properties();
+ properties.load(is);
+ is.close();
+ } catch (IOException e)
+ {
+ log.warn("Unexpected",e);
+ throw new ConfigurationException("Exception occured while reading properties from XML document",e);
+ }
+ return properties;
+ }
+
+ /**
+ * Similar to {@link #readStringContents(org.w3c.dom.Element,String)} except that it returns a boolean.
+ *
+ * @param element - element to search through.
+ * @param elementName - name of the element to find within the element passed in
+ * @return the contents of the element as a boolean, or false if not found.
+ */
+ public static boolean readBooleanContents(Element element, String elementName)
+ {
+ return readBooleanContents(element, elementName, false);
+ }
+
+ /**
+ * Similar to {@link #readStringContents(org.w3c.dom.Element,String)} except that it returns a boolean.
+ *
+ * @param element - element to search through.
+ * @param elementName - name of the element to find within the element passed in
+ * @param defaultValue - value to return if the element is not found or cannot be parsed.
+ * @return the contents of the element as a boolean
+ */
+ public static boolean readBooleanContents(Element element, String elementName, boolean defaultValue)
+ {
+ String val = readStringContents(element, elementName);
+ if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("false"))
+ {
+ // needs to be done this way because of JBBUILD-351
+ return Boolean.valueOf(val);
+ //return Boolean.parseBoolean(val);
+ }
+ return defaultValue;
+ }
+
+ /**
+ * Converts a String representing an XML snippet into an {@link org.w3c.dom.Element}.
+ *
+ * @param xml snippet as a string
+ * @return a DOM Element
+ * @throws Exception if unable to parse the String or if it doesn't contain valid XML.
+ */
+ public static Element stringToElement(String xml) throws Exception
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document d = builder.parse(bais);
+ bais.close();
+ return d.getDocumentElement();
+ }
+
+ /**
+ * Returns the root element of a given input stream
+ *
+ * @param is stream to parse
+ * @return XML DOM element, or null if unable to parse stream
+ */
+ public static Element getDocumentRoot(InputStream is)
+ {
+ Document doc;
+ try
+ {
+ InputSource xmlInp = new InputSource(is);
+
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
+ doc = parser.parse(xmlInp);
+ Element root = doc.getDocumentElement();
+ root.normalize();
+ return root;
+ }
+ catch (SAXParseException err)
+ {
+ log.error("Configurator SAXParse error", err);
+ }
+ catch (SAXException e)
+ {
+ log.error("Configurator SAX error", e);
+ }
+ catch (Exception pce)
+ {
+ log.error("Configurator general error", pce);
+ }
+ return null;
+ }
+
+ /**
+ * Retrieves the boolean value of a given attribute for the first encountered instance of elementName
+ *
+ * @param elem - element to search
+ * @param elementName - name of element to find
+ * @param attributeName - name of attribute to retrieve the value of
+ * @param defaultValue - default value to return if not found
+ */
+ public static boolean readBooleanAttribute(Element elem, String elementName, String attributeName, boolean defaultValue)
+ {
+ String val = getAttributeValue(elem, elementName, attributeName);
+ if (val != null)
+ {
+ if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("false"))
+ {
+ //return Boolean.parseBoolean(val);
+ // needs to be done this way because of JBBUILD-351
+ return Boolean.valueOf(val);
+ }
+ }
+
+ return defaultValue;
+ }
+
+ public static void setValues(Object target, Map<?, ?> attribs, boolean isXmlAttribs)
+ {
+ Class objectClass = target.getClass();
+
+ // go thru simple string setters first.
+ for (Map.Entry entry : attribs.entrySet())
+ {
+ String propName = (String) entry.getKey();
+ String setter = BeanUtils.setterName(propName);
+ Method method;
+
+ try
+ {
+ if (isXmlAttribs)
+ {
+ method = objectClass.getMethod(setter, Element.class);
+ method.invoke(target, entry.getValue());
+ }
+ else
+ {
+ method = objectClass.getMethod(setter, String.class);
+ method.invoke(target, entry.getValue());
+ }
+
+ continue;
+ }
+ catch (NoSuchMethodException me)
+ {
+ // this is ok, but certainly log this as a warning
+ // this is hugely noisy!
+ //if (log.isWarnEnabled()) log.warn("Unrecognised attribute " + propName + ". Please check your configuration. Ignoring!!");
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
+ }
+
+ // if we get here, we could not find a String or Element setter.
+ for (Method m : objectClass.getMethods())
+ {
+ if (setter.equals(m.getName()))
+ {
+ Class paramTypes[] = m.getParameterTypes();
+ if (paramTypes.length != 1)
+ {
+ throw new ConfigurationException("Setter " + setter + " does not contain the expected number of params. Has " + paramTypes.length + " instead of just 1.");
+ }
+
+ Class parameterType = paramTypes[0];
+ PropertyEditor editor = PropertyEditorManager.findEditor(parameterType);
+ if (editor == null)
+ {
+ throw new ConfigurationException("Couldn't find a property editor for parameter type " + parameterType);
+ }
+
+ editor.setAsText((String) attribs.get(propName));
+
+ Object parameter = editor.getValue();
+ //if (log.isDebugEnabled()) log.debug("Invoking setter method: " + setter + " with parameter \"" + parameter + "\" of type " + parameter.getClass());
+
+ try
+ {
+ m.invoke(target, parameter);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
+ }
+ }
+ }
+ }
+ }
+
+ public static ParsedAttributes extractAttributes(Element source)
+ {
+ Map<String, String> stringAttribs = new HashMap<String, String>();
+ Map<String, Element> xmlAttribs = new HashMap<String, Element>();
+ NodeList list = source.getElementsByTagName(ATTR);
+ if (log.isDebugEnabled()) log.debug("Attribute size: " + list.getLength());
+
+ // loop through attributes
+ for (int loop = 0; loop < list.getLength(); loop++)
+ {
+ Node node = list.item(loop);
+ if (node.getNodeType() != Node.ELEMENT_NODE) continue;
+
+ // for each element (attribute) ...
+ Element element = (Element) node;
+ String name = element.getAttribute(NAME);
+ String valueStr = getElementContent(element, true);
+
+ Element valueXml = null;
+ if (valueStr.length() == 0)
+ {
+ // This may be an XML element ...
+ valueXml = getConfigSubElement(element);
+ }
+
+ // add these to the maps.
+
+ if (valueStr.length() > 0) stringAttribs.put(name, valueStr);
+ if (valueXml != null) xmlAttribs.put(name, valueXml);
+ }
+
+ return new ParsedAttributes(stringAttribs, xmlAttribs);
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java (from rev 5987, core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,290 @@
+package org.jboss.cache.config.parsing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.*;
+import org.jboss.cache.lock.IsolationLevel;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class XmlConfigurationParser extends XmlParserBase
+{
+ private static final Log log = LogFactory.getLog(XmlConfigurationParser.class);
+
+ private Configuration config = new Configuration();
+ private Element root;
+
+
+ /**
+ * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
+ * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
+ * absolute path.
+ */
+ public Configuration parseFile(String filename)
+ {
+ InputStream is = getAsInputStreamFromClassLoader(filename);
+ if (is == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unable to find configuration file " + filename + " in classpath; searching for this file on the filesystem instead.");
+ try
+ {
+ is = new FileInputStream(filename);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!", e);
+ }
+ }
+
+ return parse(is);
+ }
+
+ protected InputStream getAsInputStreamFromClassLoader(String filename)
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl == null ? null : cl.getResourceAsStream(filename);
+ if (is == null)
+ {
+ // check system class loader
+ is = getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ return is;
+ }
+
+ public Configuration parse(InputStream configStream)
+ {
+ readRoot(configStream);
+ configureLocking(getSingleElement("locking"));
+ configureTransaction(getSingleElement("transaction"));
+ configureReplication(getSingleElement("replication"));
+ configureSerialization(getSingleElement("serialization"));
+ configureInvalidation(getSingleElement("invalidation"));
+ configureStartup(getSingleElement("startup"));
+ configureTransport(getSingleElement("transport"));
+ configureShutdown(getSingleElement("shutdown"));
+ configureJmxStatistics(getSingleElement("jmxStatistics"));
+ configureEviction(getSingleElement("eviction"));
+ configureCacheLoaders(getSingleElement("cacheLoaders"));
+ configureBuddyReplication(getSingleElement("buddyReplication"));
+ configureCustomInterceptors(getSingleElement("customInterceptors"));
+ return config;
+ }
+
+ private void configureTransaction(Element element)
+ {
+ if (element == null) return;
+ String txMngLookupClass = element.getAttribute("transactionManagerLookupClass");
+ if (existsAttribute(txMngLookupClass)) config.setTransactionManagerLookupClass(txMngLookupClass);
+ String syncRollbackPhase = element.getAttribute("syncRollbackPhase");
+ if (existsAttribute(syncRollbackPhase)) config.setSyncRollbackPhase(getBoolean(syncRollbackPhase));
+ String syncCommitPhase = element.getAttribute("syncCommitPhase");
+ if (existsAttribute(syncCommitPhase)) config.setSyncCommitPhase(getBoolean(syncCommitPhase));
+ }
+
+ private void configureSerialization(Element element)
+ {
+ if (element == null) return;
+ String objectInputStreamPoolSize = element.getAttribute("objectInputStreamPoolSize");
+ if (existsAttribute(objectInputStreamPoolSize)) config.setObjectInputStreamPoolSize(getInt(objectInputStreamPoolSize));
+ String objectOutputStreamPoolSize = element.getAttribute("objectOutputStreamPoolSize");
+ if (existsAttribute(objectOutputStreamPoolSize)) config.setObjectOutputStreamPoolSize(getInt(objectOutputStreamPoolSize));
+ String version = element.getAttribute("version");
+ if (existsAttribute(version)) config.setReplVersionString(version);
+ String marshallerClass = element.getAttribute("marshallerClass");
+ if (existsAttribute(marshallerClass)) config.setMarshallerClass(marshallerClass);
+ String useLazyDeserialization = element.getAttribute("useLazyDeserialization");
+ if (existsAttribute(useLazyDeserialization)) config.setUseLazyDeserialization(getBoolean(useLazyDeserialization));
+ String useRegionBasedMarshalling = element.getAttribute("useRegionBasedMarshalling");
+ if (existsAttribute(useRegionBasedMarshalling)) config.setUseRegionBasedMarshalling(getBoolean(useRegionBasedMarshalling));
+ }
+
+ private void configureCustomInterceptors(Element singleElement)
+ {
+ if (singleElement == null) return; //this element might be missing
+ NodeList interceptorNodes = singleElement.getElementsByTagName("interceptor");
+ List<CustomInterceptorConfig> interceptorConfigs = new ArrayList<CustomInterceptorConfig>(interceptorNodes.getLength());
+ for (int i = 0; i < interceptorNodes.getLength(); i++)
+ {
+ Element interceptorElement = (Element) interceptorNodes.item(i);
+ String interceptorClass = interceptorElement.getAttribute("class");
+ Properties props = XmlConfigHelper.readPropertiesContents(interceptorElement, "properties");
+ Element position = getSingleElement("position", interceptorElement);
+ String firstStr = position.getAttribute("first");
+ boolean first = existsAttribute(firstStr) && getBoolean(firstStr);
+ String lastStr = position.getAttribute("last");
+ boolean last = existsAttribute(lastStr) && getBoolean(lastStr);
+ String indexStr = position.getAttribute("index");
+ int index = existsAttribute(indexStr) ? getInt(indexStr) : -1;
+ String before = position.getAttribute("before");
+ if (!existsAttribute(before)) before = null;
+ String after = position.getAttribute("after");
+ if (!existsAttribute(after)) after = null;
+ CustomInterceptorConfig customInterceptorConfig = new CustomInterceptorConfig(interceptorClass, first, last,
+ index, after, before, props);
+ interceptorConfigs.add(customInterceptorConfig);
+ }
+ config.setCustomInterceptors(interceptorConfigs);
+ }
+
+ private void configureBuddyReplication(Element element)
+ {
+ if (element == null) return;//buddy config might not exist, expect that
+ BuddyReplicationElementParser buddyElementParser = new BuddyReplicationElementParser();
+ BuddyReplicationConfig brConfig = buddyElementParser.parseBuddyReplicationElement(element);
+ config.setBuddyReplicationConfig(brConfig);
+ }
+
+ private void configureCacheLoaders(Element element)
+ {
+ if (element == null) return; //null cache loaders are allowed
+ CacheLoadersElementParser clElementParser = new CacheLoadersElementParser();
+ CacheLoaderConfig cacheLoaderConfig = clElementParser.parseCacheLoadersElement(element);
+ config.setCacheLoaderConfig(cacheLoaderConfig);
+ }
+
+ private void configureEviction(Element evictionElement)
+ {
+ if (evictionElement == null) return; //no eviction might be configured
+ EvictionElementParser evictionElementParser = new EvictionElementParser();
+ config.setEvictionConfig(evictionElementParser.getEvictionConfig(evictionElement));
+ }
+
+
+ private void configureJmxStatistics(Element element)
+ {
+ if (element == null) return; //might not be specified
+ String enabled = element.getAttribute("enabled");
+ if (enabled != null) config.setExposeManagementStatistics(getBoolean(enabled));
+ }
+
+ private void configureShutdown(Element element)
+ {
+ if (element == null) return;
+ String hookBehavior = element.getAttribute("hookBehavior");
+ if (hookBehavior != null) config.setShutdownHookBehavior(hookBehavior);
+ }
+
+ private void configureTransport(Element element)
+ {
+ String clusterName = element.getAttribute("clusterName");
+ config.setClusterName(clusterName);
+ Element multiplexer = getSingleElement("multiplexer", element);
+ if (multiplexer != null)
+ {
+ config.setMultiplexerStack(multiplexer.getAttribute("stack"));
+ }
+ Element clusterConfig = getSingleElement("jgroupsConfig", element);
+ if (clusterConfig != null)
+ {
+ String clusterConfigStr = JGroupsStackParser.parseClusterConfigXml(clusterConfig);
+ config.setClusterConfig(clusterConfigStr);
+ }
+ }
+
+ private void configureStartup(Element element)
+ {
+ if (element == null) return; //we might not have this configured
+ String fetchInMemoryState = element.getAttribute("fetchInMemoryState");
+ if (fetchInMemoryState != null) config.setFetchInMemoryState(getBoolean(fetchInMemoryState));
+ String stateRetrievalTimeout = element.getAttribute("stateRetrievalTimeout");
+ if (stateRetrievalTimeout != null) config.setStateRetrievalTimeout(getLong(stateRetrievalTimeout));
+ String inactiveOnStartup = element.getAttribute("inactiveOnStartup");
+ if (inactiveOnStartup != null) config.setInactiveOnStartup(getBoolean(inactiveOnStartup));
+ }
+
+ private void configureInvalidation(Element element)
+ {
+ if (element == null) return; //might be replication
+ Element async = getSingleElement("async");
+ if (async != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
+ configureAsyncMode(getSingleElement("async", element));
+ }
+ Element sync = getSingleElement("sync");
+ if (sync != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ configureSyncMode(getSingleElement("sync", element));
+ }
+ }
+
+ private void configureReplication(Element element)
+ {
+ if (element == null) return; //might be we do not have a replication enabled
+ Element async = getSingleElement("async");
+ if (async != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+ configureAsyncMode(getSingleElement("async", element));
+ }
+ Element sync = getSingleElement("sync");
+ if (sync != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ configureSyncMode(getSingleElement("sync", element));
+ }
+ }
+
+ private void configureSyncMode(Element element)
+ {
+ String replTimeout = element.getAttribute("replTimeout");
+ if (replTimeout != null) config.setSyncReplTimeout(getLong(replTimeout));
+ }
+
+ private void configureAsyncMode(Element element)
+ {
+ String useReplQueue = element.getAttribute("useReplQueue");
+ if (existsAttribute(useReplQueue)) config.setUseReplQueue(getBoolean(useReplQueue));
+ String replQueueInterval = element.getAttribute("replQueueInterval");
+ if (replQueueInterval != null) config.setReplQueueInterval(getLong(replQueueInterval));
+ String replQueueMaxElements = element.getAttribute("replQueueMaxElements");
+ if (replQueueMaxElements != null) config.setReplQueueMaxElements(getInt(replQueueMaxElements));
+ }
+
+ private void configureLocking(Element locking)
+ {
+ String isolationLevel = locking.getAttribute("isolationLevel");
+ if (isolationLevel != null) config.setIsolationLevel(IsolationLevel.valueOf(isolationLevel));
+ String lockParentForChildInsertRemove = locking.getAttribute("lockParentForChildInsertRemove");
+ if (lockParentForChildInsertRemove != null)
+ config.setLockParentForChildInsertRemove(getBoolean(lockParentForChildInsertRemove));
+ String lockAcquisitionTimeout = locking.getAttribute("lockAcquisitionTimeout");
+ if (lockAcquisitionTimeout != null) config.setLockAcquisitionTimeout(getLong(lockAcquisitionTimeout));
+ }
+
+ private Element getSingleElement(String elementName)
+ {
+ return getSingleElement(elementName, root);
+ }
+
+ private void readRoot(InputStream config)
+ {
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
+ Document doc = parser.parse(config);
+ root = doc.getDocumentElement();
+ root.normalize();
+ } catch (Exception e)
+ {
+ throw new ConfigurationException("Could not parse the ");
+ }
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java (from rev 5987, core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,536 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.config.parsing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.util.Util;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+/**
+ * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object. When deployed as a
+ * JBoss MBean, this role is performed by the JBoss Microcontainer. This class is only used internally in unit tests
+ * or within {@link org.jboss.cache.CacheFactory} implementations for standalone JBoss Cache usage.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
+ * @since 2.00.
+ * @deprecated
+ */
+public class XmlConfigurationParserOld
+{
+ private static final Log log = LogFactory.getLog(XmlConfigurationParserOld.class);
+
+ public static final String ATTR = "attribute";
+ public static final String NAME = "name";
+
+ /**
+ * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
+ * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
+ * absolute path.
+ *
+ * @param filename the name of the XML file to parse.
+ * @return a configured Configuration object representing the configuration in the file
+ */
+ public Configuration parseFile(String filename)
+ {
+ InputStream is = getAsInputStreamFromClassLoader(filename);
+ if (is == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unable to find configuration file " + filename + " in classpath; searching for this file on the filesystem instead.");
+ try
+ {
+ is = new FileInputStream(filename);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!", e);
+ }
+ }
+
+ return parseStream(is);
+ }
+
+ /**
+ * Parses an input stream containing XML text and returns a new configuration.
+ *
+ * @param stream input stream to parse. SHould not be null.
+ * @return a configured Configuration object representing the configuration in the stream
+ * @since 2.1.0
+ */
+ public Configuration parseStream(InputStream stream)
+ {
+ // loop through all elements in XML.
+ Element root = XmlConfigHelper.getDocumentRoot(stream);
+ Element mbeanElement = getMBeanElement(root);
+
+ return parseConfiguration(mbeanElement);
+ }
+
+ public Configuration parseConfiguration(Element configurationRoot)
+ {
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(configurationRoot);
+
+ // Deal with legacy attributes we no longer support
+ handleRemovedAttributes(attributes);
+
+ // Deal with legacy attributes that we renamed or otherwise altered
+ handleRenamedAttributes(attributes);
+
+ Configuration c = new Configuration();
+ XmlConfigHelper.setValues(c, attributes.stringAttribs, false);
+ // Special handling for XML elements -- we hard code the parsing
+ setXmlValues(c, attributes.xmlAttribs);
+
+ return c;
+ }
+
+ /**
+ * Check for and remove any attributes that were supported in the
+ * 1.x releases and no longer are. Log a WARN or throw a
+ * {@link ConfigurationException} if any are found. Which is done depends
+ * on the attribute:
+ * <p/>
+ * <ul>
+ * <li><i>MultiplexerService</i> -- throws an Exception</li>
+ * <li><i>ServiceName</i> -- logs a WARN</li>
+ * </ul>
+ *
+ * @param attributes
+ */
+ protected void handleRemovedAttributes(ParsedAttributes attributes)
+ {
+ String evictionPolicy = attributes.stringAttribs.remove("EvictionPolicyClass");
+ if (evictionPolicy != null)
+ {
+ throw new ConfigurationException("XmlConfigurationParser does not " +
+ "support the JBC 1.x attribute EvictionPolicyClass. Set the default " +
+ "eviction policy via the policyClass element in the EvictionConfig section");
+ }
+ String multiplexerService = attributes.stringAttribs.remove("MultiplexerService");
+ if (multiplexerService != null)
+ {
+ throw new ConfigurationException("XmlConfigurationParser does not " +
+ "support the JBC 1.x attribute MultiplexerService. Inject the " +
+ "multiplexer directly using Configuration.getRuntimeConfig().setMuxChannelFactory()");
+ }
+ String serviceName = attributes.stringAttribs.remove("ServiceName");
+ if (serviceName != null)
+ {
+ log.warn("XmlConfigurationParser does not support the deprecated " +
+ "attribute ServiceName. If JMX registration is needed, " +
+ "register a CacheJmxWrapper or PojoCacheJmxWrapper in " +
+ "JMX with the desired name");
+ }
+ }
+
+ /**
+ * Check for any attributes that were supported in the
+ * 1.x releases but whose name has changed. Log a WARN if any are found, but
+ * convert the attribute to the new name.
+ * <p/>
+ * <ul>
+ * <li><i>UseMbean</i> becomes <i>ExposeManagementStatistics</i></li>
+ * </ul>
+ *
+ * @param attributes
+ */
+ private void handleRenamedAttributes(ParsedAttributes attributes)
+ {
+ String keepStats = attributes.stringAttribs.remove("UseInterceptorMbeans");
+ if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
+ {
+ log.warn("Found non-existent JBC 1.x attribute 'UseInterceptorMbeans' and replaced " +
+ "with 'ExposeManagementStatistics'. Please update your config " +
+ "to use the new attribute name");
+ attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
+ }
+ Element clc = attributes.xmlAttribs.remove("CacheLoaderConfiguration");
+ if (clc != null && attributes.xmlAttribs.get("CacheLoaderConfig") == null)
+ {
+ log.warn("Found non-existent JBC 1.x attribute 'CacheLoaderConfiguration' and replaced " +
+ "with 'CacheLoaderConfig'. Please update your config " +
+ "to use the new attribute name");
+ attributes.xmlAttribs.put("CacheLoaderConfig", clc);
+ }
+ }
+
+ protected InputStream getAsInputStreamFromClassLoader(String filename)
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl == null ? null : cl.getResourceAsStream(filename);
+ if (is == null)
+ {
+ // check system class loader
+ is = getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ return is;
+ }
+
+ protected Element getMBeanElement(Element root)
+ {
+ // This is following JBoss convention.
+ NodeList list = root.getElementsByTagName(XmlConfigHelper.ROOT);
+ if (list == null) throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " tag");
+
+ if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlConfigHelper.ROOT + " tag");
+
+ Node node = list.item(0);
+ Element element;
+ if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ element = (Element) node;
+ }
+ else
+ {
+ throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " element");
+ }
+ return element;
+ }
+
+ protected void setXmlValues(Configuration conf, Map<String, Element> attribs)
+ {
+ for (Entry<String, Element> entry : attribs.entrySet())
+ {
+ String propname = entry.getKey();
+ if ("BuddyReplicationConfiguration".equals(propname)
+ || "BuddyReplicationConfig".equals(propname))
+ {
+ BuddyReplicationConfig brc = parseBuddyReplicationConfig(entry.getValue());
+ conf.setBuddyReplicationConfig(brc);
+ }
+ else if ("CacheLoaderConfiguration".equals(propname)
+ || "CacheLoaderConfig".equals(propname))
+ {
+ CacheLoaderConfig clc = parseCacheLoaderConfig(entry.getValue());
+ conf.setCacheLoaderConfig(clc);
+ }
+ else if ("EvictionPolicyConfiguration".equals(propname)
+ || "EvictionPolicyConfig".equals(propname))
+ {
+ EvictionConfig ec = parseEvictionConfig(entry.getValue());
+ conf.setEvictionConfig(ec);
+ }
+ else if ("ClusterConfig".equals(propname))
+ {
+ String jgc = parseClusterConfigXml(entry.getValue());
+ conf.setClusterConfig(jgc);
+ }
+ else
+ {
+ throw new ConfigurationException("Unknown configuration element " + propname);
+ }
+ }
+ }
+
+ public static BuddyReplicationConfig parseBuddyReplicationConfig(Element element)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(XmlConfigHelper.readBooleanContents(element, "buddyReplicationEnabled"));
+ brc.setDataGravitationRemoveOnFind(XmlConfigHelper.readBooleanContents(element, "dataGravitationRemoveOnFind", true));
+ brc.setDataGravitationSearchBackupTrees(XmlConfigHelper.readBooleanContents(element, "dataGravitationSearchBackupTrees", true));
+ brc.setAutoDataGravitation(brc.isEnabled() && XmlConfigHelper.readBooleanContents(element, "autoDataGravitation", false));
+
+ String strBuddyCommunicationTimeout = XmlConfigHelper.readStringContents(element, "buddyCommunicationTimeout");
+ try
+ {
+ brc.setBuddyCommunicationTimeout(Integer.parseInt(strBuddyCommunicationTimeout));
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
+ }
+ }
+ String buddyPoolName = XmlConfigHelper.readStringContents(element, "buddyPoolName");
+ if ("".equals(buddyPoolName))
+ {
+ buddyPoolName = null;
+ }
+
+ brc.setBuddyPoolName(buddyPoolName);
+
+ // now read the buddy locator details
+
+ String buddyLocatorClass = XmlConfigHelper.readStringContents(element, "buddyLocatorClass");
+ if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
+ {
+ buddyLocatorClass = NextMemberBuddyLocator.class.getName();
+ }
+ Properties props = null;
+ props = XmlConfigHelper.readPropertiesContents(element, "buddyLocatorProperties");
+ BuddyLocatorConfig blc = new BuddyLocatorConfig();
+ blc.setBuddyLocatorClass(buddyLocatorClass);
+ blc.setBuddyLocatorProperties(props);
+ brc.setBuddyLocatorConfig(blc);
+
+ return brc;
+ }
+
+ public static CacheLoaderConfig parseCacheLoaderConfig(Element element)
+ {
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ clc.setPassivation(XmlConfigHelper.readBooleanContents(element, "passivation"));
+ clc.setPreload(XmlConfigHelper.readStringContents(element, "preload"));
+ clc.setShared(XmlConfigHelper.readBooleanContents(element, "shared"));
+
+ NodeList cacheLoaderNodes = element.getElementsByTagName("cacheloader");
+ for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
+ {
+ Node node = cacheLoaderNodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element indivElement = (Element) node;
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+ iclc.setAsync(XmlConfigHelper.readBooleanContents(indivElement, "async", false));
+ iclc.setIgnoreModifications(XmlConfigHelper.readBooleanContents(indivElement, "ignoreModifications", false));
+ iclc.setFetchPersistentState(XmlConfigHelper.readBooleanContents(indivElement, "fetchPersistentState", false));
+ iclc.setPurgeOnStartup(XmlConfigHelper.readBooleanContents(indivElement, "purgeOnStartup", false));
+ iclc.setClassName(XmlConfigHelper.readStringContents(indivElement, "class"));
+ iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
+
+ SingletonStoreConfig ssc = CacheLoadersElementParser.parseSingletonStoreConfig(indivElement);
+ if (ssc != null)
+ {
+ iclc.setSingletonStoreConfig(ssc);
+ }
+
+ clc.addIndividualCacheLoaderConfig(iclc);
+ }
+ }
+
+ return clc;
+ }
+
+ public static EvictionConfig parseEvictionConfig(Element element)
+ {
+ EvictionConfig ec = new EvictionConfig();
+
+ if (element != null)
+ {
+ // If they set the default eviction policy in the element, use that
+ // in preference to the external attribute
+ String temp = XmlConfigHelper.getTagContents(element,
+ EvictionConfig.EVICTION_POLICY_CLASS, ATTR, NAME);
+ if (temp != null && temp.length() > 0)
+ {
+ ec.setDefaultEvictionPolicyClass(temp);
+ }
+
+ temp = XmlConfigHelper.getTagContents(element,
+ EvictionConfig.WAKEUP_INTERVAL_SECONDS, ATTR, NAME);
+
+ int wakeupIntervalSeconds = 0;
+ if (temp != null)
+ {
+ wakeupIntervalSeconds = Integer.parseInt(temp);
+ }
+
+ if (wakeupIntervalSeconds <= 0)
+ {
+ wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
+ }
+
+ ec.setWakeupIntervalSeconds(wakeupIntervalSeconds);
+
+ int eventQueueSize = 0;
+ temp = XmlConfigHelper.getTagContents(element,
+ EvictionConfig.EVENT_QUEUE_SIZE, ATTR, NAME);
+
+ if (temp != null)
+ {
+ eventQueueSize = Integer.parseInt(temp);
+ }
+
+ if (eventQueueSize <= 0)
+ {
+ eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ }
+
+ ec.setDefaultEventQueueSize(eventQueueSize);
+
+ NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
+ if (list != null && list.getLength() > 0)
+ {
+ List regionConfigs = new ArrayList(list.getLength());
+ for (int i = 0; i < list.getLength(); i++)
+ {
+ org.w3c.dom.Node node = list.item(i);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+ try
+ {
+ regionConfigs.add(parseEvictionRegionConfig((Element) node, ec.getDefaultEvictionPolicyClass(), eventQueueSize));
+ }
+ catch (MissingPolicyException missingPolicy)
+ {
+ LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
+ throw missingPolicy;
+ }
+ }
+
+ ec.setEvictionRegionConfigs(regionConfigs);
+ }
+ }
+
+ return ec;
+
+ }
+
+ public static EvictionRegionConfig parseEvictionRegionConfig(Element element,
+ String defaultEvictionClass,
+ int defaultQueueCapacity)
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+
+ erc.setRegionName(element.getAttribute(EvictionRegionConfig.NAME));
+
+ String temp = element.getAttribute(EvictionRegionConfig.EVENT_QUEUE_SIZE);
+ if (temp != null && temp.length() > 0)
+ {
+ erc.setEventQueueSize(Integer.parseInt(temp));
+ }
+ else
+ {
+ erc.setEventQueueSize(defaultQueueCapacity);
+ }
+ String evictionClass = element.getAttribute(EvictionRegionConfig.REGION_POLICY_CLASS);
+
+ if (evictionClass == null || evictionClass.length() == 0)
+ {
+ evictionClass = defaultEvictionClass;
+ // if it's still null... what do we setCache?
+ if (evictionClass == null || evictionClass.length() == 0)
+ {
+ throw new MissingPolicyException(
+ "There is no Eviction Policy Class specified on the region or for the entire cache!");
+ }
+ }
+
+ EvictionPolicy policy;
+ try
+ {
+ policy = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
+ }
+
+ EvictionPolicyConfig epc;
+ try
+ {
+ epc = policy.getEvictionConfigurationClass().newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate eviction configuration of class " +
+ policy.getEvictionConfigurationClass(), e);
+ }
+
+ EvictionElementParser.parseEvictionPolicyConfig(element, epc);
+
+ erc.setEvictionPolicyConfig(epc);
+ return erc;
+
+ }
+
+ /**
+ * Parses the cluster config which is used to start a JGroups channel
+ *
+ * @param config an old-style JGroups protocol config String
+ */
+ public static String parseClusterConfigXml(Element config)
+ {
+ StringBuffer buffer = new StringBuffer();
+ NodeList stack = config.getChildNodes();
+ int length = stack.getLength();
+
+ for (int s = 0; s < length; s++)
+ {
+ org.w3c.dom.Node node = stack.item(s);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+
+ Element tag = (Element) node;
+ String protocol = tag.getTagName();
+ buffer.append(protocol);
+ NamedNodeMap attrs = tag.getAttributes();
+ int attrLength = attrs.getLength();
+ if (attrLength > 0)
+ {
+ buffer.append('(');
+ }
+ for (int a = 0; a < attrLength; a++)
+ {
+ Attr attr = (Attr) attrs.item(a);
+ String name = attr.getName();
+ String value = attr.getValue();
+ buffer.append(name);
+ buffer.append('=');
+ buffer.append(value);
+ if (a < attrLength - 1)
+ {
+ buffer.append(';');
+ }
+ }
+ if (attrLength > 0)
+ {
+ buffer.append(')');
+ }
+ buffer.append(':');
+ }
+ // Remove the trailing ':'
+ buffer.setLength(buffer.length() - 1);
+ return buffer.toString();
+ }
+
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,45 @@
+package org.jboss.cache.config.parsing;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Contains utility methods that might be useful to most of the parsers.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public abstract class XmlParserBase
+{
+ protected int getInt(String intStr)
+ {
+ return Integer.parseInt(intStr);
+ }
+
+ protected long getLong(String longStr)
+ {
+ return Long.valueOf(longStr);
+ }
+
+ protected boolean getBoolean(String str)
+ {
+ return Boolean.valueOf(str);
+ }
+
+
+ protected boolean existsAttribute(String attrValue)
+ {
+ return attrValue.length() > 0;
+ }
+
+
+ protected Element getSingleElement(String elementName, Element parent)
+ {
+ NodeList nodeList = parent.getElementsByTagName(elementName);
+ if (nodeList.getLength() == 0)
+ {
+ return null;
+ }
+ return (Element) nodeList.item(0);
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -25,9 +25,15 @@
@Dynamic
private int maxNodes = 0;
+ @Deprecated
@Dynamic
private int minTimeToLiveSeconds = 0;
+
+ /** value expressed in millis */
+ @Dynamic
+ private long minTimeToLive;
+
/**
* Can only be instantiated by a subclass.
* <p/>
@@ -60,14 +66,35 @@
this.maxNodes = maxNodes;
}
+ /** value expressed in millis */
+ public long getMinTimeToLive()
+ {
+ return minTimeToLive;
+ }
+
+ /** value expressed in millis */
+ public void setMinTimeToLive(long minTimeToLive)
+ {
+ this.minTimeToLive = minTimeToLive;
+ }
+
+ /**
+ * Use {@link #getMinTimeToLive()}
+ */
+ @Deprecated
public int getMinTimeToLiveSeconds()
{
return this.minTimeToLiveSeconds;
}
+ /**
+ * Use {@link #setMinTimeToLive(long)}
+ */
+ @Deprecated
public void setMinTimeToLiveSeconds(int minTimeToLiveSeconds)
{
this.minTimeToLiveSeconds = minTimeToLiveSeconds;
+ setMinTimeToLive(minTimeToLive * 1000);
}
public void validate() throws ConfigurationException
@@ -75,30 +102,28 @@
// no-op
}
- @Override
- public boolean equals(Object obj)
+ public boolean equals(Object o)
{
- if (this == obj)
- return true;
+ if (this == o) return true;
+ if (!(o instanceof EvictionPolicyConfigBase)) return false;
- if (obj instanceof EvictionPolicyConfigBase)
- {
- EvictionPolicyConfigBase other = (EvictionPolicyConfigBase) obj;
+ EvictionPolicyConfigBase that = (EvictionPolicyConfigBase) o;
- return this.maxNodes == other.maxNodes && this.minTimeToLiveSeconds == other.minTimeToLiveSeconds
- && Util.safeEquals(this.evictionPolicyClass, other.evictionPolicyClass);
- }
+ if (maxNodes != that.maxNodes) return false;
+ if (minTimeToLive != that.minTimeToLive) return false;
+ if (evictionPolicyClass != null ? !evictionPolicyClass.equals(that.evictionPolicyClass) : that.evictionPolicyClass != null)
+ return false;
- return false;
+ return true;
}
- @Override
public int hashCode()
{
- int result = 17;
+ int result;
+ result = (evictionPolicyClass != null ? evictionPolicyClass.hashCode() : 0);
result = 31 * result + maxNodes;
result = 31 * result + minTimeToLiveSeconds;
- result = 31 * result + (evictionPolicyClass == null ? 0 : evictionPolicyClass.hashCode());
+ result = 31 * result + (int) (minTimeToLive ^ (minTimeToLive >>> 32));
return result;
}
@@ -107,6 +132,7 @@
setEvictionPolicyClass(null);
setMaxNodes(0);
setMinTimeToLiveSeconds(0);
+ setMinTimeToLive(0);
setEvictionPolicyClassName();
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -31,7 +31,7 @@
private final Set<Region> processedRegions;
private static AtomicInteger tcount = new AtomicInteger();
- private int wakeupIntervalSeconds;
+ private long wakeupInterval;
private Timer evictionThread;
public EvictionTimerTask()
@@ -41,11 +41,11 @@
processedRegions = Collections.synchronizedSet(new HashSet<Region>());
}
- public void init(int wakeupIntervalSeconds)
+ public void init(long wakeupInterval)
{
if (log.isTraceEnabled())
- log.trace("Creating a new eviction listener with wakeupIntervalSeconds set at " + wakeupIntervalSeconds);
- this.wakeupIntervalSeconds = wakeupIntervalSeconds;
+ log.trace("Creating a new eviction listener with wakeupInterval millis set at " + wakeupInterval);
+ this.wakeupInterval = wakeupInterval;
start();
}
@@ -106,7 +106,7 @@
processRegions();
}
};
- evictionThread.schedule(tt, wakeupIntervalSeconds * 1000, wakeupIntervalSeconds * 1000);
+ evictionThread.schedule(tt, wakeupInterval, wakeupInterval);
}
private void processRegions()
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -24,9 +24,13 @@
@Dynamic
private boolean warnNoExpirationKey = true;
+ @Deprecated
@Dynamic
private int timeToLiveSeconds = 0;
+ @Dynamic
+ private long timeToLive = 0;
+
@Override
protected void setEvictionPolicyClassName()
{
@@ -66,14 +70,35 @@
this.warnNoExpirationKey = warnNoExpirationKey;
}
+ /** value expressed in millis */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /** value expressed in millis */
+ public void setTimeToLive(long timeToLive)
+ {
+ this.timeToLive = timeToLive;
+ }
+
+ /**
+ * Use {@link #getTimeToLive()}.
+ */
+ @Deprecated
public int getTimeToLiveSeconds()
{
return timeToLiveSeconds;
}
+ /**
+ * use {@link #setTimeToLive(long)}.
+ */
+ @Deprecated
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
this.timeToLiveSeconds = timeToLiveSeconds;
+ setTimeToLive(timeToLiveSeconds * 1000);
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -33,15 +33,26 @@
private static final long serialVersionUID = -3426716488271559729L;
@Dynamic
+ @Deprecated
private int timeToLiveSeconds;
@Dynamic
+ @Deprecated
private int maxAgeSeconds;
+
+ /** value expressed in millis*/
+ @Dynamic
+ private long timeToLive;
+
+ /** value expressed in millis*/
+ @Dynamic
+ private long maxAge;
+
public LRUConfiguration()
{
super();
// Force config of ttls
- setTimeToLiveSeconds(-1);
+ setTimeToLive(-1);
}
@Override
@@ -50,27 +61,72 @@
setEvictionPolicyClass(LRUPolicy.class.getName());
}
+ /** value expressed in millis*/
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+ /** value expressed in millis*/
+ public void setTimeToLive(long timeToLive)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeToLive;
+ }
+
+ /** value expressed in millis*/
+ public long getMaxAge()
+ {
+ return maxAge;
+ }
+
+ /** value expressed in millis*/
+ public void setMaxAge(long maxAge)
+ {
+ testImmutability("maxAge");
+ this.maxAge = maxAge;
+ }
+
+ /**
+ * use {@link #getTimeToLive()}
+ * @return
+ */
+ @Deprecated
public int getTimeToLiveSeconds()
{
return timeToLiveSeconds;
}
+ /**
+ * Use {@link #setTimeToLive(long)}
+ */
+ @Deprecated
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
testImmutability("timeToLiveSeconds");
this.timeToLiveSeconds = timeToLiveSeconds;
+ setTimeToLive(timeToLiveSeconds * 1000);
}
+ /**
+ * Use {@link #getMaxAge()}
+ */
+ @Deprecated
public int getMaxAgeSeconds()
{
return maxAgeSeconds;
}
+ /**
+ * Use {@link #getMaxAge()}
+ * @param maxAgeSeconds
+ */
+ @Deprecated
public void setMaxAgeSeconds(int maxAgeSeconds)
{
testImmutability("maxAgeSeconds");
this.maxAgeSeconds = maxAgeSeconds;
+ setMaxAge(maxAgeSeconds * 1000);
}
/**
@@ -80,40 +136,42 @@
@Override
public void validate() throws ConfigurationException
{
- if (timeToLiveSeconds < 0)
+ if (timeToLive < 0)
{
- throw new ConfigurationException("timeToLiveSeconds must be " +
+ throw new ConfigurationException("timeToLive must be " +
"configured to a value greater than or equal to 0");
}
}
- @Override
+
public String toString()
{
- StringBuffer str = new StringBuffer();
- str.append("LRUConfiguration: timeToLiveSeconds = ").append(getTimeToLiveSeconds()).append(" maxAgeSeconds =");
- str.append(getMaxAgeSeconds()).append(" maxNodes =").append(getMaxNodes());
- return str.toString();
+ return "LRUConfiguration{" +
+ "timeToLiveSeconds=" + timeToLiveSeconds +
+ ", timeToLive=" + timeToLive +
+ ", maxAge=" + maxAge +
+ '}';
}
- @Override
- public boolean equals(Object obj)
+ public boolean equals(Object o)
{
- if (obj instanceof LRUConfiguration && super.equals(obj))
- {
- LRUConfiguration other = (LRUConfiguration) obj;
- return maxAgeSeconds == other.maxAgeSeconds
- && timeToLiveSeconds == other.timeToLiveSeconds;
- }
- return false;
+ if (this == o) return true;
+ if (!(o instanceof LRUConfiguration)) return false;
+ if (!super.equals(o)) return false;
+
+ LRUConfiguration that = (LRUConfiguration) o;
+
+ if (maxAge != that.maxAge) return false;
+ if (timeToLive != that.timeToLive) return false;
+
+ return true;
}
- @Override
public int hashCode()
{
int result = super.hashCode();
- result = 31 * result + maxAgeSeconds;
- result = 31 * result + timeToLiveSeconds;
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
return result;
}
@@ -121,7 +179,7 @@
public void reset()
{
super.reset();
- setTimeToLiveSeconds(-1);
+ setTimeToLive(-1);
}
@Override
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cache.factories;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Parser able to parse a series of cache configurations stored in an
- * XML document with the following structure:
- * <pre>
- * <cache-configs>
- * <cache-config name="configA">
- * ....
- * </cache-config>
- * <cache-config name="configB">
- * ....
- * </cache-config>
- * </cache-configs>
- * </pre>
- * <p/>
- * The '....' represents the normal content of the mbean element in a
- * JBC -service.xml config file.
- *
- * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
- * @version $Revision: 1.1 $
- */
-public class CacheConfigsXmlParser
- {
- /** Name of the root element in a cache configs XML document*/
- public static final String DOCUMENT_ROOT = "cache-configs";
- /**
- * Name of the element that represents an individual cache configuration
- * in a cache configs XML document.
- */
- public static final String CONFIG_ROOT = "cache-config";
- /**
- * Name of the attribute in a {@link #CONFIG_ROOT cache-config} element that specifies
- * the name of the configuration.
- */
- public static final String CONFIG_NAME = "name";
-
- private static final Log log = LogFactory.getLog(CacheConfigsXmlParser.class);
-
- private final XmlConfigurationParser parser = new XmlConfigurationParser();
-
- public Map<String, Configuration> parseConfigs(String fileName) throws CloneNotSupportedException
- {
- InputStream is = getAsInputStreamFromClassLoader(fileName);
- if (is == null)
- {
- if (log.isDebugEnabled())
- log.debug("Unable to find configuration file " + fileName + " in classpath; searching for this file on the filesystem instead.");
- try
- {
- is = new FileInputStream(fileName);
- }
- catch (FileNotFoundException e)
- {
- throw new ConfigurationException("Unable to find config file " + fileName + " either in classpath or on the filesystem!", e);
- }
- }
-
- return parseConfigs(is);
- }
-
- public Map<String, Configuration> parseConfigs(InputStream stream) throws CloneNotSupportedException
- {
- // loop through all elements in XML.
- Element root = XmlHelper.getDocumentRoot(stream);
- NodeList list = root.getElementsByTagName(CONFIG_ROOT);
- if (list == null || list.getLength() == 0)
- throw new ConfigurationException("Can't find " + CONFIG_ROOT + " tag");
-
- Map<String, Configuration> result = new HashMap<String, Configuration>();
-
- for (int i = 0; i < list.getLength(); i++)
- {
- Node node = list.item(i);
- if (node.getNodeType() != Node.ELEMENT_NODE)
- {
- continue;
- }
-
- Element element = (Element) node;
- String name = element.getAttribute(CONFIG_NAME);
- if (name == null || name.trim().length() == 0)
- throw new ConfigurationException("Element " + element + " has no name attribute");
-
- Configuration c = parser.parseConfiguration(element);
- // Prove that we can successfully clone it
- c = c.clone();
- result.put(name.trim(), c);
- }
-
- return result;
- }
-
- protected InputStream getAsInputStreamFromClassLoader(String filename)
- {
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
- if (is == null)
- {
- // check system class loader
- is = getClass().getClassLoader().getResourceAsStream(filename);
- }
- return is;
- }
- }
\ No newline at end of file
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,712 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.factories;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.util.BeanUtils;
-import org.jboss.cache.util.Util;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.beans.PropertyEditor;
-import java.beans.PropertyEditorManager;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-/**
- * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object. When deployed as a
- * JBoss MBean, this role is performed by the JBoss Microcontainer. This class is only used internally in unit tests
- * or within {@link org.jboss.cache.CacheFactory} implementations for standalone JBoss Cache usage.
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- * @since 2.00.
- */
-public class XmlConfigurationParser
-{
- private static final Log log = LogFactory.getLog(XmlConfigurationParser.class);
-
- public static final String ATTR = "attribute";
- public static final String NAME = "name";
-
- /**
- * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
- * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
- * absolute path.
- *
- * @param filename the name of the XML file to parse.
- * @return a configured Configuration object representing the configuration in the file
- */
- public Configuration parseFile(String filename)
- {
- InputStream is = getAsInputStreamFromClassLoader(filename);
- if (is == null)
- {
- if (log.isDebugEnabled())
- log.debug("Unable to find configuration file " + filename + " in classpath; searching for this file on the filesystem instead.");
- try
- {
- is = new FileInputStream(filename);
- }
- catch (FileNotFoundException e)
- {
- throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!", e);
- }
- }
-
- return parseStream(is);
- }
-
- /**
- * Parses an input stream containing XML text and returns a new configuration.
- *
- * @param stream input stream to parse. SHould not be null.
- * @return a configured Configuration object representing the configuration in the stream
- * @since 2.1.0
- */
- public Configuration parseStream(InputStream stream)
- {
- // loop through all elements in XML.
- Element root = XmlHelper.getDocumentRoot(stream);
- Element mbeanElement = getMBeanElement(root);
-
- return parseConfiguration(mbeanElement);
- }
-
- public Configuration parseConfiguration(Element configurationRoot)
- {
- ParsedAttributes attributes = extractAttributes(configurationRoot);
-
- // Deal with legacy attributes we no longer support
- handleRemovedAttributes(attributes);
-
- // Deal with legacy attributes that we renamed or otherwise altered
- handleRenamedAttributes(attributes);
-
- Configuration c = new Configuration();
- setValues(c, attributes.stringAttribs, false);
- // Special handling for XML elements -- we hard code the parsing
- setXmlValues(c, attributes.xmlAttribs);
-
- return c;
- }
-
- /**
- * Check for and remove any attributes that were supported in the
- * 1.x releases and no longer are. Log a WARN or throw a
- * {@link ConfigurationException} if any are found. Which is done depends
- * on the attribute:
- * <p/>
- * <ul>
- * <li><i>MultiplexerService</i> -- throws an Exception</li>
- * <li><i>ServiceName</i> -- logs a WARN</li>
- * </ul>
- *
- * @param attributes
- */
- protected void handleRemovedAttributes(ParsedAttributes attributes)
- {
- String evictionPolicy = attributes.stringAttribs.remove("EvictionPolicyClass");
- if (evictionPolicy != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute EvictionPolicyClass. Set the default " +
- "eviction policy via the policyClass element in the EvictionConfig section");
- }
- String multiplexerService = attributes.stringAttribs.remove("MultiplexerService");
- if (multiplexerService != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute MultiplexerService. Inject the " +
- "multiplexer directly using Configuration.getRuntimeConfig().setMuxChannelFactory()");
- }
- String serviceName = attributes.stringAttribs.remove("ServiceName");
- if (serviceName != null)
- {
- log.warn("XmlConfigurationParser does not support the deprecated " +
- "attribute ServiceName. If JMX registration is needed, " +
- "register a CacheJmxWrapper or PojoCacheJmxWrapper in " +
- "JMX with the desired name");
- }
- }
-
- /**
- * Check for any attributes that were supported in the
- * 1.x releases but whose name has changed. Log a WARN if any are found, but
- * convert the attribute to the new name.
- * <p/>
- * <ul>
- * <li><i>UseMbean</i> becomes <i>ExposeManagementStatistics</i></li>
- * </ul>
- *
- * @param attributes
- */
- private void handleRenamedAttributes(ParsedAttributes attributes)
- {
- String keepStats = attributes.stringAttribs.remove("UseInterceptorMbeans");
- if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'UseInterceptorMbeans' and replaced " +
- "with 'ExposeManagementStatistics'. Please update your config " +
- "to use the new attribute name");
- attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
- }
- Element clc = attributes.xmlAttribs.remove("CacheLoaderConfiguration");
- if (clc != null && attributes.xmlAttribs.get("CacheLoaderConfig") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'CacheLoaderConfiguration' and replaced " +
- "with 'CacheLoaderConfig'. Please update your config " +
- "to use the new attribute name");
- attributes.xmlAttribs.put("CacheLoaderConfig", clc);
- }
- }
-
- protected InputStream getAsInputStreamFromClassLoader(String filename)
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- InputStream is = cl == null ? null : cl.getResourceAsStream(filename);
- if (is == null)
- {
- // check system class loader
- is = getClass().getClassLoader().getResourceAsStream(filename);
- }
- return is;
- }
-
- protected Element getMBeanElement(Element root)
- {
- // This is following JBoss convention.
- NodeList list = root.getElementsByTagName(XmlHelper.ROOT);
- if (list == null) throw new ConfigurationException("Can't find " + XmlHelper.ROOT + " tag");
-
- if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlHelper.ROOT + " tag");
-
- Node node = list.item(0);
- Element element;
- if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
- {
- element = (Element) node;
- }
- else
- {
- throw new ConfigurationException("Can't find " + XmlHelper.ROOT + " element");
- }
- return element;
- }
-
- protected static void setValues(Object target, Map<?, ?> attribs, boolean isXmlAttribs)
- {
- Class objectClass = target.getClass();
-
- // go thru simple string setters first.
- for (Entry entry : attribs.entrySet())
- {
- String propName = (String) entry.getKey();
- String setter = BeanUtils.setterName(propName);
- Method method;
-
- try
- {
- if (isXmlAttribs)
- {
- method = objectClass.getMethod(setter, Element.class);
- method.invoke(target, entry.getValue());
- }
- else
- {
- method = objectClass.getMethod(setter, String.class);
- method.invoke(target, entry.getValue());
- }
-
- continue;
- }
- catch (NoSuchMethodException me)
- {
- // this is ok, but certainly log this as a warning
- // this is hugely noisy!
- //if (log.isWarnEnabled()) log.warn("Unrecognised attribute " + propName + ". Please check your configuration. Ignoring!!");
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
- }
-
- // if we get here, we could not find a String or Element setter.
- for (Method m : objectClass.getMethods())
- {
- if (setter.equals(m.getName()))
- {
- Class paramTypes[] = m.getParameterTypes();
- if (paramTypes.length != 1)
- {
- throw new ConfigurationException("Setter " + setter + " does not contain the expected number of params. Has " + paramTypes.length + " instead of just 1.");
- }
-
- Class parameterType = paramTypes[0];
- PropertyEditor editor = PropertyEditorManager.findEditor(parameterType);
- if (editor == null)
- {
- throw new ConfigurationException("Couldn't find a property editor for parameter type " + parameterType);
- }
-
- editor.setAsText((String) attribs.get(propName));
-
- Object parameter = editor.getValue();
- //if (log.isDebugEnabled()) log.debug("Invoking setter method: " + setter + " with parameter \"" + parameter + "\" of type " + parameter.getClass());
-
- try
- {
- m.invoke(target, parameter);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
- }
- }
- }
- }
- }
-
- protected void setXmlValues(Configuration conf, Map<String, Element> attribs)
- {
- for (Entry<String, Element> entry : attribs.entrySet())
- {
- String propname = entry.getKey();
- if ("BuddyReplicationConfiguration".equals(propname)
- || "BuddyReplicationConfig".equals(propname))
- {
- BuddyReplicationConfig brc = parseBuddyReplicationConfig(entry.getValue());
- conf.setBuddyReplicationConfig(brc);
- }
- else if ("CacheLoaderConfiguration".equals(propname)
- || "CacheLoaderConfig".equals(propname))
- {
- CacheLoaderConfig clc = parseCacheLoaderConfig(entry.getValue());
- conf.setCacheLoaderConfig(clc);
- }
- else if ("EvictionPolicyConfiguration".equals(propname)
- || "EvictionPolicyConfig".equals(propname))
- {
- EvictionConfig ec = parseEvictionConfig(entry.getValue());
- conf.setEvictionConfig(ec);
- }
- else if ("ClusterConfig".equals(propname))
- {
- String jgc = parseClusterConfigXml(entry.getValue());
- conf.setClusterConfig(jgc);
- }
- else
- {
- throw new ConfigurationException("Unknown configuration element " + propname);
- }
- }
- }
-
- public static BuddyReplicationConfig parseBuddyReplicationConfig(Element element)
- {
- BuddyReplicationConfig brc = new BuddyReplicationConfig();
- brc.setEnabled(XmlHelper.readBooleanContents(element, "buddyReplicationEnabled"));
- brc.setDataGravitationRemoveOnFind(XmlHelper.readBooleanContents(element, "dataGravitationRemoveOnFind", true));
- brc.setDataGravitationSearchBackupTrees(XmlHelper.readBooleanContents(element, "dataGravitationSearchBackupTrees", true));
- brc.setAutoDataGravitation(brc.isEnabled() && XmlHelper.readBooleanContents(element, "autoDataGravitation", false));
-
- String strBuddyCommunicationTimeout = XmlHelper.readStringContents(element, "buddyCommunicationTimeout");
- try
- {
- brc.setBuddyCommunicationTimeout(Integer.parseInt(strBuddyCommunicationTimeout));
- }
- catch (Exception e)
- {
- }
- finally
- {
- if (log.isDebugEnabled())
- {
- log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
- }
- }
- String buddyPoolName = XmlHelper.readStringContents(element, "buddyPoolName");
- if ("".equals(buddyPoolName))
- {
- buddyPoolName = null;
- }
-
- brc.setBuddyPoolName(buddyPoolName);
-
- // now read the buddy locator details
-
- String buddyLocatorClass = XmlHelper.readStringContents(element, "buddyLocatorClass");
- if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
- {
- buddyLocatorClass = NextMemberBuddyLocator.class.getName();
- }
- Properties props = null;
- try
- {
- props = XmlHelper.readPropertiesContents(element, "buddyLocatorProperties");
- }
- catch (IOException e)
- {
- log.warn("Caught exception reading buddyLocatorProperties", e);
- log.error("Unable to read buddyLocatorProperties specified! Using defaults for [" + buddyLocatorClass + "]");
- }
- BuddyLocatorConfig blc = new BuddyLocatorConfig();
- blc.setBuddyLocatorClass(buddyLocatorClass);
- blc.setBuddyLocatorProperties(props);
- brc.setBuddyLocatorConfig(blc);
-
- return brc;
- }
-
- public static CacheLoaderConfig parseCacheLoaderConfig(Element element)
- {
- CacheLoaderConfig clc = new CacheLoaderConfig();
- clc.setPassivation(XmlHelper.readBooleanContents(element, "passivation"));
- clc.setPreload(XmlHelper.readStringContents(element, "preload"));
- clc.setShared(XmlHelper.readBooleanContents(element, "shared"));
-
- NodeList cacheLoaderNodes = element.getElementsByTagName("cacheloader");
- for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
- {
- Node node = cacheLoaderNodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element indivElement = (Element) node;
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
- iclc.setAsync(XmlHelper.readBooleanContents(indivElement, "async", false));
- iclc.setIgnoreModifications(XmlHelper.readBooleanContents(indivElement, "ignoreModifications", false));
- iclc.setFetchPersistentState(XmlHelper.readBooleanContents(indivElement, "fetchPersistentState", false));
- iclc.setPurgeOnStartup(XmlHelper.readBooleanContents(indivElement, "purgeOnStartup", false));
- iclc.setClassName(XmlHelper.readStringContents(indivElement, "class"));
- try
- {
- iclc.setProperties(XmlHelper.readPropertiesContents(indivElement, "properties"));
- }
- catch (IOException e)
- {
- throw new ConfigurationException("Problem loader cache loader properties", e);
- }
-
- SingletonStoreConfig ssc = parseSingletonStoreConfig(indivElement);
- if (ssc != null)
- {
- iclc.setSingletonStoreConfig(ssc);
- }
-
- clc.addIndividualCacheLoaderConfig(iclc);
- }
- }
-
- return clc;
- }
-
- private static SingletonStoreConfig parseSingletonStoreConfig(Element cacheLoaderelement)
- {
- /* singletonStore element can only appear once in a cacheloader, so we just take the first one ignoring any
- subsequent definitions in cacheloader element*/
- Node singletonStoreNode = cacheLoaderelement.getElementsByTagName("singletonStore").item(0);
- if (singletonStoreNode != null && singletonStoreNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element singletonStoreElement = (Element) singletonStoreNode;
- boolean singletonStoreEnabled = XmlHelper.readBooleanContents(singletonStoreElement, "enabled");
- String singletonStoreClass = XmlHelper.readStringContents(singletonStoreElement, "class");
- Properties singletonStoreproperties;
- try
- {
- singletonStoreproperties = XmlHelper.readPropertiesContents(singletonStoreElement, "properties");
- }
- catch (IOException e)
- {
- throw new ConfigurationException("Problem loading singleton store properties", e);
- }
- SingletonStoreConfig ssc = new SingletonStoreConfig();
- ssc.setSingletonStoreEnabled(singletonStoreEnabled);
- ssc.setSingletonStoreClass(singletonStoreClass);
- ssc.setSingletonStoreproperties(singletonStoreproperties);
-
- return ssc;
- }
-
- return null;
- }
-
- public static EvictionConfig parseEvictionConfig(Element element)
- {
- EvictionConfig ec = new EvictionConfig();
-
- if (element != null)
- {
- // If they set the default eviction policy in the element, use that
- // in preference to the external attribute
- String temp = XmlHelper.getTagContents(element,
- EvictionConfig.EVICTION_POLICY_CLASS, ATTR, NAME);
- if (temp != null && temp.length() > 0)
- {
- ec.setDefaultEvictionPolicyClass(temp);
- }
-
- temp = XmlHelper.getTagContents(element,
- EvictionConfig.WAKEUP_INTERVAL_SECONDS, ATTR, NAME);
-
- int wakeupIntervalSeconds = 0;
- if (temp != null)
- {
- wakeupIntervalSeconds = Integer.parseInt(temp);
- }
-
- if (wakeupIntervalSeconds <= 0)
- {
- wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
- }
-
- ec.setWakeupIntervalSeconds(wakeupIntervalSeconds);
-
- int eventQueueSize = 0;
- temp = XmlHelper.getTagContents(element,
- EvictionConfig.EVENT_QUEUE_SIZE, ATTR, NAME);
-
- if (temp != null)
- {
- eventQueueSize = Integer.parseInt(temp);
- }
-
- if (eventQueueSize <= 0)
- {
- eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
- }
-
- ec.setDefaultEventQueueSize(eventQueueSize);
-
- NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
- if (list != null && list.getLength() > 0)
- {
- List regionConfigs = new ArrayList(list.getLength());
- for (int i = 0; i < list.getLength(); i++)
- {
- org.w3c.dom.Node node = list.item(i);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
- try
- {
- regionConfigs.add(parseEvictionRegionConfig((Element) node, ec.getDefaultEvictionPolicyClass(), eventQueueSize));
- }
- catch (MissingPolicyException missingPolicy)
- {
- LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
- throw missingPolicy;
- }
- }
-
- ec.setEvictionRegionConfigs(regionConfigs);
- }
- }
-
- return ec;
-
- }
-
- public static EvictionRegionConfig parseEvictionRegionConfig(Element element,
- String defaultEvictionClass,
- int defaultQueueCapacity)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
-
- erc.setRegionName(element.getAttribute(EvictionRegionConfig.NAME));
-
- String temp = element.getAttribute(EvictionRegionConfig.EVENT_QUEUE_SIZE);
- if (temp != null && temp.length() > 0)
- {
- erc.setEventQueueSize(Integer.parseInt(temp));
- }
- else
- {
- erc.setEventQueueSize(defaultQueueCapacity);
- }
-
- String evictionClass = element.getAttribute(EvictionRegionConfig.REGION_POLICY_CLASS);
- if (evictionClass == null || evictionClass.length() == 0)
- {
- evictionClass = defaultEvictionClass;
- // if it's still null... what do we setCache?
- if (evictionClass == null || evictionClass.length() == 0)
- {
- throw new MissingPolicyException(
- "There is no Eviction Policy Class specified on the region or for the entire cache!");
- }
- }
-
- EvictionPolicy policy;
- try
- {
- policy = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
- }
-
- EvictionPolicyConfig epc;
- try
- {
- epc = policy.getEvictionConfigurationClass().newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate eviction configuration of class " +
- policy.getEvictionConfigurationClass(), e);
- }
-
- parseEvictionPolicyConfig(element, epc);
-
- erc.setEvictionPolicyConfig(epc);
-
- return erc;
- }
-
- public static void parseEvictionPolicyConfig(Element element, EvictionPolicyConfig target)
- {
- target.reset();
- ParsedAttributes attributes = extractAttributes(element);
- setValues(target, attributes.stringAttribs, false);
- setValues(target, attributes.xmlAttribs, true);
- target.validate();
- }
-
- /**
- * Parses the cluster config which is used to start a JGroups channel
- *
- * @param config an old-style JGroups protocol config String
- */
- public static String parseClusterConfigXml(Element config)
- {
- StringBuffer buffer = new StringBuffer();
- NodeList stack = config.getChildNodes();
- int length = stack.getLength();
-
- for (int s = 0; s < length; s++)
- {
- org.w3c.dom.Node node = stack.item(s);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
-
- Element tag = (Element) node;
- String protocol = tag.getTagName();
- buffer.append(protocol);
- NamedNodeMap attrs = tag.getAttributes();
- int attrLength = attrs.getLength();
- if (attrLength > 0)
- {
- buffer.append('(');
- }
- for (int a = 0; a < attrLength; a++)
- {
- Attr attr = (Attr) attrs.item(a);
- String name = attr.getName();
- String value = attr.getValue();
- buffer.append(name);
- buffer.append('=');
- buffer.append(value);
- if (a < attrLength - 1)
- {
- buffer.append(';');
- }
- }
- if (attrLength > 0)
- {
- buffer.append(')');
- }
- buffer.append(':');
- }
- // Remove the trailing ':'
- buffer.setLength(buffer.length() - 1);
- return buffer.toString();
- }
-
- protected static ParsedAttributes extractAttributes(Element source)
- {
- Map<String, String> stringAttribs = new HashMap<String, String>();
- Map<String, Element> xmlAttribs = new HashMap<String, Element>();
- NodeList list = source.getElementsByTagName(XmlHelper.ATTR);
- if (log.isDebugEnabled()) log.debug("Attribute size: " + list.getLength());
-
- // loop through attributes
- for (int loop = 0; loop < list.getLength(); loop++)
- {
- Node node = list.item(loop);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) continue;
-
- // for each element (attribute) ...
- Element element = (Element) node;
- String name = element.getAttribute(XmlHelper.NAME);
- String valueStr = XmlHelper.getElementContent(element, true);
-
- Element valueXml = null;
- if (valueStr.length() == 0)
- {
- // This may be an XML element ...
- valueXml = XmlHelper.getConfigSubElement(element);
- }
-
- // add these to the maps.
-
- if (valueStr.length() > 0) stringAttribs.put(name, valueStr);
- if (valueXml != null) xmlAttribs.put(name, valueXml);
- }
-
- return new ParsedAttributes(stringAttribs, xmlAttribs);
- }
-
- static class ParsedAttributes
- {
- final Map<String, String> stringAttribs;
- final Map<String, Element> xmlAttribs;
-
- ParsedAttributes(Map strings, Map elements)
- {
- this.stringAttribs = strings;
- this.xmlAttribs = elements;
- }
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -35,7 +35,7 @@
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.RuntimeConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.CachePrinter;
import org.jgroups.Address;
@@ -374,7 +374,7 @@
BuddyReplicationConfig brc = null;
if (config != null)
{
- brc = XmlConfigurationParser.parseBuddyReplicationConfig(config);
+ brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(config);
}
getConfiguration().setBuddyReplicationConfig(brc);
this.buddyReplConfig = config;
@@ -385,7 +385,7 @@
CacheLoaderConfig clc = null;
if (cache_loader_config != null)
{
- clc = XmlConfigurationParser.parseCacheLoaderConfig(cache_loader_config);
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(cache_loader_config);
}
getConfiguration().setCacheLoaderConfig(clc);
this.cacheLoaderConfig = cache_loader_config;
@@ -408,7 +408,7 @@
String props = null;
if (config != null)
{
- props = XmlConfigurationParser.parseClusterConfigXml(config);
+ props = XmlConfigurationParserOld.parseClusterConfigXml(config);
}
getConfiguration().setClusterConfig(props);
this.clusterConfig = config;
@@ -435,7 +435,7 @@
EvictionConfig ec = null;
if (config != null)
{
- ec = XmlConfigurationParser.parseEvictionConfig(config);
+ ec = XmlConfigurationParserOld.parseEvictionConfig(config);
}
getConfiguration().setEvictionConfig(ec);
this.evictionConfig = config;
Deleted: core/trunk/src/main/java/org/jboss/cache/xml/XmlHelper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/xml/XmlHelper.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/main/java/org/jboss/cache/xml/XmlHelper.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,420 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.xml;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.util.StringPropertyReplacer;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * A simple XML utility class for reading configuration elements
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- */
-public class XmlHelper
-{
- private static final Log log = LogFactory.getLog(XmlHelper.class);
-
- /**
- * The root of a JBoss Cache configuration XML file. This is the <tt><mbean></tt> tag.
- */
- public static final String ROOT = "mbean";
-
- /**
- * The <tt><attribute></tt> tag which forms the bulk of JBoss Cache configuration elements
- */
- public static final String ATTR = "attribute";
-
- /**
- * The <tt><config></tt> tag may be embedded in the contents of an <tt><attribute></tt>, to specify more
- * complex configuration for certain parameters.
- */
- public static final String CONFIG_ATTR = "config";
-
- /**
- * The <tt><name></tt> attribute to an <tt><attribute></tt> tag.
- */
- public static final String NAME = "name";
-
-
- /**
- * Returns the contents of a specific node of given element name, provided a certain attribute exists and is set to value.
- * E.g., if you have a {@link Element} which represents the following XML snippet:
- * <pre>
- * <ItemQuantity Colour="Red">100</ItemQuantity>
- * <ItemQuantity Colour="Blue">30</ItemQuantity>
- * <ItemQuantity Colour="Black">10</ItemQuantity>
- * <pre>
- * <p/>
- * The following results could be expected:
- * </p>
- * <pre>
- * getTagContents(element, "Red", "ItemQuantity", "Colour"); // 100
- * getTagContents(element, "Black", "ItemQuantity", "Colour"); // 10
- * getTagContents(element, "Blah", "ItemQuantity", "Colour"); // null
- * getTagContents(element, "Red", "Blah", "Colour"); // null
- * getTagContents(element, "Black", "ItemQuantity", "Blah"); // null
- * </pre>
- * <p/>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- * </p>
- *
- * @param elem - element to search through.
- * @param value - expected value to match against
- * @param elementName - element name
- * @param attributeName - attribute name of the element that would contain the expected value.
- * @return the contents of the matched element, or null if not found/matched
- */
- public static String getTagContents(Element elem, String value, String elementName, String attributeName)
- {
- NodeList list = elem.getElementsByTagName(elementName);
-
- for (int s = 0; s < list.getLength(); s++)
- {
- org.w3c.dom.Node node = list.item(s);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- continue;
-
- Element element = (Element) node;
- String name = element.getAttribute(attributeName);
- if (name.equals(value))
- {
- return getElementContent(element, true);
- }
- }
- return null;
- }
-
- /**
- * Retrieves the value of a given attribute for the first encountered instance of a tag in an element.
- * <p/>
- * E.g., if you have a {@link Element} which represents the following XML snippet:
- * </p>
- * <pre>
- * <ItemQuantity Colour="Red">100</ItemQuantity>
- * <ItemQuantity Colour="Blue">30</ItemQuantity>
- * <ItemQuantity Colour="Black">10</ItemQuantity>
- * <pre>
- * <p/>
- * The following results could be expected:
- * </p>
- * <pre>
- * getAttributeValue(element, "ItemQuantity", "Colour"); // "Red"
- * getTagContents(element, "Blah", "Colour"); // null
- * getTagContents(element, "ItemQuantity", "Blah"); // null
- * </pre>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- *
- * @param elem - element to search through.
- * @param elementName - element name
- * @param attributeName - attribute name of the element that would contain the expected value.
- * @return the contents of the matched attribute, or null if not found/matched
- */
- public static String getAttributeValue(Element elem, String elementName, String attributeName)
- {
- NodeList list = elem.getElementsByTagName(elementName);
-
- for (int s = 0; s < list.getLength(); s++)
- {
- org.w3c.dom.Node node = list.item(s);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- continue;
-
- Element element = (Element) node;
- String value = element.getAttribute(attributeName);
- return value == null ? null : StringPropertyReplacer.replaceProperties(value);
-
- }
- return null;
- }
-
- /**
- * Convenience method, equivalent to calling <tt>getSubElement(element, "config");</tt>
- */
- public static Element getConfigSubElement(Element element)
- {
- return getSubElement(element, CONFIG_ATTR);
- }
-
- /**
- * Returns a named sub-element of the current element passed in.
- * <p/>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- *
- * @param element - element to search through.
- * @param subElementName - the name of a sub element to look for
- * @return the first matching sub element, if found, or null otherwise.
- */
- public static Element getSubElement(Element element, String subElementName)
- {
- NodeList nl = element.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++)
- {
- Node node = nl.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE && subElementName.equals(((Element) node).getTagName()))
- {
- return (Element) node;
- }
- }
-
- if (log.isDebugEnabled()) log.debug("getSubElement(): Does not exist for " + subElementName);
- return null;
- }
-
- /**
- * Reads the contents of the element passed in.
- * <p/>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- *
- * @param element - element to search through.
- * @param trim - if true, whitespace is trimmed before returning
- * @return the contents of the element passed in. Will return an empty String if the element is empty.
- */
- public static String getElementContent(Element element, boolean trim)
- {
- NodeList nl = element.getChildNodes();
- String attributeText = "";
- for (int i = 0; i < nl.getLength(); i++)
- {
- Node n = nl.item(i);
- if (n instanceof Text)
- {
- attributeText += StringPropertyReplacer.replaceProperties(((Text) n).getData());
- }
- } // end of for ()
- if (trim)
- attributeText = attributeText.trim();
- return attributeText;
- }
-
- /**
- * Reads the contents of the first occurence of elementName under the given element, trimming results of whitespace.
- * <p/>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- *
- * @param element - element to search through.
- * @param elementName - name of the element to find within the element passed in
- * @return may return an empty String of not found.
- */
- public static String readStringContents(Element element, String elementName)
- {
- NodeList nodes = element.getElementsByTagName(elementName);
- if (nodes.getLength() > 0)
- {
- Node node = nodes.item(0);
- Element ne = (Element) node;
- NodeList nl2 = ne.getChildNodes();
- Node node2 = nl2.item(0);
- if (node2 != null)
- {
- String value = node2.getNodeValue();
- if (value == null)
- return "";
- return StringPropertyReplacer.replaceProperties(value.trim());
- }
- else
- {
- return "";
- }
- }
- else
- {
- return "";
- }
- }
-
- /**
- * Escapes backslashes ('\') with additional backslashes in a given String, returning a new, escaped String.
- *
- * @param value String to escape. Cannot be null.
- * @return escaped String. Never is null.
- */
- public static String escapeBackslashes(String value)
- {
- StringBuffer buf = new StringBuffer(value);
- for (int looper = 0; looper < buf.length(); looper++)
- {
- char curr = buf.charAt(looper);
- char next = 0;
- if (looper + 1 < buf.length())
- next = buf.charAt(looper + 1);
-
- if (curr == '\\')
- {
- if (next != '\\')
- { // only if not already escaped
- buf.insert(looper, '\\'); // escape backslash
- }
- looper++; // skip past extra backslash (either the one we added or existing)
- }
- }
- return buf.toString();
- }
-
- /**
- * Reads the contents of a named sub element within a given element, and attempts to parse the contents as a Java
- * properties file.
- * <p/>
- * E.g., if you have a {@link Element} which represents the following XML snippet:
- * <p/>
- * <pre>
- * <props>
- * my.attrib.1 = blah
- * my.attrib.2 = blahblah
- * </props>
- * <pre>
- * <p/>
- * The following results could be expected:
- * <p/>
- * <pre>
- * Properties p = readPropertiesContents(element, "props");
- * p.getProperty("my.attrib.1"); // blah
- * p.getProperty("my.attrib.2"); // blahblah
- * </pre>
- * None of the parameters should be null - otherwise the method may throw a NullPointerException.
- *
- * @param element - element to search through.
- * @param elementName - name of the element to find within the element passed in
- * @return a {@link Properties} object, never null.
- * @throws IOException if unable to parse the contents of the element
- */
- public static Properties readPropertiesContents(Element element, String elementName) throws IOException
- {
- String stringContents = readStringContents(element, elementName);
- if (stringContents == null) return new Properties();
- // JBCACHE-531: escape all backslash characters
- stringContents = escapeBackslashes(stringContents);
- ByteArrayInputStream is = new ByteArrayInputStream(stringContents.trim().getBytes("ISO8859_1"));
- Properties properties = new Properties();
- properties.load(is);
- is.close();
- return properties;
- }
-
- /**
- * Similar to {@link #readStringContents(org.w3c.dom.Element,String)} except that it returns a boolean.
- *
- * @param element - element to search through.
- * @param elementName - name of the element to find within the element passed in
- * @return the contents of the element as a boolean, or false if not found.
- */
- public static boolean readBooleanContents(Element element, String elementName)
- {
- return readBooleanContents(element, elementName, false);
- }
-
- /**
- * Similar to {@link #readStringContents(org.w3c.dom.Element,String)} except that it returns a boolean.
- *
- * @param element - element to search through.
- * @param elementName - name of the element to find within the element passed in
- * @param defaultValue - value to return if the element is not found or cannot be parsed.
- * @return the contents of the element as a boolean
- */
- public static boolean readBooleanContents(Element element, String elementName, boolean defaultValue)
- {
- String val = readStringContents(element, elementName);
- if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("false"))
- {
- // needs to be done this way because of JBBUILD-351
- return Boolean.valueOf(val);
- //return Boolean.parseBoolean(val);
- }
- return defaultValue;
- }
-
- /**
- * Converts a String representing an XML snippet into an {@link org.w3c.dom.Element}.
- *
- * @param xml snippet as a string
- * @return a DOM Element
- * @throws Exception if unable to parse the String or if it doesn't contain valid XML.
- */
- public static Element stringToElement(String xml) throws Exception
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document d = builder.parse(bais);
- bais.close();
- return d.getDocumentElement();
- }
-
- /**
- * Returns the root element of a given input stream
- *
- * @param is stream to parse
- * @return XML DOM element, or null if unable to parse stream
- */
- public static Element getDocumentRoot(InputStream is)
- {
- Document doc;
- try
- {
- InputSource xmlInp = new InputSource(is);
-
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
- doc = parser.parse(xmlInp);
- Element root = doc.getDocumentElement();
- root.normalize();
- return root;
- }
- catch (SAXParseException err)
- {
- log.error("Configurator SAXParse error", err);
- }
- catch (SAXException e)
- {
- log.error("Configurator SAX error", e);
- }
- catch (Exception pce)
- {
- log.error("Configurator general error", pce);
- }
- return null;
- }
-
- /**
- * Retrieves the boolean value of a given attribute for the first encountered instance of elementName
- *
- * @param elem - element to search
- * @param elementName - name of element to find
- * @param attributeName - name of attribute to retrieve the value of
- * @param defaultValue - default value to return if not found
- */
- public static boolean readBooleanAttribute(Element elem, String elementName, String attributeName, boolean defaultValue)
- {
- String val = getAttributeValue(elem, elementName, attributeName);
- if (val != null)
- {
- if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("false"))
- {
- //return Boolean.parseBoolean(val);
- // needs to be done this way because of JBBUILD-351
- return Boolean.valueOf(val);
- }
- }
-
- return defaultValue;
- }
-
-}
Modified: core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,7 +7,7 @@
package org.jboss.cache;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
@@ -31,7 +31,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp()
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
expected = parser.parseFile(configFile);
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -9,10 +9,10 @@
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -544,7 +544,7 @@
"<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -12,9 +12,9 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.CommandsFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -43,8 +43,8 @@
String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
" <buddyLocatorProperties>numBuddies = 3</buddyLocatorProperties>\n" +
" <buddyPoolName>groupOne</buddyPoolName></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -66,8 +66,8 @@
" <buddyLocatorClass>org.i.dont.exist.PhantomBuddyLocator</buddyLocatorClass>\n" +
" <buddyLocatorProperties>numBuddies = 3</buddyLocatorProperties>\n" +
" <buddyPoolName>groupOne</buddyPoolName></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -89,8 +89,8 @@
{
String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
BuddyManager mgr = new BuddyManager(config);
assertTrue(!mgr.isEnabled());
@@ -105,8 +105,8 @@
{
String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -122,8 +122,8 @@
BuddyManager bm = null;
try
{
- Element element = XmlHelper.stringToElement("<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>");
- BuddyReplicationConfig cfg = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement("<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>");
+ BuddyReplicationConfig cfg = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
bm = new BuddyManager(cfg);
bm.injectDependencies(null, null, null, null, null, null, null, null, new BuddyFqnTransformer());
CommandsFactory commandsFactory = new CommandsFactory();
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,10 +11,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.interceptors.DataGravitatorInterceptor;
import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -47,8 +47,8 @@
public void testDisabledConfig() throws Exception
{
String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
assertNull(cache.getBuddyManager());
@@ -57,8 +57,8 @@
public void testBasicConfig() throws Exception
{
String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache.getConfiguration().setBuddyReplicationConfig(config);
@@ -76,7 +76,7 @@
public void testXmlConfig() throws Exception
{
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(new XmlConfigurationParser().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(new XmlConfigurationParserOld().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
cache.create();
cache.start();
BuddyManager bm = cache.getBuddyManager();
@@ -105,8 +105,8 @@
public void testLocalModeConfig() throws Exception
{
String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
- Element element = XmlHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
cache.create();
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -13,14 +13,14 @@
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jgroups.Address;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -139,8 +139,8 @@
if (buddyPoolName != null) xmlString += "<buddyPoolName>" + buddyPoolName + "</buddyPoolName>";
xmlString += "</config>";
- Element element = XmlHelper.stringToElement(xmlString);
- BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlString);
+ BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
c.getConfiguration().setBuddyReplicationConfig(config);
c.getConfiguration().setFetchInMemoryState(true);
@@ -236,8 +236,8 @@
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(cloader);
- CacheLoaderConfig cfg = XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(cloader);
+ CacheLoaderConfig cfg = XmlConfigurationParserOld.parseCacheLoaderConfig(element);
cache.getConfiguration().setCacheLoaderConfig(cfg);
if (start)
{
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -22,8 +22,8 @@
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.testng.annotations.Test;
/**
@@ -42,7 +42,7 @@
public void testClone() throws Exception
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE);
try {
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -12,7 +12,7 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.TransactionSetup;
import org.testng.annotations.Test;
@@ -47,7 +47,7 @@
public void testMultiplexerStack() throws Exception
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
Configuration conf = parser.parseFile("META-INF/conf-test/mux-service.xml");
// test that multiplexer settings have been read in properly.
Modified: core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -17,7 +17,7 @@
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -93,7 +93,7 @@
System.setProperty(MAX_NODES_PROP, "1000");
System.setProperty(BUDDY_POOL_PROP, "replaced");
- Configuration cfg = new XmlConfigurationParser().parseFile(STRING_REPLACED_FILE);
+ Configuration cfg = new XmlConfigurationParserOld().parseFile(STRING_REPLACED_FILE);
assertEquals(NodeLockingScheme.OPTIMISTIC, cfg.getNodeLockingScheme());
assertEquals(CacheMode.REPL_SYNC, cfg.getCacheMode());
Added: core/trunk/src/test/java/org/jboss/cache/config/XmlConfigurationParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/XmlConfigurationParserTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/XmlConfigurationParserTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,226 @@
+package org.jboss.cache.config;
+
+import org.jboss.cache.config.parsing.XmlConfigurationParser;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.MRUConfiguration;
+import org.jboss.cache.lock.IsolationLevel;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Test(groups = "unit")
+public class XmlConfigurationParserTest
+{
+ Configuration config;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ XmlConfigurationParser parser = new XmlConfigurationParser();
+ config = parser.parseFile("META-INF/conf-test/parser-test-file-3.x.xml");
+ }
+
+ public void testTransactionManagerLookupClass()
+ {
+ assert config.getTransactionManagerLookupClass().equals("org.jboss.cache.transaction.GenericTransactionManagerLookup");
+ }
+
+ public void testIsolationLevel()
+ {
+ assert config.getIsolationLevel().equals(IsolationLevel.REPEATABLE_READ);
+ }
+
+ public void testCacheMode()
+ {
+ assert config.getCacheMode().equals(Configuration.CacheMode.REPL_SYNC);
+ }
+
+ public void testUseReplQueue()
+ {
+ assert !config.isUseReplQueue();
+ }
+
+ public void testClusterName()
+ {
+ assert config.getClusterName().equals("JBossCache-Cluster");
+ }
+
+ public void testGetClusterConfig()
+ {
+ assert config.getClusterConfig().indexOf("MERGE2") >= 0;
+ }
+
+ public void testFetchInMemoryState()
+ {
+ assert config.isFetchInMemoryState();
+ }
+
+ public void testStateRetrievalTimeout()
+ {
+ assert config.getStateRetrievalTimeout() == 15124;
+ }
+
+ public void testSyncReplTimeout()
+ {
+ assert config.getSyncReplTimeout() == 15421;
+ }
+
+ public void testLockAcquisitionTimeout()
+ {
+ assert config.getLockAcquisitionTimeout() == 10234;
+ }
+
+ public void testUseLazyDeserialization()
+ {
+ assert config.isUseLazyDeserialization();
+ }
+
+ public void testObjectInputStreamPoolSize()
+ {
+ assert 12 == config.getObjectInputStreamPoolSize();
+ }
+
+ public void testObjectOutputStreamPoolSize()
+ {
+ assert 14 == config.getObjectOutputStreamPoolSize();
+ }
+
+ public void testShutdownHookBehavior()
+ {
+ assert Configuration.ShutdownHookBehavior.REGISTER == config.getShutdownHookBehavior();
+ }
+
+ public void testSyncRollbackPhase()
+ {
+ assert config.isSyncRollbackPhase();
+ }
+
+ public void testSyncCommitPhase()
+ {
+ assert config.isSyncCommitPhase();
+ }
+
+ public void testUseReplicationVersion()
+ {
+ assert config.getReplicationVersion() == 124;
+ }
+
+ public void testGetMultiplexerStack()
+ {
+ assert "file_name".equals(config.getMultiplexerStack());
+ }
+
+ public void testMarshallerClass()
+ {
+ assert "some.Clazz".equals(config.getMarshallerClass());
+ }
+
+ public void testLockParentForChildInsertRemove()
+ {
+ assert config.isLockParentForChildInsertRemove();
+ }
+
+ public void testInactiveOnStartup()
+ {
+ assert config.isInactiveOnStartup();
+ }
+
+ public void testExposeManagementStatistics()
+ {
+ assert !config.getExposeManagementStatistics();
+ }
+
+ public void testCacheLoaderConfiguration()
+ {
+ CacheLoaderConfig clc = config.getCacheLoaderConfig();
+ assert null != clc;
+ assert clc.isPassivation();
+ assert clc.isShared();
+ assert "/a/b/c,/f/r/s".equals(clc.getPreload());
+ CacheLoaderConfig.IndividualCacheLoaderConfig first = clc.getFirstCacheLoaderConfig();
+ assert "org.jboss.cache.loader.JDBCCacheLoader".equals(first.getClassName());
+ assert first.isAsync();
+ assert first.isFetchPersistentState();
+ assert first.isIgnoreModifications();
+ assert first.isPurgeOnStartup();
+ assert first.getProperties().get("cache.jdbc.table.name").equals("jbosscache");
+ assert first.getProperties().get("cache.jdbc.table.create").equals("true");
+ assert first.getProperties().get("cache.jdbc.table.drop").equals("true");
+ }
+
+ public void testBuddyReplicationConfig()
+ {
+ BuddyReplicationConfig brConfig = config.getBuddyReplicationConfig();
+ assert brConfig.isEnabled();
+ BuddyReplicationConfig.BuddyLocatorConfig locatorConfig = brConfig.getBuddyLocatorConfig();
+ assert "org.jboss.cache.buddyreplication.NextMemberBuddyLocator".equals(locatorConfig.getBuddyLocatorClass());
+ assert locatorConfig.getBuddyLocatorProperties().get("numBuddies").equals("1");
+ assert locatorConfig.getBuddyLocatorProperties().get("ignoreColocatedBuddies").equals("true");
+ assert brConfig.getBuddyPoolName().equals("myBuddyPoolReplicationGroup");
+ assert brConfig.getBuddyCommunicationTimeout() == 2000;
+ assert brConfig.isAutoDataGravitation();
+ assert brConfig.isDataGravitationRemoveOnFind();
+ assert brConfig.isDataGravitationSearchBackupTrees();
+ }
+
+ public void testUseRegionBasedMarshalling()
+ {
+ assert config.isUseRegionBasedMarshalling();
+ }
+
+ public void testEvictionPolicyConfig()
+ {
+ EvictionConfig evictionConfig = config.getEvictionConfig();
+ assert "org.jboss.cache.eviction.LRUPolicy".equals(evictionConfig.getDefaultEvictionPolicyClass());
+ assert 200000 == evictionConfig.getDefaultEventQueueSize();
+ assert 5 == evictionConfig.getWakeupIntervalSeconds();
+
+ List<EvictionRegionConfig> regionConfigs = evictionConfig.getEvictionRegionConfigs();
+ assert regionConfigs.size() == 3;
+
+ EvictionRegionConfig first = regionConfigs.get(0);
+ assert first.getRegionName().equals("/_default_");
+ assert first.getEvictionPolicyConfig() instanceof LRUConfiguration;
+ LRUConfiguration firstConfiguration = (LRUConfiguration) first.getEvictionPolicyConfig();
+ assert firstConfiguration.getMaxAge() <= 0;
+ assert firstConfiguration.getTimeToLive() == 1000;
+ assert firstConfiguration.getMaxNodes() == 5000;
+
+ EvictionRegionConfig second = regionConfigs.get(1);
+ LRUConfiguration secondConfiguration = (LRUConfiguration) second.getEvictionPolicyConfig();
+ assert secondConfiguration.getMaxAge() == 0;
+ assert secondConfiguration.getTimeToLive() == 1002;
+ assert secondConfiguration.getMaxNodes() == 0;
+
+ EvictionRegionConfig third = regionConfigs.get(2);
+ MRUConfiguration thirdConfiguration = (MRUConfiguration) third.getEvictionPolicyConfig();
+ assert thirdConfiguration.getMaxNodes() == 2103;
+ assert thirdConfiguration.getMinTimeToLive() == 22;
+ assert third.getEventQueueSize() == 21;
+ }
+
+ public void testCustomInterceptors()
+ {
+ List<CustomInterceptorConfig> interceptorConfigs = config.getCustomInterceptors();
+ if (interceptorConfigs.isEmpty()) return; //todo drop this once you drop the old configuration
+ assert interceptorConfigs.size() == 5;
+ assert interceptorConfigs.get(0).getInterceptorClass().equals("com.myCompany.MyInterceptor1");
+ assert interceptorConfigs.get(1).getInterceptorClass().equals("com.myCompany.MyInterceptor2");
+ assert interceptorConfigs.get(2).getInterceptorClass().equals("com.myCompany.MyInterceptor3");
+ assert interceptorConfigs.get(3).getInterceptorClass().equals("com.myCompany.MyInterceptor4");
+ assert interceptorConfigs.get(4).getInterceptorClass().equals("com.myCompany.MyInterceptor5");
+ assert interceptorConfigs.get(0).isFirst();
+ assert !interceptorConfigs.get(0).isLast();
+ assert interceptorConfigs.get(0).getProperties().get("x").equals("y");
+ assert interceptorConfigs.get(0).getProperties().get("i").equals("10");
+ assert interceptorConfigs.get(1).isLast();
+ assert interceptorConfigs.get(2).getIndex() == 3;
+ assert interceptorConfigs.get(3).getBeforeClass().equals("org.jboss.cache.interceptors.CallInterceptor");
+ assert interceptorConfigs.get(4).getAfterClass().equals("org.jboss.cache.interceptors.CallInterceptor");
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,8 +11,8 @@
import static org.testng.AssertJUnit.fail;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
/**
@@ -30,8 +30,8 @@
"<attribute name=\"maxElementsPerNode\">100</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(1000, config.getMaxNodes());
@@ -45,10 +45,10 @@
"<attribute name=\"maxNodes\">1000</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (ConfigurationException ce)
{
@@ -67,9 +67,9 @@
"<attribute name=\"maxElementsPerNode\">100</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(0, config.getMaxNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,8 +11,8 @@
import static org.testng.AssertJUnit.fail;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -33,9 +33,9 @@
"<attribute name=\"maxNodes\">1000</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(1000, config.getMaxNodes());
@@ -47,11 +47,11 @@
String xml = "<region name=\"abc\">" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (ConfigurationException ce)
{
@@ -68,11 +68,11 @@
"<attribute name=\"maxNodes\">1000</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (ConfigurationException ce)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -8,8 +8,8 @@
import static org.testng.AssertJUnit.assertEquals;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -32,9 +32,9 @@
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(10, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
@@ -47,9 +47,9 @@
"<region name=\"abc\">" +
"<attribute name=\"minNodes\">10</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(10, config.getMinNodes());
assertEquals(0, config.getMaxNodes());
@@ -62,9 +62,9 @@
"<region name=\"abc\">" +
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(0, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -10,8 +10,8 @@
import static org.testng.AssertJUnit.assertTrue;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -34,9 +34,9 @@
"<attribute name=\"timeToLiveSeconds\">1000</attribute>\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(5000, config.getMaxNodes());
assertEquals(1000, config.getTimeToLiveSeconds());
@@ -50,9 +50,9 @@
"<attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
"<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(10000, config.getMaxNodes());
assertEquals(8, config.getTimeToLiveSeconds());
@@ -66,11 +66,11 @@
"<attribute name=\"maxNodes\">10000</attribute>\n" +
"<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
boolean caught = false;
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (ConfigurationException ce)
{
@@ -83,9 +83,9 @@
"<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
"</region>";
- element = XmlHelper.stringToElement(xml);
+ element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(0, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -10,8 +10,8 @@
import static org.testng.AssertJUnit.assertTrue;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -39,9 +39,9 @@
"<region name=\"/org/jboss/data\">\n" +
"<attribute name=\"maxNodes\">5000</attribute>\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(5000, config.getMaxNodes());
}
@@ -51,9 +51,9 @@
String xml = "<region name=\"/Test/\">\n" +
"<attribute name=\"maxNodes\">10000</attribute>\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(10000, config.getMaxNodes());
}
@@ -62,11 +62,11 @@
{
String xml = "<region name=\"/Test/\">\n" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
boolean caught = false;
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (ConfigurationException ce)
{
@@ -78,9 +78,9 @@
"<attribute name=\"maxNodes\">10000</attribute>\n" +
"</region>";
- element = XmlHelper.stringToElement(xml);
+ element = XmlConfigHelper.stringToElement(xml);
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
assertEquals(10000, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -8,8 +8,8 @@
import static org.testng.AssertJUnit.fail;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -73,11 +73,11 @@
*/
private void testConfigBlock(String xml) throws Exception
{
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
NullEvictionPolicyConfig config = new NullEvictionPolicyConfig();
try
{
- XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
}
catch (Exception e)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -5,12 +5,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.interceptors.EvictionInterceptor;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
@@ -77,8 +77,8 @@
" </region>\n" +
" </config>\n" +
" </attribute>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseEvictionConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseEvictionConfig(element);
}
@AfterMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -31,11 +31,11 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -93,10 +93,10 @@
"<attribute name=\"maxNodes\">10000</attribute>" +
"<attribute name=\"timeToLiveSeconds\">4</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
RegionManager regionManager = cache_.getRegionManager();
EvictionConfig topConfig = cache_.getConfiguration().getEvictionConfig();
- EvictionRegionConfig erc = XmlConfigurationParser.parseEvictionRegionConfig(element, topConfig.getDefaultEvictionPolicyClass(), topConfig.getDefaultEventQueueSize());
+ EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, topConfig.getDefaultEvictionPolicyClass(), topConfig.getDefaultEventQueueSize());
regionManager.setEvictionConfig(topConfig);
// Fqn is the region name
regionManager.getRegion("/programmatic", true).setEvictionPolicy(erc.getEvictionPolicyConfig());
@@ -131,10 +131,10 @@
"<attribute name=\"maxNodes\">10000</attribute>" +
"<attribute name=\"timeToLiveSeconds\">4</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
RegionManager regionManager = cache_.getRegionManager();
EvictionConfig topEC = cache_.getConfiguration().getEvictionConfig();
- EvictionRegionConfig erc = XmlConfigurationParser.parseEvictionRegionConfig(element,
+ EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element,
topEC.getDefaultEvictionPolicyClass(),
topEC.getDefaultEventQueueSize());
// Fqn is the region name
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -6,8 +6,8 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -110,10 +110,10 @@
"<attribute name=\"minNodes\">10</attribute>" +
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
- Element element = XmlHelper.stringToElement(xml);
+ Element element = XmlConfigHelper.stringToElement(xml);
RegionManager regionManager = new RegionManager();
regionManager.setUsingEvictions(true);
- EvictionRegionConfig erc = XmlConfigurationParser.parseEvictionRegionConfig(element, null, EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+ EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, null, EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
Region region = regionManager.getRegion(erc.getRegionFqn(), true);
region.setEvictionPolicy(erc.getEvictionPolicyConfig());
@@ -129,8 +129,8 @@
"<attribute name=\"minNodes\">10</attribute>" +
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
- element = XmlHelper.stringToElement(xml);
- erc = XmlConfigurationParser.parseEvictionRegionConfig(element, "org.jboss.cache.eviction.LFUPolicy", EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+ element = XmlConfigHelper.stringToElement(xml);
+ erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, "org.jboss.cache.eviction.LFUPolicy", EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
regionManager = new RegionManager();
regionManager.setUsingEvictions(true);
region = regionManager.getRegion(erc.getRegionFqn(), true);
Modified: core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -6,10 +6,11 @@
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.interceptors.*;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import org.testng.annotations.AfterMethod;
@@ -104,8 +105,8 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
public void testSharedCacheLoaderConfig() throws Exception
@@ -392,8 +393,8 @@
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
- Element element = XmlHelper.stringToElement(xmlString);
- BuddyReplicationConfig brc = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlString);
+ BuddyReplicationConfig brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
cache.getConfiguration().setBuddyReplicationConfig(brc);
cache.getConfiguration().setCacheMode("REPL_SYNC");
@@ -431,8 +432,8 @@
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
- Element element = XmlHelper.stringToElement(xmlString);
- BuddyReplicationConfig brc = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xmlString);
+ BuddyReplicationConfig brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
cache.getConfiguration().setBuddyReplicationConfig(brc);
cache.getConfiguration().setCacheMode("REPL_SYNC");
Modified: core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,9 +11,11 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.ParsedAttributes;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.transaction.TransactionSetup;
-import org.jboss.cache.xml.XmlHelper;
import org.jgroups.conf.XmlConfigurator;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -100,8 +102,8 @@
"<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
/**
@@ -174,7 +176,7 @@
return erc;
}
- private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
+ private static class UnitTestXmlConfigurationParser extends XmlConfigurationParserOld
{
public Configuration parseFile(String filename, CacheMode mode)
@@ -187,10 +189,10 @@
// loop through all elements in XML.
if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
- Element root = XmlHelper.getDocumentRoot(stream);
+ Element root = XmlConfigHelper.getDocumentRoot(stream);
Element mbeanElement = getMBeanElement(root);
- ParsedAttributes attributes = extractAttributes(mbeanElement);
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(mbeanElement);
// Deal with rename of the old property that controlled MBean registration
String keepStats = attributes.stringAttribs.remove("UseMbean");
@@ -200,7 +202,7 @@
}
Configuration c = new Configuration();
- setValues(c, attributes.stringAttribs, false);
+ XmlConfigHelper.setValues(c, attributes.stringAttribs, false);
// Special handling for XML elements -- we hard code the parsing
setXmlValues(c, attributes.xmlAttribs);
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -17,9 +17,9 @@
import org.jboss.cache.util.internals.ReplicationListener;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -919,8 +919,8 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
protected void assertHasBeenInvalidated(Node n, String message)
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -24,6 +24,7 @@
import org.jboss.cache.Version;
import org.jboss.cache.config.*;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration.CacheMode;
@@ -35,12 +36,10 @@
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.multiplexer.MultiplexerTestHelper;
import org.jboss.cache.transaction.BatchModeTransactionManagerLookup;
-import org.jboss.cache.xml.XmlHelper;
import org.jgroups.ChannelFactory;
import org.jgroups.JChannelFactory;
import org.jgroups.jmx.JChannelFactoryMBean;
import static org.testng.AssertJUnit.*;
-import org.testng.annotations.Test;
import org.w3c.dom.Element;
import javax.management.MBeanServerInvocationHandler;
@@ -263,7 +262,7 @@
" <dataGravitationRemoveOnFind>false</dataGravitationRemoveOnFind>\n" +
" <dataGravitationSearchBackupTrees>false</dataGravitationSearchBackupTrees>" +
"</config>";
- return XmlHelper.stringToElement(xmlString);
+ return XmlConfigHelper.stringToElement(xmlString);
}
protected static Element getCacheLoaderConfig() throws Exception
@@ -299,7 +298,7 @@
"</singletonStore>" +
"</cacheloader>\n" +
"</config>";
- return XmlHelper.stringToElement(xml);
+ return XmlConfigHelper.stringToElement(xml);
}
protected static Element getEvictionPolicyConfig() throws Exception
@@ -324,7 +323,7 @@
" <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
"</region>\n" +
" </config>\n";
- return XmlHelper.stringToElement(xml);
+ return XmlConfigHelper.stringToElement(xml);
}
protected static Element getClusterConfig() throws Exception
@@ -381,7 +380,7 @@
" <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
" <pbcast.FLUSH timeout=\"0\"/>\n" +
"</config>";
- return XmlHelper.stringToElement(xml);
+ return XmlConfigHelper.stringToElement(xml);
}
protected String getDefaultProperties()
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -6,11 +6,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
-import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -333,8 +333,8 @@
"<ignoreModifications>false</ignoreModifications>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
private static void validateHealthyListener(MyListener listener)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -9,8 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -49,7 +49,7 @@
"<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -5,10 +5,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.statetransfer.StateTransferManager;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -216,8 +216,8 @@
"<purgeOnStartup>false</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
protected Properties getProperties() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -8,8 +8,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -56,7 +56,7 @@
private static Element strToElement(String s) throws Exception
{
- return XmlHelper.stringToElement(s);
+ return XmlConfigHelper.stringToElement(s);
}
public void testSingleCacheLoader() throws Exception
@@ -158,7 +158,7 @@
" location=" + getTempDir() +
" </properties>" +
"</cacheloader></config>";
- CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
CacheLoader cl = mgr.getCacheLoader();
@@ -194,7 +194,7 @@
" location=" + getTempDir() +
" </properties>" +
"</cacheloader></config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr.setConfig(clc, null, null);
cl = mgr.getCacheLoader();
@@ -256,7 +256,7 @@
" </properties>" +
"</cacheloader></config>";
- CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
CacheLoader cl = mgr.getCacheLoader();
@@ -289,7 +289,7 @@
"cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
" </properties>" +
"</cacheloader></config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr.setConfig(clc, null, null);
cl = mgr.getCacheLoader();
@@ -388,7 +388,7 @@
"cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
" </properties>" +
"</cacheloader></config>";
- CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -436,7 +436,7 @@
"cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
" </properties>" +
"</cacheloader></config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -461,7 +461,7 @@
" </properties>" +
"</cacheloader>" +
"</config>";
- CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -486,7 +486,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -512,7 +512,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -545,7 +545,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -576,7 +576,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -603,7 +603,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -636,7 +636,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -670,7 +670,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -702,7 +702,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
try
{
@@ -732,7 +732,7 @@
" </singletonStore>" +
"</cacheloader>" +
"</config>";
- clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
+ clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
try
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,8 +11,8 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -117,8 +117,8 @@
"</config>";
Configuration c = cache.getConfiguration();
- Element element = XmlHelper.stringToElement(xml);
- c.setCacheLoaderConfig(XmlConfigurationParser.parseCacheLoaderConfig(element));
+ Element element = XmlConfigHelper.stringToElement(xml);
+ c.setCacheLoaderConfig(XmlConfigurationParserOld.parseCacheLoaderConfig(element));
cache.start();
cache.put(fqn, key, value);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,9 +7,9 @@
package org.jboss.cache.loader;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -65,7 +65,7 @@
"<fetchPersistentState>false</fetchPersistentState>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,9 +11,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.Test;
@@ -86,8 +86,8 @@
"<ignoreModifications>" + ignoreMods2 + "</ignoreModifications>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
public void testCruds() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -13,10 +13,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.util.internals.ViewChangeListener;
import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -292,8 +292,8 @@
" </singletonStore>" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
private void initSingletonNonPushCache(CacheSPI cache) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,11 +7,11 @@
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.jmx.CacheJmxWrapper;
import org.jboss.cache.loader.tcp.TcpCacheServer;
-import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -74,8 +74,8 @@
"<purgeOnStartup>false</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
@AfterMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -6,10 +6,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -119,7 +119,7 @@
"<ignoreModifications>false</ignoreModifications>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -13,7 +13,7 @@
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.interceptors.CacheMgmtInterceptor;
import org.jboss.cache.interceptors.CallInterceptor;
import org.jboss.cache.interceptors.NotificationInterceptor;
@@ -28,7 +28,7 @@
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionSetup;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jgroups.Address;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -113,8 +113,8 @@
" <ignoreModifications>false</ignoreModifications>\n" +
" </cacheloader>\n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
protected CacheSPI<Object, Object> createCacheWithLoader(boolean passivationEnabled) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -8,10 +8,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.Test;
@@ -40,8 +40,8 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
private CacheSPI createLocalCache() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,7 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheListener;
@@ -59,7 +59,7 @@
private void initCaches()
{
CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
- cache = (CacheSPI) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Object listener = new TestCacheListener();
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -11,7 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.fail;
@@ -47,7 +47,7 @@
private void initCaches()
{
CacheFactory<Integer, String> instance = new DefaultCacheFactory();
- cache = (CacheSPI) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -13,7 +13,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheListener;
@@ -44,7 +44,7 @@
public void setUp() throws Exception
{
CacheFactory<String, String> instance = new DefaultCacheFactory();
- cache = (CacheSPI<String, String>) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI<String, String>) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache.getConfiguration().setUseRegionBasedMarshalling(true);
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -10,14 +10,14 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -66,8 +66,8 @@
"<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
"</cacheloader>\n" +
"</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
@BeforeMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,8 +1,8 @@
package org.jboss.cache.passivation;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -75,7 +75,7 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -1,8 +1,8 @@
package org.jboss.cache.passivation;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.w3c.dom.Element;
/**
@@ -49,8 +49,8 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -7,8 +7,8 @@
package org.jboss.cache.passivation;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.w3c.dom.Element;
import java.util.Properties;
@@ -42,8 +42,8 @@
" </cacheloader>\n" +
" \n" +
" </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -30,11 +30,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.notifications.annotation.CacheListener;
@@ -116,8 +116,8 @@
" </cacheloader>\n" +
" </config>\n" +
" </attribute>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
}
@@ -138,8 +138,8 @@
" </region>\n" +
" </config>\n" +
" </attribute>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseEvictionConfig(element);
+ Element element = XmlConfigHelper.stringToElement(xml);
+ return XmlConfigurationParserOld.parseEvictionConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java 2008-06-17 11:56:20 UTC (rev 5994)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java 2008-06-17 15:36:31 UTC (rev 5995)
@@ -14,7 +14,6 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import static org.testng.AssertJUnit.assertEquals;
Added: core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml (rev 0)
+++ core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbosscache>
+
+ <locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="true" lockAcquisitionTimeout="10234"/>
+
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"
+ syncRollbackPhase="true" syncCommitPhase="true"/>
+
+ <!-- serialization related configuration, used for replication and cache loading -->
+ <serialization objectInputStreamPoolSize="10" objectOutputStreamPoolSize="20" version="5.1.0"
+ marshallerClass="some.Clazz" useLazyDeserialization="true" useRegionBasedMarshalling="false"/>
+
+ <!-- either replication or invalidation tags will be present, not both -->
+ <replication>
+ <!-- either sync or async will be present, not both -->
+ <async useReplQueue="false" replQueueInterval="12" replQueueMaxElements="12345"/>
+ <sync replTimeout="15421"/>
+ </replication>
+
+ <!-- either replication or invalidation tags will be present, not both -->
+ <invalidation>
+ <!-- either sync or async will be present, not both -->
+ <async useReplQueue="false" replQueueInterval="12" replQueueMaxElements="12345"/>
+ <sync replTimeout="15421"/>
+ </invalidation>
+
+ <startup fetchInMemoryState="true" stateRetrievalTimeout="1524" inactiveOnStartup="true"/>
+ <shutdown hookBehavior="REGISTER"/>
+
+ <transport clusterName="JBossCache-Cluster">
+ <clusterName>JBossCache-Cluster</clusterName>
+ <multiplexer stack="file_name"/>
+ <clusterConfig>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="30000" min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="5000" shun="false"
+ view_bundling="true" view_ack_collection_timeout="5000"/>
+ <FRAG2 frag_size="60000"/>
+ <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+ <pbcast.FLUSH timeout="0"/>
+ </clusterConfig>
+ </transport>
+
+
+ <jmxStatistics enabled="false"/>
+
+ <eviction wakeUpInterval="5" defaultPolicyClass="org.jboss.cache.eviction.LRUPolicy" defaultEventQueueSize="200000">
+ <default>
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="timeToLive">1000</attribute>
+ </default>
+ <region name="/org/jboss/data">
+ <attribute name="timeToLive">1002</attribute>
+ </region>
+ <region name="/org/jboss/xyz" policyClass="org.jboss.cache.eviction.MRUPolicy" eventQueueSize="21">
+ <attribute name="maxNodes">2103</attribute>
+ <attribute name="minTimeToLive">22</attribute>
+ </region>
+ </eviction>
+
+ <!-- this should be deprecated in 3.0 and should be replaced with CacheLoaderConfig-->
+ <cacheLoaders passivation="false" shared="false">
+ <preload>
+ <node fqn="/a/b/c"/>
+ <node fqn="/f/r/s"/>
+ </preload>
+
+ <!-- we can now have multiple cache loaders, which get chained -->
+ <cacheLoader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
+ ignoreModifications="true" purgeOnStartup="true">
+ <properties>
+ cache.jdbc.table.name=jbosscache
+ cache.jdbc.table.create=true
+ cache.jdbc.table.drop=true
+ </properties>
+ </cacheLoader>
+ </cacheLoaders>
+
+ <buddyReplication enabled="true" buddyPoolName="myBuddyPoolReplicationGroup" buddyCommunicationTimeout="2000">
+ <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
+ <buddyLocator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
+ <properties>
+ numBuddies = 1
+ ignoreColocatedBuddies = true
+ </properties>
+ </buddyLocator>
+ </buddyReplication>
+
+ <!-- this is new behavior added within 3.x only. it support configuring custom interceptors through configurations -->
+ <customInterceptors>
+ <interceptor class="com.myCompany.MyInterceptor1">
+ <properties>
+ x=y
+ i=10
+ </properties>
+ <position first="true"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor2">
+ <position last="true"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor3">
+ <position index="3"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor4">
+ <position before="org.jboss.cache.interceptors.CallInterceptor"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor5">
+ <position after="org.jboss.cache.interceptors.CallInterceptor"/>
+ </interceptor>
+ </customInterceptors>
+</jbosscache>
Added: core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml (rev 0)
+++ core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+ <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+ name="jboss.cache:service=TreeCache">
+
+ <depends>jboss:service=Naming</depends>
+ <depends>jboss:service=TransactionManager</depends>
+ <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
+ </attribute>
+ <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
+ <attribute name="CacheMode">REPL_SYNC</attribute>
+ <attribute name="UseReplQueue">false</attribute>
+ <attribute name="ReplQueueInterval">12</attribute>
+
+ <attribute name="ReplQueueMaxElements">12345</attribute>
+
+ <attribute name="ClusterName">JBossCache-Cluster</attribute>
+
+ <attribute name="UseRegionBasedMarshalling">true</attribute>
+
+ <attribute name="ClusterConfig">
+ <config>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="30000" min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="5000" shun="false"
+ view_bundling="true" view_ack_collection_timeout="5000"/>
+ <FRAG2 frag_size="60000"/>
+ <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+ <!-- <pbcast.STATE_TRANSFER/> -->
+ <pbcast.FLUSH timeout="0"/>
+ </config>
+ </attribute>
+
+
+ <attribute name="FetchInMemoryState">true</attribute>
+
+ <attribute name="StateRetrievalTimeout">15124</attribute>
+
+ <attribute name="SyncReplTimeout">15421</attribute>
+
+ <attribute name="LockAcquisitionTimeout">10234</attribute>
+
+ <attribute name="UseLazyDeserialization">true</attribute>
+
+ <attribute name="ObjectInputStreamPoolSize">12</attribute>
+
+ <attribute name="ObjectOutputStreamPoolSize">14</attribute>
+
+ <attribute name="ShutdownHookBehavior">REGISTER</attribute>
+
+ <attribute name="SyncRollbackPhase">true</attribute>
+
+ <attribute name="SyncCommitPhase">true</attribute>
+
+ <attribute name="ReplicationVersion">510</attribute>
+
+ <attribute name="MultiplexerStack">file_name</attribute>
+
+ <attribute name="MarshallerClass">some.Clazz</attribute>
+
+ <attribute name="LockParentForChildInsertRemove">true</attribute>
+
+ <attribute name="InactiveOnStartup">true</attribute>
+
+ <attribute name="ExposeManagementStatistics">false</attribute>
+
+
+ <attribute name="EvictionPolicyConfig">
+ <config>
+ <attribute name="wakeUpIntervalSeconds">5</attribute>
+ <!-- This defaults to 200000 if not specified -->
+ <attribute name="eventQueueSize">200000</attribute>
+ <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+ <!-- Cache wide default -->
+ <region name="/_default_">
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="timeToLiveSeconds">1000</attribute>
+ </region>
+ <region name="/org/jboss/data">
+ <attribute name="timeToLiveSeconds">1002</attribute>
+ </region>
+ <region name="/org/jboss/xyz" policyClass="org.jboss.cache.eviction.MRUPolicy" eventQueueSize="21">
+ <attribute name="maxNodes">2103</attribute>
+ <attribute name="minTimeToLiveSeconds">22</attribute>
+ </region>
+ </config>
+ </attribute>
+
+ <!-- this should be deprecated in 3.0 and should be replaced with CacheLoaderConfig-->
+ <attribute name="CacheLoaderConfiguration">
+ <config>
+ <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
+ <passivation>true</passivation>
+ <preload>/a/b/c,/f/r/s</preload>
+ <shared>true</shared>
+
+ <!-- we can now have multiple cache loaders, which get chained -->
+ <cacheloader>
+ <class>org.jboss.cache.loader.JDBCCacheLoader</class>
+ <!-- same as the old CacheLoaderConfig attribute -->
+ <properties>
+ cache.jdbc.table.name=jbosscache
+ cache.jdbc.table.create=true
+ cache.jdbc.table.drop=true
+ </properties>
+ <async>true</async>
+ <fetchPersistentState>true</fetchPersistentState>
+ <ignoreModifications>true</ignoreModifications>
+ <purgeOnStartup>true</purgeOnStartup>
+ </cacheloader>
+ </config>
+ </attribute>
+
+ <attribute name="BuddyReplicationConfig">
+ <config>
+ <buddyReplicationEnabled>true</buddyReplicationEnabled>
+ <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>
+ <buddyLocatorProperties>
+ numBuddies = 1
+ ignoreColocatedBuddies = true
+ </buddyLocatorProperties>
+ <buddyPoolName>myBuddyPoolReplicationGroup</buddyPoolName>
+ <buddyCommunicationTimeout>2000</buddyCommunicationTimeout>
+ <autoDataGravitation>true</autoDataGravitation>
+ <dataGravitationRemoveOnFind>true</dataGravitationRemoveOnFind>
+ <dataGravitationSearchBackupTrees>true</dataGravitationSearchBackupTrees>
+ </config>
+ </attribute>
+ </mbean>
+</server>
Added: core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml (rev 0)
+++ core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml 2008-06-17 15:36:31 UTC (rev 5995)
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbosscache>
+
+ <locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="true" lockAcquisitionTimeout="10234"/>
+
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"
+ syncRollbackPhase="true" syncCommitPhase="true"/>
+
+ <!-- serialization related configuration, used for replication and cache loading -->
+ <serialization objectInputStreamPoolSize="12" objectOutputStreamPoolSize="14" version="1.2.4"
+ marshallerClass="some.Clazz" useLazyDeserialization="true" useRegionBasedMarshalling="true"/>
+
+ <replication>
+ <sync replTimeout="15421"/>
+ </replication>
+
+ <startup fetchInMemoryState="true" stateRetrievalTimeout="15124" inactiveOnStartup="true"/>
+ <shutdown hookBehavior="REGISTER"/>
+
+ <transport clusterName="JBossCache-Cluster">
+ <clusterName>JBossCache-Cluster</clusterName>
+ <multiplexer stack="file_name"/>
+ <jgroupsConfig>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="30000" min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="5000" shun="false"
+ view_bundling="true" view_ack_collection_timeout="5000"/>
+ <FRAG2 frag_size="60000"/>
+ <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+ <!-- <pbcast.STATE_TRANSFER/> -->
+ <pbcast.FLUSH timeout="0"/>
+ </jgroupsConfig>
+ </transport>
+
+
+ <jmxStatistics enabled="false"/>
+
+ <eviction wakeUpInterval="5" defaultPolicyClass="org.jboss.cache.eviction.LRUPolicy" defaultEventQueueSize="200000">
+ <default>
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="timeToLive">1000</attribute>
+ </default>
+ <region name="/org/jboss/data">
+ <attribute name="timeToLive">1002</attribute>
+ </region>
+ <region name="/org/jboss/xyz" policyClass="org.jboss.cache.eviction.MRUPolicy" eventQueueSize="21">
+ <attribute name="maxNodes">2103</attribute>
+ <attribute name="minTimeToLive">22</attribute>
+ </region>
+ </eviction>
+
+ <!-- this should be deprecated in 3.0 and should be replaced with CacheLoaderConfig-->
+ <cacheLoaders passivation="true" shared="true">
+ <preload>
+ <node fqn="/a/b/c"/>
+ <node fqn="/f/r/s"/>
+ </preload>
+
+ <!-- we can now have multiple cache loaders, which get chained -->
+ <cacheLoader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
+ ignoreModifications="true" purgeOnStartup="true">
+ <properties>
+ cache.jdbc.table.name=jbosscache
+ cache.jdbc.table.create=true
+ cache.jdbc.table.drop=true
+ </properties>
+ </cacheLoader>
+ </cacheLoaders>
+
+ <buddyReplication enabled="true" buddyPoolName="myBuddyPoolReplicationGroup" buddyCommunicationTimeout="2000">
+ <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
+ <buddyLocator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
+ <properties>
+ numBuddies = 1
+ ignoreColocatedBuddies = true
+ </properties>
+ </buddyLocator>
+ </buddyReplication>
+
+ <!-- this is new behavior added within 3.x only. it support configuring custom interceptors through configurations -->
+ <customInterceptors>
+ <interceptor class="com.myCompany.MyInterceptor1">
+ <properties>
+ x=y
+ i=10
+ </properties>
+ <position first="true"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor2">
+ <position last="true"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor3">
+ <position index="3"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor4">
+ <position before="org.jboss.cache.interceptors.CallInterceptor"/>
+ </interceptor>
+ <interceptor class="com.myCompany.MyInterceptor5">
+ <position after="org.jboss.cache.interceptors.CallInterceptor"/>
+ </interceptor>
+ </customInterceptors>
+</jbosscache>
16 years, 6 months
JBoss Cache SVN: r5994 - pojo/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-17 07:56:20 -0400 (Tue, 17 Jun 2008)
New Revision: 5994
Modified:
pojo/trunk/pom.xml
Log:
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-06-17 09:49:40 UTC (rev 5993)
+++ pojo/trunk/pom.xml 2008-06-17 11:56:20 UTC (rev 5994)
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<jbosscache-pojo-version>2.2.0-SNAPSHOT</jbosscache-pojo-version>
- <jbosscache-core-version>2.2.0.CR3</jbosscache-core-version>
+ <jbosscache-core-version>2.2.0.CR4</jbosscache-core-version>
<jboss.aop.version>2.0.0-SNAPSHOT</jboss.aop.version>
</properties>
<parent>
16 years, 6 months
JBoss Cache SVN: r5993 - core/branches/2.1.X/src/main/java/org/jboss/cache/loader.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-17 05:49:40 -0400 (Tue, 17 Jun 2008)
New Revision: 5993
Modified:
core/branches/2.1.X/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
Log:
Should not attempt to preload if to cache loader cfgs have been provided
Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-06-17 00:40:14 UTC (rev 5992)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-06-17 09:49:40 UTC (rev 5993)
@@ -282,6 +282,8 @@
*/
public void preloadCache() throws CacheException
{
+ // ensure that config != null!
+ if (config == null) return; // nothing to do!
if (config.getPreload() == null || config.getPreload().equals("")) return;
if (log.isDebugEnabled()) log.debug("preloading transient state from cache loader " + loader);
StringTokenizer st = new StringTokenizer(config.getPreload(), ",");
16 years, 6 months
JBoss Cache SVN: r5992 - core/branches/1.4.X/src/org/jboss/cache/aop.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-16 20:40:14 -0400 (Mon, 16 Jun 2008)
New Revision: 5992
Modified:
core/branches/1.4.X/src/org/jboss/cache/aop/TreeCacheAopDelegate.java
Log:
Fix JBCACHE-1370
Modified: core/branches/1.4.X/src/org/jboss/cache/aop/TreeCacheAopDelegate.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/aop/TreeCacheAopDelegate.java 2008-06-17 00:16:30 UTC (rev 5991)
+++ core/branches/1.4.X/src/org/jboss/cache/aop/TreeCacheAopDelegate.java 2008-06-17 00:40:14 UTC (rev 5992)
@@ -137,7 +137,7 @@
CacheInterceptor interceptor = new CacheInterceptor(cache_, fqn, type);
interceptor.setAopInstance(aopInstance);
advisor.appendInterceptor(interceptor);
- cache_.addUndoInterceptor(advisor, interceptor, ModificationEntry.INTERCEPTOR_ADD);
+ //cache_.addUndoInterceptor(advisor, interceptor, ModificationEntry.INTERCEPTOR_ADD);
} else { // Must be Collection classes. We will use aop.ClassProxy instance instead.
try {
@@ -609,7 +609,7 @@
Interceptor interceptor = CollectionInterceptorUtil.getInterceptor((ClassProxy)value);
value = ((AbstractCollectionInterceptor)interceptor).getOriginalInstance();
}
-
+
try {
field.set(result, value);
} catch (IllegalAccessException e) {
16 years, 6 months
JBoss Cache SVN: r5991 - core/branches/1.4.X/tests-50/functional/org/jboss/cache/aop.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-16 20:16:30 -0400 (Mon, 16 Jun 2008)
New Revision: 5991
Modified:
core/branches/1.4.X/tests-50/functional/org/jboss/cache/aop/ReplicatedAnnotationAopTest.java
Log:
Remove invalid test
Modified: core/branches/1.4.X/tests-50/functional/org/jboss/cache/aop/ReplicatedAnnotationAopTest.java
===================================================================
--- core/branches/1.4.X/tests-50/functional/org/jboss/cache/aop/ReplicatedAnnotationAopTest.java 2008-06-16 16:58:35 UTC (rev 5990)
+++ core/branches/1.4.X/tests-50/functional/org/jboss/cache/aop/ReplicatedAnnotationAopTest.java 2008-06-17 00:16:30 UTC (rev 5991)
@@ -105,29 +105,6 @@
}
- public void testSeriazableAnnotationWithRelationship() throws Exception
- {
- log_.info("testSerializableAnnotationWithRelationship() ....");
- Gadget ga = new Gadget();
- ga.setName("Printer");
- SpecialAddress addr = new SpecialAddress();
- addr.setAddr("10.1.2.2");
- ga.setAddr(addr);
-
- cache_.putObject("/gadget1", ga);
- Object obj = cache_.getObject("/gadget1");
- assertEquals(ga, obj);
-
- Gadget ga2 = new Gadget();
- ga2.setName("Fax");
- ga2.setAddr(addr);
- cache_.putObject("/gadget2", ga2);
-
- ga = (Gadget)cache1_.getObject("/gadget1");
- ga2 = (Gadget)cache1_.getObject("/gadget2");
- assertTrue("Sepcial address should be the same ", ga.getAddr() == ga2.getAddr());
- }
-
public static Test suite() throws Exception
{
return new TestSuite(ReplicatedAnnotationAopTest.class);
16 years, 6 months
JBoss Cache SVN: r5990 - in searchable/trunk/src: test/java and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-16 12:58:35 -0400 (Mon, 16 Jun 2008)
New Revision: 5990
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
searchable/trunk/src/test/java/org/
searchable/trunk/src/test/java/org/jboss/
searchable/trunk/src/test/java/org/jboss/cache/
searchable/trunk/src/test/java/org/jboss/cache/search/
searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/test/
searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
Removed:
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Renamed stuff
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -3,12 +3,13 @@
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Sort;
import org.hibernate.search.FullTextFilter;
+
/**
@author Navin Surtani - navin(a)surtani.org
*/
+// TODO: Can we remove this?
public interface CacheQuery
{
- //TODO: Figure out where we got this interface from ... then get the methods from the impl of THAT impl and copy it into CacheQuery impl.
/**
* Allows to let lucene sort the results. This is useful when you have
* additional sort requirements on top of the default lucene ranking.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -2,64 +2,80 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.apache.lucene.search.Query;
import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Sort;
-import org.hibernate.HibernateException;
+import org.hibernate.*;
+import org.hibernate.type.Type;
+import org.hibernate.transform.ResultTransformer;
import org.hibernate.search.FullTextFilter;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.search.SearchException;
+import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.FilterDef;
import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.filter.ChainedFilter;
+import org.hibernate.search.filter.FilterKey;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.query.FullTextFilterImpl;
-import org.hibernate.search.util.ContextHelper;
+import org.hibernate.search.reader.ReaderProvider;
+import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
+import org.hibernate.search.store.DirectoryProvider;
import org.jboss.cache.Cache;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+import java.math.BigDecimal;
+import java.math.BigInteger;
/**
* @author Navin Surtani - navin(a)surtani.org
*/
-public class CacheQueryImpl implements CacheQuery
+public class CacheQueryImpl implements FullTextQuery
{
//TODO: Javadoc all these methods
- private Query query;
private Cache cache;
private Class[] classes;
private Sort sort;
private Filter filter;
private Map<String, FullTextFilterImpl> filterDefinitions;
- private SearchFactoryImplementor searchFactoryImplementor;
+ private SearchFactoryImpl searchFactory;
private Integer firstResult;
private Integer resultSize;
private Integer maxResults;
private static final Log log = LogFactory.getLog(CacheQueryImpl.class);
+ private Set<Class> classesAndSubclasses;
+ private boolean needClassFilterClause;
+ private Query luceneQuery;
+ private int fetchSize;
- public CacheQueryImpl(Query luceneQuery, Cache cache)
+ public CacheQueryImpl(Query luceneQuery, SearchFactoryImpl searchFactory, Cache cache)
{
- this.query = luceneQuery;
+ this.luceneQuery = luceneQuery;
this.cache = cache;
+ this.searchFactory = searchFactory;
}
- public CacheQueryImpl(Query luceneQuery, Cache cache, Class... classes)
+ public CacheQueryImpl(Query luceneQuery, SearchFactoryImpl searchFactory, Cache cache, Class... classes)
{
- this.query = luceneQuery;
+ this.luceneQuery = luceneQuery;
this.cache = cache;
this.classes = classes;
+ this.searchFactory = searchFactory;
}
- public CacheQuery setSort(Sort sort)
+ public FullTextQuery setSort(Sort sort)
{
this.sort = sort;
return this;
}
- public CacheQuery setFilter(Filter filter)
+ public FullTextQuery setFilter(Filter filter)
{
this.filter = filter;
return this;
@@ -70,8 +86,7 @@
if (resultSize == null)
{
//get result size without object initialization
- SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI(session);
- IndexSearcher searcher = buildSearcher(searchFactoryImplementor);
+ IndexSearcher searcher = buildSearcher(searchFactory);
if (searcher == null)
{
resultSize = 0;
@@ -93,12 +108,12 @@
//searcher cannot be null
try
{
- closeSearcher(searcher, searchFactoryImplementor.getReaderProvider());
+ closeSearcher(searcher, searchFactory.getReaderProvider());
//searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
}
catch (SearchException e)
{
- log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
+ log.warn("Unable to properly close searcher during lucene query: " + e);
}
}
}
@@ -106,6 +121,24 @@
return this.resultSize;
}
+ public FullTextQuery setCriteriaQuery(Criteria criteria)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public FullTextQuery setProjection(String... strings)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ private void closeSearcher(Searcher searcher, ReaderProvider readerProvider) {
+ Set<IndexReader> indexReaders = getIndexReaders( searcher );
+
+ for (IndexReader indexReader : indexReaders) {
+ readerProvider.closeReader( indexReader );
+ }
+ }
+
public FullTextFilter enableFullTextFilter(String name)
{
if (filterDefinitions == null)
@@ -117,7 +150,7 @@
filterDefinition = new FullTextFilterImpl();
filterDefinition.setName(name);
- FilterDef filterDef = getSearchFactoryImplementor().getFilterDefinition(name);
+ FilterDef filterDef = searchFactory.getFilterDefinition(name);
if (filterDef == null)
{
throw new SearchException("Unkown @FullTextFilter: " + name);
@@ -126,44 +159,653 @@
return filterDefinition;
}
- private SearchFactoryImplementor getSearchFactoryImplementor()
+ public void disableFullTextFilter(String name)
{
- if (searchFactoryImplementor == null)
+ filterDefinitions.remove(name);
+ }
+
+ public FullTextQuery setFirstResult(int firstResult)
+ {
+ if (firstResult < 0)
{
- searchFactoryImplementor = createNewSearchFactoryImpl();
+ throw new IllegalArgumentException("'first' pagination parameter less than 0");
}
- return searchFactoryImplementor;
+ this.firstResult = firstResult;
+ return this;
}
- private synchronized SearchFactoryImplementor createNewSearchFactoryImpl()
+ public org.hibernate.Query setReadOnly(boolean b)
{
- if (searchFactoryImplementor == null) searchFactoryImplementor = new SearchFactoryImpl(null); // TODO: This really expects a Hibernate Config object. How can we work around that?@??
- return searchFactoryImplementor;
+ return null; //TODO: Generated method. Do we need this method?
}
+ public org.hibernate.Query setCacheable(boolean b)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
- public void disableFullTextFilter(String name)
+ public org.hibernate.Query setCacheRegion(String s)
{
- filterDefinitions.remove(name);
+ return null; //TODO: Generated method. Do we need this method?
}
- public CacheQuery setFirstResult(int firstResult)
+ public org.hibernate.Query setTimeout(int i)
{
- if (firstResult < 0)
- {
- throw new IllegalArgumentException("'first' pagination parameter less than 0");
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public String getQueryString()
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public Type[] getReturnTypes() throws HibernateException
+ {
+ return new Type[0]; //TODO: Generated method. Do we need this method?
+ }
+
+ public String[] getReturnAliases() throws HibernateException
+ {
+ return new String[0]; //TODO: Generated method. Do we need this method?
+ }
+
+ public String[] getNamedParameters() throws HibernateException
+ {
+ return new String[0]; //TODO: Generated method. Do we need this method?
+ }
+
+ public Iterator iterate() throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public ScrollableResults scroll() throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public List list() throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public Object uniqueResult() throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public int executeUpdate() throws HibernateException
+ {
+ return 0; //TODO: Generated method. Do we need this method?
+ }
+
+ public FullTextQuery setMaxResults(int maxResults) {
+ if ( maxResults < 0 ) {
+ throw new IllegalArgumentException( "'max' pagination parameter less than 0" );
}
- this.firstResult = firstResult;
+ this.maxResults = maxResults;
return this;
}
- public CacheQuery setMaxResults(int maxResults)
+ public FullTextQuery setFetchSize(int fetchSize) {
+ if ( fetchSize <= 0 ) {
+ throw new IllegalArgumentException( "'fetch size' parameter less than or equals to 0" );
+ }
+ this.fetchSize = fetchSize;
+ return this;
+ }
+
+ public org.hibernate.Query setLockMode(String s, LockMode lockMode)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null; //TODO: Generated method. Do we need this method?
}
- public CacheQuery setFetchSize(int i)
+ public org.hibernate.Query setComment(String s)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null; //TODO: Generated method. Do we need this method?
}
+
+ public org.hibernate.Query setFlushMode(FlushMode flushMode)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCacheMode(CacheMode cacheMode)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameter(int i, Object o, Type type)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameter(String s, Object o, Type type)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameter(int i, Object o) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameter(String s, Object o) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameters(Object[] objects, Type[] types) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameterList(String s, Collection collection, Type type) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameterList(String s, Collection collection) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameterList(String s, Object[] objects, Type type) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setParameterList(String s, Object[] objects) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setProperties(Object o) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setProperties(Map map) throws HibernateException
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setString(int i, String s)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCharacter(int i, char c)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBoolean(int i, boolean b)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setByte(int i, byte b)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setShort(int i, short i1)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setInteger(int i, int i1)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setLong(int i, long l)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setFloat(int i, float v)
+ {
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
+ }
+
+ public org.hibernate.Query setDouble(int i, double v)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBinary(int i, byte[] bytes)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setText(int i, String s)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setSerializable(int i, Serializable serializable)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setLocale(int i, Locale locale)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBigDecimal(int i, BigDecimal bigDecimal)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBigInteger(int i, BigInteger bigInteger)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setDate(int i, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setTime(int i, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setTimestamp(int i, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCalendar(int i, Calendar calendar)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCalendarDate(int i, Calendar calendar)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setString(String s, String s1)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCharacter(String s, char c)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBoolean(String s, boolean b)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setByte(String s, byte b)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setShort(String s, short i)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setInteger(String s, int i)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setLong(String s, long l)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setFloat(String s, float v)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setDouble(String s, double v)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBinary(String s, byte[] bytes)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setText(String s, String s1)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setSerializable(String s, Serializable serializable)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setLocale(String s, Locale locale)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBigDecimal(String s, BigDecimal bigDecimal)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setBigInteger(String s, BigInteger bigInteger)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setDate(String s, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setTime(String s, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setTimestamp(String s, Date date)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCalendar(String s, Calendar calendar)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setCalendarDate(String s, Calendar calendar)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setEntity(int i, Object o)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public org.hibernate.Query setEntity(String s, Object o)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ public FullTextQuery setResultTransformer(ResultTransformer resultTransformer)
+ {
+ return null; //TODO: Generated method. Do we need this method?
+ }
+
+ private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor)
+ {
+ Map<Class, DocumentBuilder<Object>> builders = searchFactoryImplementor.getDocumentBuilders();
+ List<DirectoryProvider> directories = new ArrayList<DirectoryProvider>();
+
+ Similarity searcherSimilarity = null;
+
+ if (classes == null || classes.length == 0)
+ {
+ //no class means all classes
+ for (DocumentBuilder builder : builders.values())
+ {
+ searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
+ final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
+ populateDirectories(directories, directoryProviders, searchFactoryImplementor);
+ }
+ classesAndSubclasses = null;
+ }
+ else
+ {
+ Set<Class> involvedClasses = new HashSet<Class>(classes.length);
+ Collections.addAll(involvedClasses, classes);
+ for (Class clazz : classes)
+ {
+ DocumentBuilder builder = builders.get(clazz);
+ if (builder != null) involvedClasses.addAll(builder.getMappedSubclasses());
+ }
+
+ for (Class clazz : involvedClasses)
+ {
+ DocumentBuilder builder = builders.get(clazz);
+ if (builder == null)
+ throw new HibernateException("Not a mapped entity (don't forget to add @Indexed): " + clazz);
+
+ final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
+ searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
+ populateDirectories(directories, directoryProviders, searchFactoryImplementor);
+ }
+ classesAndSubclasses = involvedClasses;
+ }
+
+ //compute optimization needClassFilterClause
+ //if at least one DP contains one class that is not part of the targeted classesAndSubclasses we can't optimize
+ if (classesAndSubclasses != null)
+ {
+ for (DirectoryProvider dp : directories)
+ {
+ final Set<Class> classesInDirectoryProvider = searchFactoryImplementor.getClassesInDirectoryProvider(dp);
+ // if a DP contains only one class, we know for sure it's part of classesAndSubclasses
+ if (classesInDirectoryProvider.size() > 1)
+ {
+ //risk of needClassFilterClause
+ for (Class clazz : classesInDirectoryProvider)
+ {
+ if (!classesAndSubclasses.contains(clazz))
+ {
+ this.needClassFilterClause = true;
+ break;
+ }
+ }
+ }
+ if (this.needClassFilterClause) break;
+ }
+ }
+
+ //set up the searcher
+ final DirectoryProvider[] directoryProviders = directories.toArray(new DirectoryProvider[directories.size()]);
+ IndexSearcher is = new IndexSearcher(searchFactoryImplementor.getReaderProvider().openReader(directoryProviders));
+ is.setSimilarity(searcherSimilarity);
+ return is;
+ }
+
+ private Similarity checkSimilarity(Similarity similarity, DocumentBuilder builder)
+ {
+ if (similarity == null)
+ {
+ similarity = builder.getSimilarity();
+ }
+ else if (!similarity.getClass().equals(builder.getSimilarity().getClass()))
+ {
+ throw new HibernateException("Cannot perform search on two entities with differing Similarity implementations (" + similarity.getClass().getName() + " & " + builder.getSimilarity().getClass().getName() + ")");
+ }
+
+ return similarity;
+ }
+
+ private void populateDirectories(List<DirectoryProvider> directories, DirectoryProvider[] directoryProviders,
+ SearchFactoryImplementor searchFactoryImplementor)
+ {
+ for (DirectoryProvider provider : directoryProviders)
+ {
+ if (!directories.contains(provider))
+ {
+ directories.add(provider);
+ }
+ }
+ }
+
+ private Hits getHits(Searcher searcher) throws IOException
+ {
+ Hits hits;
+ org.apache.lucene.search.Query query = filterQueryByClasses(luceneQuery);
+ buildFilters();
+ hits = searcher.search(query, filter, sort);
+ setResultSize(hits);
+ return hits;
+ }
+
+ private void setResultSize(Hits hits)
+ {
+ resultSize = hits.length();
+ }
+
+ private org.apache.lucene.search.Query filterQueryByClasses(org.apache.lucene.search.Query luceneQuery)
+ {
+ if (!needClassFilterClause)
+ {
+ return luceneQuery;
+ }
+ else
+ {
+ //A query filter is more practical than a manual class filtering post query (esp on scrollable resultsets)
+ //it also probably minimise the memory footprint
+ BooleanQuery classFilter = new BooleanQuery();
+ //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
+ classFilter.setBoost(0);
+ for (Class clazz : classesAndSubclasses)
+ {
+ Term t = new Term(DocumentBuilder.CLASS_FIELDNAME, clazz.getName());
+ TermQuery termQuery = new TermQuery(t);
+ classFilter.add(termQuery, BooleanClause.Occur.SHOULD);
+ }
+ BooleanQuery filteredQuery = new BooleanQuery();
+ filteredQuery.add(luceneQuery, BooleanClause.Occur.MUST);
+ filteredQuery.add(classFilter, BooleanClause.Occur.MUST);
+ return filteredQuery;
+ }
+ }
+
+ private void buildFilters()
+ {
+ if (filterDefinitions != null && filterDefinitions.size() > 0)
+ {
+ ChainedFilter chainedFilter = new ChainedFilter();
+ for (FullTextFilterImpl filterDefinition : filterDefinitions.values())
+ {
+ FilterDef def = searchFactory.getFilterDefinition(filterDefinition.getName());
+ Class implClass = def.getImpl();
+ Object instance;
+ try
+ {
+ instance = implClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new SearchException("Unable to create @FullTextFilterDef: " + def.getImpl(), e);
+ }
+ for (Map.Entry<String, Object> entry : filterDefinition.getParameters().entrySet())
+ {
+ def.invoke(entry.getKey(), instance, entry.getValue());
+ }
+ if (def.isCache() && def.getKeyMethod() == null && filterDefinition.getParameters().size() > 0)
+ {
+ throw new SearchException("Filter with parameters and no @Key method: " + filterDefinition.getName());
+ }
+ FilterKey key = null;
+ if (def.isCache())
+ {
+ if (def.getKeyMethod() == null)
+ {
+ key = new FilterKey()
+ {
+ public int hashCode()
+ {
+ return getImpl().hashCode();
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof FilterKey)) return false;
+ FilterKey that = (FilterKey) obj;
+ return this.getImpl().equals(that.getImpl());
+ }
+ };
+ }
+ else
+ {
+ try
+ {
+ key = (FilterKey) def.getKeyMethod().invoke(instance);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new SearchException("Unable to access @Key method: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new SearchException("Unable to access @Key method: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ }
+ catch (ClassCastException e)
+ {
+ throw new SearchException("@Key method does not return FilterKey: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ }
+ }
+ key.setImpl(def.getImpl());
+ }
+
+ Filter filter = def.isCache() ?
+ searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+ null;
+ if (filter == null)
+ {
+ if (def.getFactoryMethod() != null)
+ {
+ try
+ {
+ filter = (Filter) def.getFactoryMethod().invoke(instance);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new SearchException("Unable to access @Factory method: "
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new SearchException("Unable to access @Factory method: "
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ }
+ catch (ClassCastException e)
+ {
+ throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ }
+ }
+ else
+ {
+ try
+ {
+ filter = (Filter) instance;
+ }
+ catch (ClassCastException e)
+ {
+ throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ }
+ }
+ if (def.isCache())
+ searchFactory.getFilterCachingStrategy().addCachedFilter(key, filter);
+ }
+ chainedFilter.addFilter(filter);
+ }
+ if (filter != null) chainedFilter.addFilter(filter);
+ filter = chainedFilter;
+ }
+ }
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -0,0 +1,28 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.CacheException;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class InvalidFqnException extends CacheException
+{
+ public InvalidFqnException()
+ {
+ }
+
+ public InvalidFqnException(String s)
+ {
+ super(s);
+ }
+
+ public InvalidFqnException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public InvalidFqnException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -5,8 +5,6 @@
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
/**
@author Navin Surtani - navin(a)surtani.org
@@ -17,6 +15,11 @@
//TODO: Javadoc all these methods
NodeModifiedEvent event;
+ public NodeModifiedTransactionContext(NodeModifiedEvent event)
+ {
+ this.event = event;
+ }
+
public boolean isTxInProgress()
{
return (event.getTransaction() != null);
@@ -34,14 +37,9 @@
{
transaction.registerSynchronization(synchronization);
}
- catch (SystemException e)
+ catch (Exception e)
{
- e.printStackTrace();
+ throw new RuntimeException(e);
}
- catch (RollbackException e)
- {
- e.printStackTrace();
- }
-
}
}
Deleted: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -1,72 +0,0 @@
-package org.jboss.cache.search;
-
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.Sort;
-import org.hibernate.search.FullTextFilter;
-import org.hibernate.search.FullTextQuery;
-
-/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 3:13:27 PM
- * To change this template use File | Settings | File Templates.
- */
-public interface QueryResult {
-
- /**
- * Allows to let lucene sort the results. This is useful when you have
- * additional sort requirements on top of the default lucene ranking.
- * Without lucene sorting you would have to retrieve the full result set and
- * order the hibernate objects.
- *
- * @param sort The lucene sort object.
- * @return this for method chaining
- */
- FullTextQuery setSort(Sort sort);
-
- /**
- * Allows to use lucene filters.
- * Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach
- *
- * @param filter The lucene filter.
- * @return this for method chaining
- */
- FullTextQuery setFilter(Filter filter);
-
- /**
- * Returns the number of hits for this search
- * <p/>
- * Caution:
- * The number of results might be slightly different from
- * <code>list().size()</code> because list() if the index is
- * not in sync with the database at the time of query.
- */
- int getResultSize();
-
- /**
- * Enable a given filter by its name. Returns a FullTextFilter object that allows filter parameter injection
- */
- FullTextFilter enableFullTextFilter(String name);
-
- /**
- * Disable a given filter by its name
- */
- void disableFullTextFilter(String name);
-
- /**
- * {link:Query#setFirstResult}
- */
- FullTextQuery setFirstResult(int firstResult);
-
- /**
- * {link:Query#setMaxResults}
- */
- FullTextQuery setMaxResults(int maxResults);
-
- /**
- * Defines scrollable result fetch size as well as the JDBC fetch size
- */
- FullTextQuery setFetchSize(int i);
-
-}
Deleted: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -1,76 +0,0 @@
-package org.jboss.cache.search;
-
-import org.hibernate.search.FullTextQuery;
-import org.hibernate.search.FullTextFilter;
-import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.Query;
-import org.jboss.cache.Cache;
-
-/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 3:23:25 PM
- * To change this template use File | Settings | File Templates.
- */
-public class QueryResultImpl implements QueryResult
-{
- private Query query;
- private Cache cache;
- private Class[] classes;
-
- public QueryResultImpl(Query luceneQuery, Cache cache)
- {
- this.query = luceneQuery;
- this.cache = cache;
- }
-
- public QueryResultImpl(Query luceneQuery, Cache cache, Class[] classes)
- {
- this.query = luceneQuery;
- this.cache=cache;
- this.classes = classes;
-
- }
-
- public FullTextQuery setSort(Sort sort)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public FullTextQuery setFilter(Filter filter)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int getResultSize()
- {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public FullTextFilter enableFullTextFilter(String name)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void disableFullTextFilter(String name)
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public FullTextQuery setFirstResult(int firstResult)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public FullTextQuery setMaxResults(int maxResults)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public FullTextQuery setFetchSize(int i)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -1,6 +1,7 @@
package org.jboss.cache.search;
import org.apache.lucene.search.Query;
+import org.hibernate.search.FullTextQuery;
import org.jboss.cache.Cache;
/**
@@ -14,8 +15,8 @@
* @param luceneQuery
* @return
*/
- public CacheQuery createQuery(Query luceneQuery);
+ public FullTextQuery createQuery(Query luceneQuery);
- public CacheQuery createQuery(Query luceneQuery, Class... classes);
+ public FullTextQuery createQuery(Query luceneQuery, Class... classes);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -1,8 +1,12 @@
package org.jboss.cache.search;
+import org.hibernate.cfg.Configuration;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import java.util.Properties;
+
/**
@author Navin Surtani - navin(a)surtani.org
*/
@@ -13,13 +17,32 @@
public SearchableCache createSearchableCache (Cache c, Class... classes)
{
+ return createSearchableCache(c, null, classes);
+ }
- // TODO: Initialise HS internals and use the classes array that's being passed in as a param
+ public SearchableCache createSearchableCache (Cache c, Properties properties, Class... classes)
+ {
+ // assume cache is already created and running.
+ // otherwise, start the cache!!
+ if (c.getCacheStatus() != CacheStatus.STARTED) c.start();
+ // Step 1: Add cache listener to listen for events happening in the cache.
SearchableListener listener = new SearchableListener();
c.addCacheListener(listener);
- SearchableCache sc = new SearchableCacheImpl(c);
+ // step 2: create hibernate search searchImpl
+ Configuration cfg = new Configuration();
+ if (properties != null) cfg.setProperties(properties);
+ // set classes in the cfg
+ if (classes != null)
+ {
+ for (Class clazz : classes) cfg.addClass(clazz);
+ }
+
+ SearchFactoryImpl searchImpl = new SearchFactoryImpl(cfg);
+
+ // step 3: create the searchable cache delegate.
+ SearchableCache sc = new SearchableCacheImpl(c, searchImpl);
return sc;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -1,6 +1,8 @@
package org.jboss.cache.search;
import org.apache.lucene.search.Query;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.FullTextQuery;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheStatus;
@@ -23,23 +25,24 @@
{
// this is the ACTUAL cache. that does all the work.
private Cache cache;
- private Class[] classes;
+ private SearchFactoryImpl searchFactory;
//TODO: Javadoc all these methods
- public SearchableCacheImpl(Cache cache)
+ public SearchableCacheImpl(Cache cache, SearchFactoryImpl searchFactory)
{
this.cache = cache;
+ this.searchFactory = searchFactory;
}
- public CacheQuery createQuery(Query luceneQuery)
+ public FullTextQuery createQuery(Query luceneQuery)
{
- return new CacheQueryImpl(luceneQuery, cache);
+ return new CacheQueryImpl(luceneQuery, searchFactory, cache);
}
- public CacheQuery createQuery(Query luceneQuery, Class... classes)
+ public FullTextQuery createQuery(Query luceneQuery, Class... classes)
{
- return new CacheQueryImpl(luceneQuery, cache, classes);
+ return new CacheQueryImpl(luceneQuery, searchFactory, cache, classes);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -11,42 +11,46 @@
import java.util.Map;
/**
-@author Navin Surtani - navin(a)surtani.org
+ * @author Navin Surtani - navin(a)surtani.org
*/
@CacheListener
public class SearchableListener
{
-//TODO: Javadoc everything
+ //TODO: Javadoc everything
private SearchFactoryImpl searchFactory;
- private TransactionContext transactionContext;
@NodeModified
public void updateLuceneIndexes(NodeModifiedEvent event)
{
- if (event.getModificationType() == NodeModifiedEvent.ModificationType.valueOf("PUT_DATA"))
+ if (!event.isPre())
+ {
+ switch (event.getModificationType())
{
- handlePutData(event);
+ case PUT_MAP:
+ case PUT_DATA:
+ handlePutData(event);
+ break;
+ case REMOVE_DATA:
+ handleDeleteData(event);
+ break;
}
-
- if (event.getModificationType() == NodeModifiedEvent.ModificationType.valueOf("DELETE_DATA"))
- {
- handleDeleteData(event);
- }
+ }
}
void handlePutData(NodeModifiedEvent event)
{
Map dataMap = event.getData();
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
for (Object key : dataMap.keySet())
{
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), transactionContext);
-
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.ADD), transactionContext);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), ctx);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.ADD), ctx);
}
}
@@ -55,12 +59,14 @@
{
Map dataMap = event.getData();
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
for (Object key : dataMap.keySet())
{
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), transactionContext);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), ctx);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-16 14:26:08 UTC (rev 5989)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -46,8 +46,10 @@
return fqn;
}
- public static String generateId(Fqn fqn, String key)
+ public static String generateId(Fqn fqn, String key) throws InvalidFqnException
{
+ if (key == null) throw new InvalidFqnException("Key passed in cannot be null!");
+
StringBuilder sb = new StringBuilder();
sb.append("Fqn=[");
sb.append(fqn);
Added: searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -0,0 +1,38 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.Test;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+@Test
+public class BlackBoxTest
+{
+ public void doTest()
+ {
+ Cache cache = new DefaultCacheFactory().createCache();
+ SearchableCache sc = new SearchableCacheFactory().createSearchableCache(cache, Person.class);
+ Person p1 = new Person();
+ p1.setName("Navin Surtani");
+ p1.setBlurb("Likes playing WoW");
+ sc.put(Fqn.fromString("/a/b/c"), "Navin", p1);
+
+ // try and search for navin
+ // TODO: Create a dummy lucene query
+ //sc.createQuery(new LQ)
+ // TODO: Test should search on name, as well as blurb. Try both cases.
+ // TODO: Also test with stuff in different Fqns.
+ // TODO; test if the indexes get updated. Try changing the values of a Person object and put it back in the cache.
+
+ // TODO: Test more complex object graphs. Put a person Object which has an address which has a City class with a name and description about that city. Then try finding stuff by searching on the city.
+
+ // TODO: test removal of stuff. Remove stuff and see if you can still search for it. You should not be able to.
+ // TODO: Create more black box tests - use a replicated cache, put stuff in one instance and perform searches on anotehr instance.
+ // TODO: Test stuff with PojoCache. Put stuff in PojoCache (using cache.attach()) and see if you can find stuff.
+
+ }
+}
Copied: searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java (from rev 5951, searchable/trunk/src/test/java/TransformerTest.java)
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -0,0 +1,98 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+import org.testng.annotations.Test;
+
+/**
+@author Navin Surtani - navin(a)surtani.org
+ */
+
+@Test
+public class TransformerTest
+{
+ //TODO: Javadoc everything
+ public void testGenerateId()
+ {
+
+ Fqn fqn = Fqn.fromString("/a/b/c");
+ String key = "key";
+
+ String generatedId = Transformer.generateId(fqn, key);
+
+ assert generatedId.contentEquals("Fqn=[/a/b/c]Key=[key]");
+
+ assert ! generatedId.contentEquals("/ab/c/d");
+ }
+
+ public void testGetFqn()
+ {
+ Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
+
+ Fqn expectedFqn = Fqn.fromString("/cat/dog/person");
+
+ assert fqn.equals(expectedFqn);
+
+ expectedFqn = Fqn.fromString("/dog/cat/person");
+
+ assert !fqn.equals(expectedFqn);
+
+ }
+
+ public void testGetKey()
+ {
+ String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
+
+ assert key.contentEquals("thisIsMyKey");
+
+ assert ! key.contentEquals("thisIsNotMyKey");
+
+ }
+
+ @Test (expectedExceptions = NullPointerException.class)
+ public void testGetKeyWithNull()
+ {
+ Transformer.getKey(null);
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithHackedString()
+ {
+ Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithHackedFqn()
+ {
+ Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithHackedFqn2()
+ {
+ Transformer.generateId(Fqn.fromString("/]Key=[/a/b/c"), "x");
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithHackedKey()
+ {
+ Transformer.generateId(Fqn.fromString("/a/b/c"), "]Key=[");
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithHackedKey2()
+ {
+ Transformer.generateId(Fqn.fromString("/a/b/c"), "Fqn=[");
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithNullKey()
+ {
+ Transformer.generateId(Fqn.fromString("/a/b/c"), null);
+ }
+
+ @Test (expectedExceptions = InvalidFqnException.class)
+ public void testGenerateIdWithNullFqn()
+ {
+ Transformer.generateId(null, "x");
+ }
+}
Added: searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java 2008-06-16 16:58:35 UTC (rev 5990)
@@ -0,0 +1,36 @@
+package org.jboss.cache.search.test;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+@Indexed
+public class Person
+{
+ @Field
+ private String name;
+ @Field
+ private String blurb;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getBlurb()
+ {
+ return blurb;
+ }
+
+ public void setBlurb(String blurb)
+ {
+ this.blurb = blurb;
+ }
+}
16 years, 6 months
JBoss Cache SVN: r5989 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-16 10:26:08 -0400 (Mon, 16 Jun 2008)
New Revision: 5989
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
Log:
Play nice with 3.0.0.
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-06-16 14:05:46 UTC (rev 5988)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-06-16 14:26:08 UTC (rev 5989)
@@ -78,7 +78,7 @@
byte[] bytes = marshaller.objectToByteBuffer("Hello");
ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(bytes));
- assertEquals("Version header short should be '22'", 22, in.readShort());
+ assertEquals("Version header short should be '30'", 30, in.readShort());
}
public void testVersionHeader210() throws Exception
16 years, 6 months
JBoss Cache SVN: r5988 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-16 10:05:46 -0400 (Mon, 16 Jun 2008)
New Revision: 5988
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Renamed stuff
Copied: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java (from rev 5947, searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java)
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -0,0 +1,67 @@
+package org.jboss.cache.search;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Sort;
+import org.hibernate.search.FullTextFilter;
+/**
+@author Navin Surtani - navin(a)surtani.org
+ */
+public interface CacheQuery
+{
+ //TODO: Figure out where we got this interface from ... then get the methods from the impl of THAT impl and copy it into CacheQuery impl.
+ /**
+ * Allows to let lucene sort the results. This is useful when you have
+ * additional sort requirements on top of the default lucene ranking.
+ * Without lucene sorting you would have to retrieve the full result set and
+ * order the hibernate objects.
+ *
+ * @param sort The lucene sort object.
+ * @return this for method chaining
+ */
+ CacheQuery setSort(Sort sort);
+
+ /**
+ * Allows to use lucene filters.
+ * Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach
+ *
+ * @param filter The lucene filter.
+ * @return this for method chaining
+ */
+ CacheQuery setFilter(Filter filter);
+
+ /**
+ * Returns the number of hits for this search
+ * <p/>
+ * Caution:
+ * The number of results might be slightly different from
+ * <code>list().size()</code> because list() if the index is
+ * not in sync with the database at the time of query.
+ */
+ int getResultSize();
+
+ /**
+ * Enable a given filter by its name. Returns a FullTextFilter object that allows filter parameter injection
+ */
+ FullTextFilter enableFullTextFilter(String name);
+
+ /**
+ * Disable a given filter by its name
+ */
+ void disableFullTextFilter(String name);
+
+ /**
+ * {link:Query#setFirstResult}
+ */
+ CacheQuery setFirstResult(int firstResult);
+
+ /**
+ * {link:Query#setMaxResults}
+ */
+ CacheQuery setMaxResults(int maxResults);
+
+ /**
+ * Defines scrollable result fetch size as well as the JDBC fetch size
+ */
+ CacheQuery setFetchSize(int i);
+
+}
Copied: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java (from rev 5965, searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java)
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -0,0 +1,169 @@
+package org.jboss.cache.search;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Sort;
+import org.hibernate.HibernateException;
+import org.hibernate.search.FullTextFilter;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.engine.FilterDef;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.query.FullTextFilterImpl;
+import org.hibernate.search.util.ContextHelper;
+import org.jboss.cache.Cache;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class CacheQueryImpl implements CacheQuery
+{
+ //TODO: Javadoc all these methods
+ private Query query;
+ private Cache cache;
+ private Class[] classes;
+ private Sort sort;
+ private Filter filter;
+ private Map<String, FullTextFilterImpl> filterDefinitions;
+ private SearchFactoryImplementor searchFactoryImplementor;
+ private Integer firstResult;
+ private Integer resultSize;
+ private Integer maxResults;
+ private static final Log log = LogFactory.getLog(CacheQueryImpl.class);
+
+ public CacheQueryImpl(Query luceneQuery, Cache cache)
+ {
+ this.query = luceneQuery;
+ this.cache = cache;
+ }
+
+ public CacheQueryImpl(Query luceneQuery, Cache cache, Class... classes)
+ {
+ this.query = luceneQuery;
+ this.cache = cache;
+ this.classes = classes;
+
+ }
+
+ public CacheQuery setSort(Sort sort)
+ {
+ this.sort = sort;
+ return this;
+ }
+
+ public CacheQuery setFilter(Filter filter)
+ {
+ this.filter = filter;
+ return this;
+ }
+
+ public int getResultSize()
+ {
+ if (resultSize == null)
+ {
+ //get result size without object initialization
+ SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI(session);
+ IndexSearcher searcher = buildSearcher(searchFactoryImplementor);
+ if (searcher == null)
+ {
+ resultSize = 0;
+ }
+ else
+ {
+ Hits hits;
+ try
+ {
+ hits = getHits(searcher);
+ resultSize = hits.length();
+ }
+ catch (IOException e)
+ {
+ throw new HibernateException("Unable to query Lucene index", e);
+ }
+ finally
+ {
+ //searcher cannot be null
+ try
+ {
+ closeSearcher(searcher, searchFactoryImplementor.getReaderProvider());
+ //searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
+ }
+ catch (SearchException e)
+ {
+ log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
+ }
+ }
+ }
+ }
+ return this.resultSize;
+ }
+
+ public FullTextFilter enableFullTextFilter(String name)
+ {
+ if (filterDefinitions == null)
+ {
+ filterDefinitions = new HashMap<String, FullTextFilterImpl>();
+ }
+ FullTextFilterImpl filterDefinition = filterDefinitions.get(name);
+ if (filterDefinition != null) return filterDefinition;
+
+ filterDefinition = new FullTextFilterImpl();
+ filterDefinition.setName(name);
+ FilterDef filterDef = getSearchFactoryImplementor().getFilterDefinition(name);
+ if (filterDef == null)
+ {
+ throw new SearchException("Unkown @FullTextFilter: " + name);
+ }
+ filterDefinitions.put(name, filterDefinition);
+ return filterDefinition;
+ }
+
+ private SearchFactoryImplementor getSearchFactoryImplementor()
+ {
+ if (searchFactoryImplementor == null)
+ {
+ searchFactoryImplementor = createNewSearchFactoryImpl();
+ }
+ return searchFactoryImplementor;
+ }
+
+ private synchronized SearchFactoryImplementor createNewSearchFactoryImpl()
+ {
+ if (searchFactoryImplementor == null) searchFactoryImplementor = new SearchFactoryImpl(null); // TODO: This really expects a Hibernate Config object. How can we work around that?@??
+ return searchFactoryImplementor;
+ }
+
+
+ public void disableFullTextFilter(String name)
+ {
+ filterDefinitions.remove(name);
+ }
+
+ public CacheQuery setFirstResult(int firstResult)
+ {
+ if (firstResult < 0)
+ {
+ throw new IllegalArgumentException("'first' pagination parameter less than 0");
+ }
+ this.firstResult = firstResult;
+ return this;
+ }
+
+ public CacheQuery setMaxResults(int maxResults)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public CacheQuery setFetchSize(int i)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -9,14 +9,12 @@
import javax.transaction.SystemException;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 13, 2008
- * Time: 4:23:26 PM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
public class NodeModifiedTransactionContext implements TransactionContext
{
+
+ //TODO: Javadoc all these methods
NodeModifiedEvent event;
public boolean isTxInProgress()
@@ -42,7 +40,7 @@
}
catch (RollbackException e)
{
- e.printStackTrace();
+ e.printStackTrace();
}
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -4,15 +4,18 @@
import org.jboss.cache.Cache;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 10:48:46 AM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
public interface SearchableCache extends Cache
{
- public QueryResult createQuery(Query luceneQuery);
+ /**
+ *
+ * @param luceneQuery
+ * @return
+ */
+ public CacheQuery createQuery(Query luceneQuery);
+ public CacheQuery createQuery(Query luceneQuery, Class... classes);
+
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -4,21 +4,17 @@
import org.jboss.cache.Cache;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 10:52:25 AM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
public class SearchableCacheFactory
{
-
+ //TODO: Javadoc everything.
private SearchFactoryImpl searchFactory;
public SearchableCache createSearchableCache (Cache c, Class... classes)
{
- // TODO: Initialise HS internals
+ // TODO: Initialise HS internals and use the classes array that's being passed in as a param
SearchableListener listener = new SearchableListener();
c.addCacheListener(listener);
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -17,11 +17,7 @@
import java.util.Set;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 10:51:53 AM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
public class SearchableCacheImpl implements SearchableCache
{
@@ -29,19 +25,21 @@
private Cache cache;
private Class[] classes;
+ //TODO: Javadoc all these methods
+
public SearchableCacheImpl(Cache cache)
{
this.cache = cache;
}
- public QueryResult createQuery(Query luceneQuery)
+ public CacheQuery createQuery(Query luceneQuery)
{
- return new QueryResultImpl(luceneQuery, cache);
+ return new CacheQueryImpl(luceneQuery, cache);
}
- public QueryResult createQuery(Query luceneQuery, Class... classes)
+ public CacheQuery createQuery(Query luceneQuery, Class... classes)
{
- return new QueryResultImpl(luceneQuery, cache, classes);
+ return new CacheQueryImpl(luceneQuery, cache, classes);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -11,25 +11,19 @@
import java.util.Map;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 11:42:50 AM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
@CacheListener
public class SearchableListener
{
-
+//TODO: Javadoc everything
private SearchFactoryImpl searchFactory;
private TransactionContext transactionContext;
@NodeModified
public void updateLuceneIndexes(NodeModifiedEvent event)
{
- if (!event.isPre())
- {
if (event.getModificationType() == NodeModifiedEvent.ModificationType.valueOf("PUT_DATA"))
{
handlePutData(event);
@@ -39,12 +33,6 @@
{
handleDeleteData(event);
}
-
- }
- else
- {
- //TODO: Ask Manik or EB about good ways to ignore the data. Just have souts? Perhaps log stuff.
- }
}
void handlePutData(NodeModifiedEvent event)
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-13 15:36:15 UTC (rev 5987)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-16 14:05:46 UTC (rev 5988)
@@ -3,14 +3,11 @@
import org.jboss.cache.Fqn;
/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 3, 2008
- * Time: 2:02:57 PM
- * To change this template use File | Settings | File Templates.
+@author Navin Surtani - navin(a)surtani.org
*/
public class Transformer
{
+ //TODO: Javadoc everything
public static String getKey(String docId)
{
//docID comes in the format "Fqn=[/a/b/c]Key=[key]"
@@ -62,6 +59,5 @@
}
- //TODO: Look at HS documentation to see what can be done about non-String keys.
}
16 years, 6 months
JBoss Cache SVN: r5987 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-13 11:36:15 -0400 (Fri, 13 Jun 2008)
New Revision: 5987
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
Log:
Work objects now added to queue.
Wrote up NodeModifiedTransactionContext which implements TransactionContext from HibernateSearch.
Added: searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-13 15:36:15 UTC (rev 5987)
@@ -0,0 +1,49 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.transaction.TransactionContext;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 13, 2008
+ * Time: 4:23:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class NodeModifiedTransactionContext implements TransactionContext
+{
+ NodeModifiedEvent event;
+
+ public boolean isTxInProgress()
+ {
+ return (event.getTransaction() != null);
+ }
+
+ public Object getTransactionIdentifier()
+ {
+ return event.getTransaction();
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ {
+ Transaction transaction = event.getTransaction();
+ try
+ {
+ transaction.registerSynchronization(synchronization);
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ }
+ catch (RollbackException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-13 02:36:30 UTC (rev 5986)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-13 15:36:15 UTC (rev 5987)
@@ -3,6 +3,7 @@
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.transaction.TransactionContext;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
@@ -22,18 +23,27 @@
{
private SearchFactoryImpl searchFactory;
+ private TransactionContext transactionContext;
@NodeModified
public void updateLuceneIndexes(NodeModifiedEvent event)
{
if (!event.isPre())
{
+ if (event.getModificationType() == NodeModifiedEvent.ModificationType.valueOf("PUT_DATA"))
+ {
+ handlePutData(event);
+ }
- // TODO: Update Lucene Indexes. See Hibernate Search's FullTextEventListener class for details on what to do.
+ if (event.getModificationType() == NodeModifiedEvent.ModificationType.valueOf("DELETE_DATA"))
+ {
+ handleDeleteData(event);
+ }
+
}
else
{
- // ignore the event.
+ //TODO: Ask Manik or EB about good ways to ignore the data. Just have souts? Perhaps log stuff.
}
}
@@ -46,11 +56,9 @@
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- new Work(dataMap.get(key), docId, WorkType.ADD);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), transactionContext);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE);
- );
-
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.ADD), transactionContext);
}
}
@@ -64,10 +72,8 @@
String keyString = (String) key;
String docId = Transformer.generateId(event.getFqn(), keyString);
- new Work(dataMap.get(key), docId, WorkType.DELETE);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId, WorkType.DELETE), transactionContext);
- //TODO: Add to queue.
-
}
}
16 years, 6 months
JBoss Cache SVN: r5986 - in pojo/trunk/src: main/java/org/jboss/cache/pojo/interceptors/dynamic and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-12 22:36:30 -0400 (Thu, 12 Jun 2008)
New Revision: 5986
Modified:
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedListInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedSetInterceptor.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedMapTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedSetTest.java
Log:
PCACHE-66 - Add support for serializable proxies
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -47,7 +47,7 @@
private static ClassProxy createProxy(Class clazz, AbstractCollectionInterceptor interceptor)
throws Exception
{
- ClassProxy result = ClassProxyFactory.newInstance(clazz);
+ ClassProxy result = ClassProxyFactory.newInstance(clazz, null, true);
InstanceAdvisor advisor = result._getInstanceAdvisor();
advisor.appendInterceptor(interceptor);
@@ -153,6 +153,14 @@
{
log.trace("invoke(): method intercepted " + method.getName());
}
+
+ if (writeReplaceInvocation(methodInvocation)) {
+ if (!skipVerify(methodInvocation.getMethod()))
+ interceptor.verifyAttached(impl);
+
+ return interceptor.getSerializationCopy();
+ }
+
Object[] args = methodInvocation.getArguments();
if (method != null)
{
@@ -193,4 +201,10 @@
return invocation.invokeNext();
}
+ private static boolean writeReplaceInvocation(MethodInvocation methodInvocation)
+ {
+ Method method = methodInvocation.getMethod();
+ return "writeReplace".equals(method.getName()) && method.getParameterTypes().length == 0;
+ }
+
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -97,8 +97,32 @@
throw new PojoCacheAlreadyDetachedException(identity + " has possibly been detached remotely. Internal id: " + fqn);
}
+ Object copyOrConstruct(Object mem)
+ {
+ if (mem instanceof Cloneable) {
+ try
+ {
+ return mem.getClass().getMethod("clone").invoke(mem);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ try
+ {
+ return mem.getClass().newInstance();
+ }
+ catch (Exception e)
+ {
+ }
+
+ return null;
+ }
+
abstract void setInMemoryCopy(Object obj);
abstract Object getInMemoryCopy();
+ public abstract Object getSerializationCopy();
abstract void setCacheCopy(Object obj);
abstract Object getCacheCopy();
abstract void setCurrentCopy(Object obj);
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedListInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedListInterceptor.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedListInterceptor.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -8,6 +8,7 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CachedListImpl;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
@@ -182,6 +183,32 @@
}
}
+ public Object getSerializationCopy()
+ {
+ if (current_ == inMemImpl_)
+ return inMemImpl_;
+
+ List list;
+ Object mem = inMemImpl_;
+ if (mem == null)
+ {
+ list = new ArrayList();
+ }
+ else
+ {
+ list = (List) copyOrConstruct(mem);
+ if (list == null)
+ throw new PojoCacheException("Could not serialize class, since it can not be copied: " + mem.getClass().getName());
+ }
+
+ list.clear();
+ int size = cacheImpl_.size();
+ for (int i = 0; i < size; i++)
+ list.add(cacheImpl_.get(i));
+
+ return list;
+ }
+
public String getName()
{
return "CachedListInterceptor";
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -8,12 +8,15 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CachedMapImpl;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
/**
@@ -165,6 +168,35 @@
}
}
+ public Object getSerializationCopy()
+ {
+ if (current_ == inMemImpl_)
+ return inMemImpl_;
+
+ Map map;
+ Object mem = inMemImpl_;
+ if (mem == null)
+ {
+ map = new HashMap();
+ }
+ else
+ {
+ map = (Map) copyOrConstruct(mem);
+ if (map == null)
+ throw new PojoCacheException("Could not serialize class, since it can not be copied: " + mem.getClass().getName());
+ }
+
+ map.clear();
+ Iterator it = cacheImpl_.keySet().iterator();
+ while (it.hasNext())
+ {
+ Object key = it.next();
+ Object val = cacheImpl_.get(key);
+ map.put(key, val);
+ }
+ return map;
+ }
+
public String getName()
{
return "CachedMapInterceptor";
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedSetInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedSetInterceptor.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedSetInterceptor.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -8,10 +8,12 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CachedSetImpl;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -159,7 +161,34 @@
}
}
+ public Object getSerializationCopy()
+ {
+ if (current_ == inMemImpl_)
+ return inMemImpl_;
+ Set set;
+ Object mem = inMemImpl_;
+ if (mem == null)
+ {
+ set = new HashSet();
+ }
+ else
+ {
+ set = (Set) copyOrConstruct(mem);
+ if (set == null)
+ throw new PojoCacheException("Could not serialize class, since it can not be copied: " + mem.getClass().getName());
+ }
+
+ set.clear();
+ Iterator it = cacheImpl_.iterator();
+ while (it.hasNext())
+ {
+ Object obj = it.next();
+ set.add(obj);
+ }
+ return set;
+ }
+
public String getName()
{
return "CachedSetInterceptor";
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListTest.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListTest.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -5,6 +5,10 @@
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -321,6 +325,27 @@
}
@SuppressWarnings("unchecked")
+ public void testSerialize() throws Exception
+ {
+ List<String> list = new ArrayList<String>();
+ list.add("English");
+ list.add("French");
+ list.add("Taiwanese");
+
+ cache_.attach("/test", list); // attach
+ list = (List<String>) cache_.find("/test");
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ out.writeObject(list);
+ List<String> newList = (List<String>)
+ (new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()))).readObject();
+
+ assertTrue(newList instanceof ArrayList);
+ assertEquals(list, newList);
+ }
+
+
+ @SuppressWarnings("unchecked")
public void testPojoAttachAndDetach() throws Exception
{
Address add1 = new Address();
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedMapTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedMapTest.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedMapTest.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -5,11 +5,17 @@
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -271,6 +277,26 @@
}
@SuppressWarnings("unchecked")
+ public void testSerialize() throws Exception
+ {
+ Map<Integer, String> map = new HashMap<Integer,String>();
+ map.put(1, "English");
+ map.put(2, "French");
+ map.put(3, "Taiwanese");
+
+ cache_.attach("/test", map); // attach
+ map = (Map<Integer, String>) cache_.find("/test");
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ out.writeObject(map);
+ Map<Integer, String> newMap = (Map<Integer, String>)
+ (new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()))).readObject();
+
+ assertTrue(newMap instanceof HashMap);
+ assertEquals(map, newMap);
+ }
+
+ @SuppressWarnings("unchecked")
public void testPojoAttachAndDetach() throws Exception
{
Address add1 = new Address();
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedSetTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedSetTest.java 2008-06-12 16:31:07 UTC (rev 5985)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedSetTest.java 2008-06-13 02:36:30 UTC (rev 5986)
@@ -5,6 +5,10 @@
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
@@ -35,7 +39,7 @@
*/
@Test(groups = {"functional"})
-public class CachedSetTest
+public class CachedSetTest
{
Log log = LogFactory.getLog(CachedSetTest.class);
PojoCache cache_;
@@ -126,7 +130,7 @@
return "" + i;
}
}
-
+
@SuppressWarnings("unchecked")
public void testConflictingHash() throws Exception
{
@@ -299,6 +303,26 @@
}
@SuppressWarnings("unchecked")
+ public void testSerialize() throws Exception
+ {
+ Set<String> set = new HashSet<String>();
+ set.add("English");
+ set.add("French");
+ set.add("Taiwanese");
+
+ cache_.attach("/test", set); // attach
+ set = (Set<String>) cache_.find("/test");
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ out.writeObject(set);
+ Set<String> newSet = (Set<String>)
+ (new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()))).readObject();
+
+ assertTrue(newSet instanceof HashSet);
+ assertEquals(set, newSet);
+ }
+
+ @SuppressWarnings("unchecked")
public void testPojoAttachAndDetach() throws Exception
{
Address add1 = new Address();
16 years, 6 months