public class XmlConfiguration extends java.lang.Object implements Configuration
Configuration
and CacheConfigurationBuilder
expressed
in a XML file that obeys the core Ehcache schema.
Instances of this class are not thread-safe.
Modifier and Type | Class and Description |
---|---|
static interface |
XmlConfiguration.Template |
Modifier and Type | Field and Description |
---|---|
static java.net.URL |
CORE_SCHEMA_URL |
Constructor and Description |
---|
XmlConfiguration(Configuration configuration)
Constructs an instance of XmlConfiguration from an existing configuration object.
|
XmlConfiguration(org.w3c.dom.Document xml)
Constructs an instance of XmlConfiguration from the given XML DOM.
|
XmlConfiguration(org.w3c.dom.Document xml,
java.lang.ClassLoader classLoader)
Constructs an instance of XmlConfiguration from the given XML DOM and using the provided
classLoader to
load user types (e.g. |
XmlConfiguration(org.w3c.dom.Document xml,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,java.lang.ClassLoader> cacheClassLoaders)
Constructs an instance of XmlConfiguration from the given XML DOM and using the provided
classLoader to
load user types (e.g. |
XmlConfiguration(java.net.URL url)
Constructs an instance of XmlConfiguration mapping to the XML file located at
url . |
XmlConfiguration(java.net.URL url,
java.lang.ClassLoader classLoader)
Constructs an instance of XmlConfiguration mapping to the XML file located at
url and using the provided
classLoader to load user types (e.g. |
XmlConfiguration(java.net.URL url,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,java.lang.ClassLoader> cacheClassLoaders)
Constructs an instance of XmlConfiguration mapping to the XML file located at
url and using the provided
classLoader to load user types (e.g. |
Modifier and Type | Method and Description |
---|---|
org.w3c.dom.Document |
asDocument()
Return this configuration as an XML
Document . |
java.lang.String |
asRenderedDocument()
Return this configuration as a rendered XML string.
|
FluentConfigurationBuilder<?> |
derive()
Creates a builder seeded with this configuration.
|
java.util.Map<java.lang.String,CacheConfiguration<?,?>> |
getCacheConfigurations()
Mapping of aliases to
CacheConfiguration s, used to configure the Cache s
managed by the CacheManager . |
static java.lang.Class<?> |
getClassForName(java.lang.String name,
java.lang.ClassLoader classLoader) |
java.lang.ClassLoader |
getClassLoader()
The
ClassLoader for the CacheManager . |
java.util.Collection<ServiceCreationConfiguration<?,?>> |
getServiceCreationConfigurations()
|
java.net.URL |
getURL()
Exposes the URL where the XML file parsed or yet to be parsed was or will be sourced from.
|
<K,V> CacheConfigurationBuilder<K,V> |
newCacheConfigurationBuilderFromTemplate(java.lang.String name,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType)
Creates a new
CacheConfigurationBuilder seeded with the cache-template configuration
by the given name in the parsed XML configuration. |
<K,V> CacheConfigurationBuilder<K,V> |
newCacheConfigurationBuilderFromTemplate(java.lang.String name,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType,
Builder<? extends ResourcePools> resourcePoolsBuilder)
Creates a new
CacheConfigurationBuilder seeded with the cache-template configuration
by the given name in the parsed XML configuration. |
<K,V> CacheConfigurationBuilder<K,V> |
newCacheConfigurationBuilderFromTemplate(java.lang.String name,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType,
ResourcePools resourcePools)
Creates a new
CacheConfigurationBuilder seeded with the cache-template configuration
by the given name in the parsed XML configuration. |
java.lang.String |
toString() |
public XmlConfiguration(java.net.URL url) throws org.ehcache.xml.exceptions.XmlConfigurationException
url
.
The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that loaded the Ehcache classes.
url
- URL pointing to the XML file's locationorg.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(java.net.URL url, java.lang.ClassLoader classLoader) throws org.ehcache.xml.exceptions.XmlConfigurationException
url
and using the provided
classLoader
to load user types (e.g. key and value Class instances).url
- URL pointing to the XML file's locationclassLoader
- ClassLoader to use to load user types.org.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(java.net.URL url, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.ClassLoader> cacheClassLoaders) throws org.ehcache.xml.exceptions.XmlConfigurationException
url
and using the provided
classLoader
to load user types (e.g. key and value Class instances). The cacheClassLoaders
will
let you specify a different ClassLoader
to use for each Cache
managed by
the CacheManager
configured using this XmlConfiguration
. Caches with
aliases that do not appear in the map will use classLoader
as a default.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 loadersorg.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(org.w3c.dom.Document xml) throws org.ehcache.xml.exceptions.XmlConfigurationException
The default ClassLoader will first try to use the thread context class loader, followed by the ClassLoader that loaded the Ehcache classes.
xml
- XML Document Object Modelorg.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(org.w3c.dom.Document xml, java.lang.ClassLoader classLoader) throws org.ehcache.xml.exceptions.XmlConfigurationException
classLoader
to
load user types (e.g. key and value Class instances).xml
- XML Document Object ModelclassLoader
- ClassLoader to use to load user types.org.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(org.w3c.dom.Document xml, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.ClassLoader> cacheClassLoaders) throws org.ehcache.xml.exceptions.XmlConfigurationException
classLoader
to
load user types (e.g. key and value Class instances). The cacheClassLoaders
will let you specify a
different ClassLoader
to use for each Cache
managed by the
CacheManager
configured using this XmlConfiguration
. Caches with
aliases that do not appear in the map will use classLoader
as a default.xml
- XML Document Object ModelclassLoader
- ClassLoader to use to load user types.cacheClassLoaders
- the map with mappings between cache names and the corresponding class loadersorg.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong parsing the XMLpublic XmlConfiguration(Configuration configuration) throws org.ehcache.xml.exceptions.XmlConfigurationException
configuration
- existing configurationorg.ehcache.xml.exceptions.XmlConfigurationException
- if anything went wrong converting to XMLpublic org.w3c.dom.Document asDocument()
Document
.public java.lang.String asRenderedDocument()
public java.lang.String toString()
toString
in class java.lang.Object
public java.net.URL getURL()
public <K,V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(java.lang.String name, java.lang.Class<K> keyType, java.lang.Class<V> valueType) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
CacheConfigurationBuilder
seeded with the cache-template configuration
by the given name
in 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.
K
- type of keysV
- type of valuesname
- the unique name identifying the cache-template element in the XMLkeyType
- the type of keys for the CacheConfigurationBuilder
to use, must
match the key-type
declared in the template if declared in XMLvalueType
- the type of values for the CacheConfigurationBuilder
to use, must
match the value-type
declared in the template if declared in XMLCacheConfigurationBuilder
or null
if no cache-template for the provided name
java.lang.IllegalStateException
- if the template does not configure resources.java.lang.IllegalArgumentException
- if keyType
or valueType
don't match the declared type(s) of the templatejava.lang.ClassNotFoundException
- if a Class
declared in the XML couldn't be foundjava.lang.InstantiationException
- if a user provided Class
couldn't get instantiatedjava.lang.IllegalAccessException
- if a method (including constructor) couldn't be invoked on a user provided typepublic <K,V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(java.lang.String name, java.lang.Class<K> keyType, java.lang.Class<V> valueType, ResourcePools resourcePools) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
CacheConfigurationBuilder
seeded with the cache-template configuration
by the given name
in the parsed XML configuration.K
- type of keysV
- type of valuesname
- the unique name identifying the cache-template element in the XMLkeyType
- the type of keys for the CacheConfigurationBuilder
to use, must
match the key-type
declared in the template if declared in XMLvalueType
- the type of values for the CacheConfigurationBuilder
to use, must
match the value-type
declared in the template if declared in XMLresourcePools
- Resources definitions that will be usedCacheConfigurationBuilder
or null
if no cache-template for the provided name
java.lang.IllegalArgumentException
- if keyType
or valueType
don't match the declared type(s) of the templatejava.lang.ClassNotFoundException
- if a Class
declared in the XML couldn't be foundjava.lang.InstantiationException
- if a user provided Class
couldn't get instantiatedjava.lang.IllegalAccessException
- if a method (including constructor) couldn't be invoked on a user provided typepublic <K,V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilderFromTemplate(java.lang.String name, java.lang.Class<K> keyType, java.lang.Class<V> valueType, Builder<? extends ResourcePools> resourcePoolsBuilder) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
CacheConfigurationBuilder
seeded with the cache-template configuration
by the given name
in the parsed XML configuration.K
- type of keysV
- type of valuesname
- the unique name identifying the cache-template element in the XMLkeyType
- the type of keys for the CacheConfigurationBuilder
to use, must
match the key-type
declared in the template if declared in XMLvalueType
- the type of values for the CacheConfigurationBuilder
to use, must
match the value-type
declared in the template if declared in XMLresourcePoolsBuilder
- Resources definitions that will be usedCacheConfigurationBuilder
or null
if no cache-template for the provided name
java.lang.IllegalArgumentException
- if keyType
or valueType
don't match the declared type(s) of the templatejava.lang.ClassNotFoundException
- if a Class
declared in the XML couldn't be foundjava.lang.InstantiationException
- if a user provided Class
couldn't get instantiatedjava.lang.IllegalAccessException
- if a method (including constructor) couldn't be invoked on a user provided typepublic java.util.Map<java.lang.String,CacheConfiguration<?,?>> getCacheConfigurations()
Configuration
CacheConfiguration
s, used to configure the Cache
s
managed by the CacheManager
.
The map must not be null
but can be empty. It must be unmodifiable.
getCacheConfigurations
in interface Configuration
public java.util.Collection<ServiceCreationConfiguration<?,?>> getServiceCreationConfigurations()
Configuration
ServiceCreationConfiguration
initially used to bootstrap the CacheManager
and its Cache
s.
The collection must not be null but can be empty. Also it must be unmodifiable.
getServiceCreationConfigurations
in interface Configuration
public java.lang.ClassLoader getClassLoader()
Configuration
ClassLoader
for the CacheManager
.
This ClassLoader
will be used to instantiate cache manager level services
and for Cache
s that do not have a specific ClassLoader
.
The ClassLoader
must not be null.
getClassLoader
in interface Configuration
ClassLoader
public FluentConfigurationBuilder<?> derive()
Configuration
The default implementation throws UnsupportedOperationException
to indicate that configuration derivation
is not supported.
derive
in interface Configuration
FluentConfigurationBuilder
public static java.lang.Class<?> getClassForName(java.lang.String name, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException