Package org.ehcache.xml
Class XmlConfiguration
java.lang.Object
org.ehcache.xml.XmlConfiguration
- All Implemented Interfaces:
org.ehcache.config.Configuration
Exposes
Configuration and CacheConfigurationBuilder expressed
in a XML file that obeys the core Ehcache schema.
Instances of this class are not thread-safe.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXmlConfiguration(URL url) Constructs an instance of XmlConfiguration mapping to the XML file located aturl.XmlConfiguration(URL url, ClassLoader classLoader) Constructs an instance of XmlConfiguration mapping to the XML file located aturland using the providedclassLoaderto load user types (e.g.XmlConfiguration(URL url, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) Constructs an instance of XmlConfiguration mapping to the XML file located aturland using the providedclassLoaderto load user types (e.g.XmlConfiguration(org.ehcache.config.Configuration configuration) Constructs an instance of XmlConfiguration from an existing configuration object.XmlConfiguration(Document xml) Constructs an instance of XmlConfiguration from the given XML DOM.XmlConfiguration(Document xml, ClassLoader classLoader) Constructs an instance of XmlConfiguration from the given XML DOM and using the providedclassLoaderto load user types (e.g.XmlConfiguration(Document xml, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) Constructs an instance of XmlConfiguration from the given XML DOM and using the providedclassLoaderto load user types (e.g. -
Method Summary
Modifier and TypeMethodDescriptionReturn this configuration as an XMLDocument.Return this configuration as a rendered XML string.org.ehcache.config.FluentConfigurationBuilder<?>derive()static Class<?>getClassForName(String name, ClassLoader classLoader) Collection<org.ehcache.spi.service.ServiceCreationConfiguration<?,?>> org.ehcache.config.ResourcePoolsgetURL()Exposes the URL where the XML file parsed or yet to be parsed was or will be sourced from.<K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K, V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType) Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.<K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K, V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType, org.ehcache.config.Builder<? extends org.ehcache.config.ResourcePools> resourcePoolsBuilder) Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.<K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K, V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType, org.ehcache.config.ResourcePools resourcePools) Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.toString()
-
Field Details
-
CORE_SCHEMA_URL
-
-
Constructor Details
-
XmlConfiguration
Constructs an instance of XmlConfiguration mapping to the XML file located aturl.The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that loaded the Ehcache classes.
- Parameters:
url- URL pointing to the XML file's location- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
public XmlConfiguration(URL url, ClassLoader classLoader) throws org.ehcache.xml.exceptions.XmlConfigurationException Constructs an instance of XmlConfiguration mapping to the XML file located aturland using the providedclassLoaderto load user types (e.g. key and value Class instances).- Parameters:
url- URL pointing to the XML file's locationclassLoader- ClassLoader to use to load user types.- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
public XmlConfiguration(URL url, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) throws org.ehcache.xml.exceptions.XmlConfigurationExceptionConstructs an instance of XmlConfiguration mapping to the XML file located aturland using the providedclassLoaderto load user types (e.g. key and value Class instances). ThecacheClassLoaderswill let you specify a differentClassLoaderto use for eachCachemanaged by theCacheManagerconfigured using thisXmlConfiguration. Caches with aliases that do not appear in the map will useclassLoaderas a default.- Parameters:
url- URL pointing to the XML file's locationclassLoader- ClassLoader to use to load user types.cacheClassLoaders- the map with mappings between cache names and the corresponding class loaders- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
Constructs an instance of XmlConfiguration from the given XML DOM.The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that loaded the Ehcache classes.
- Parameters:
xml- XML Document Object Model- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
public XmlConfiguration(Document xml, ClassLoader classLoader) throws org.ehcache.xml.exceptions.XmlConfigurationException Constructs an instance of XmlConfiguration from the given XML DOM and using the providedclassLoaderto load user types (e.g. key and value Class instances).- Parameters:
xml- XML Document Object ModelclassLoader- ClassLoader to use to load user types.- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
public XmlConfiguration(Document xml, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) throws org.ehcache.xml.exceptions.XmlConfigurationExceptionConstructs an instance of XmlConfiguration from the given XML DOM and using the providedclassLoaderto load user types (e.g. key and value Class instances). ThecacheClassLoaderswill let you specify a differentClassLoaderto use for eachCachemanaged by theCacheManagerconfigured using thisXmlConfiguration. Caches with aliases that do not appear in the map will useclassLoaderas a default.- Parameters:
xml- XML Document Object ModelclassLoader- ClassLoader to use to load user types.cacheClassLoaders- the map with mappings between cache names and the corresponding class loaders- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong parsing the XML
-
XmlConfiguration
public XmlConfiguration(org.ehcache.config.Configuration configuration) throws org.ehcache.xml.exceptions.XmlConfigurationException Constructs an instance of XmlConfiguration from an existing configuration object.- Parameters:
configuration- existing configuration- Throws:
org.ehcache.xml.exceptions.XmlConfigurationException- if anything went wrong converting to XML
-
-
Method Details
-
asDocument
Return this configuration as an XMLDocument.- Returns:
- configuration XML DOM.
-
asRenderedDocument
Return this configuration as a rendered XML string.- Returns:
- configuration XML string
-
toString
-
getURL
Exposes the URL where the XML file parsed or yet to be parsed was or will be sourced from.- Returns:
- The URL provided at object instantiation
-
newCacheConfigurationBuilderFromTemplate
public <K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType) throws ReflectiveOperationException Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.Note that this version does not specify resources, which are mandatory to create a
CacheConfigurationBuilder. So if the template does not define resources, this will throw.- Type Parameters:
K- type of keysV- type of values- Parameters:
name- the unique name identifying the cache-template element in the XMLkeyType- the type of keys for theCacheConfigurationBuilderto use, must match thekey-typedeclared in the template if declared in XMLvalueType- the type of values for theCacheConfigurationBuilderto use, must match thevalue-typedeclared in the template if declared in XML- Returns:
- the preconfigured
CacheConfigurationBuilderornullif no cache-template for the providedname - Throws:
IllegalStateException- if the template does not configure resources.IllegalArgumentException- ifkeyTypeorvalueTypedon't match the declared type(s) of the templateReflectiveOperationException- if aClassdeclared in the XML couldn't be found, or if a user providedClasscouldn't get instantiated, or if a method (including constructor) couldn't be invoked on a user provided type
-
newCacheConfigurationBuilderFromTemplate
public <K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType, org.ehcache.config.ResourcePools resourcePools) throws ReflectiveOperationException Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.- Type Parameters:
K- type of keysV- type of values- Parameters:
name- the unique name identifying the cache-template element in the XMLkeyType- the type of keys for theCacheConfigurationBuilderto use, must match thekey-typedeclared in the template if declared in XMLvalueType- the type of values for theCacheConfigurationBuilderto use, must match thevalue-typedeclared in the template if declared in XMLresourcePools- Resources definitions that will be used- Returns:
- the preconfigured
CacheConfigurationBuilderornullif no cache-template for the providedname - Throws:
IllegalArgumentException- ifkeyTypeorvalueTypedon't match the declared type(s) of the templateReflectiveOperationException- if aClassdeclared in the XML couldn't be found, or if a user providedClasscouldn't get instantiated, or if a method (including constructor) couldn't be invoked on a user provided type
-
newCacheConfigurationBuilderFromTemplate
public <K,V> org.ehcache.config.builders.CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(String name, Class<K> keyType, Class<V> valueType, org.ehcache.config.Builder<? extends org.ehcache.config.ResourcePools> resourcePoolsBuilder) throws ReflectiveOperationException Creates a newCacheConfigurationBuilderseeded with the cache-template configuration by the givennamein the parsed XML configuration.- Type Parameters:
K- type of keysV- type of values- Parameters:
name- the unique name identifying the cache-template element in the XMLkeyType- the type of keys for theCacheConfigurationBuilderto use, must match thekey-typedeclared in the template if declared in XMLvalueType- the type of values for theCacheConfigurationBuilderto use, must match thevalue-typedeclared in the template if declared in XMLresourcePoolsBuilder- Resources definitions that will be used- Returns:
- the preconfigured
CacheConfigurationBuilderornullif no cache-template for the providedname - Throws:
IllegalArgumentException- ifkeyTypeorvalueTypedon't match the declared type(s) of the templateReflectiveOperationException- if aClassdeclared in the XML couldn't be found, or if a user providedClasscouldn't get instantiated, or if a method (including constructor) couldn't be invoked on a user provided type
-
getCacheConfigurations
- Specified by:
getCacheConfigurationsin interfaceorg.ehcache.config.Configuration
-
getServiceCreationConfigurations
public Collection<org.ehcache.spi.service.ServiceCreationConfiguration<?,?>> getServiceCreationConfigurations()- Specified by:
getServiceCreationConfigurationsin interfaceorg.ehcache.config.Configuration
-
getClassLoader
- Specified by:
getClassLoaderin interfaceorg.ehcache.config.Configuration
-
derive
public org.ehcache.config.FluentConfigurationBuilder<?> derive()- Specified by:
derivein interfaceorg.ehcache.config.Configuration
-
getClassForName
public static Class<?> getClassForName(String name, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-