Class XmlConfiguration

java.lang.Object
org.ehcache.xml.XmlConfiguration
All Implemented Interfaces:
org.ehcache.config.Configuration

public class XmlConfiguration extends Object implements 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.

  • Field Details

    • CORE_SCHEMA_URL

      public static final URL CORE_SCHEMA_URL
  • Constructor Details

    • XmlConfiguration

      public XmlConfiguration(URL url) throws org.ehcache.xml.exceptions.XmlConfigurationException
      Constructs an instance of XmlConfiguration mapping to the XML file located at url.

      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 at url and using the provided classLoader to load user types (e.g. key and value Class instances).
      Parameters:
      url - URL pointing to the XML file's location
      classLoader - 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.XmlConfigurationException
      Constructs an instance of XmlConfiguration mapping to the XML file located at 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.
      Parameters:
      url - URL pointing to the XML file's location
      classLoader - 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(Document xml) throws org.ehcache.xml.exceptions.XmlConfigurationException
      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 provided classLoader to load user types (e.g. key and value Class instances).
      Parameters:
      xml - XML Document Object Model
      classLoader - 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.XmlConfigurationException
      Constructs an instance of XmlConfiguration from the given XML DOM 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.
      Parameters:
      xml - XML Document Object Model
      classLoader - 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

      public Document asDocument()
      Return this configuration as an XML Document.
      Returns:
      configuration XML DOM.
    • asRenderedDocument

      public String asRenderedDocument()
      Return this configuration as a rendered XML string.
      Returns:
      configuration XML string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getURL

      public URL 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 new 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.

      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      name - the unique name identifying the cache-template element in the XML
      keyType - the type of keys for the CacheConfigurationBuilder to use, must match the key-type declared in the template if declared in XML
      valueType - the type of values for the CacheConfigurationBuilder to use, must match the value-type declared in the template if declared in XML
      Returns:
      the preconfigured CacheConfigurationBuilder or null if no cache-template for the provided name
      Throws:
      IllegalStateException - if the template does not configure resources.
      IllegalArgumentException - if keyType or valueType don't match the declared type(s) of the template
      ReflectiveOperationException - if a Class declared in the XML couldn't be found, or if a user provided Class couldn'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 new CacheConfigurationBuilder seeded with the cache-template configuration by the given name in the parsed XML configuration.
      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      name - the unique name identifying the cache-template element in the XML
      keyType - the type of keys for the CacheConfigurationBuilder to use, must match the key-type declared in the template if declared in XML
      valueType - the type of values for the CacheConfigurationBuilder to use, must match the value-type declared in the template if declared in XML
      resourcePools - Resources definitions that will be used
      Returns:
      the preconfigured CacheConfigurationBuilder or null if no cache-template for the provided name
      Throws:
      IllegalArgumentException - if keyType or valueType don't match the declared type(s) of the template
      ReflectiveOperationException - if a Class declared in the XML couldn't be found, or if a user provided Class couldn'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 new CacheConfigurationBuilder seeded with the cache-template configuration by the given name in the parsed XML configuration.
      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      name - the unique name identifying the cache-template element in the XML
      keyType - the type of keys for the CacheConfigurationBuilder to use, must match the key-type declared in the template if declared in XML
      valueType - the type of values for the CacheConfigurationBuilder to use, must match the value-type declared in the template if declared in XML
      resourcePoolsBuilder - Resources definitions that will be used
      Returns:
      the preconfigured CacheConfigurationBuilder or null if no cache-template for the provided name
      Throws:
      IllegalArgumentException - if keyType or valueType don't match the declared type(s) of the template
      ReflectiveOperationException - if a Class declared in the XML couldn't be found, or if a user provided Class couldn't get instantiated, or if a method (including constructor) couldn't be invoked on a user provided type
    • getCacheConfigurations

      public Map<String,org.ehcache.config.CacheConfiguration<?,?>> getCacheConfigurations()
      Specified by:
      getCacheConfigurations in interface org.ehcache.config.Configuration
    • getServiceCreationConfigurations

      public Collection<org.ehcache.spi.service.ServiceCreationConfiguration<?,?>> getServiceCreationConfigurations()
      Specified by:
      getServiceCreationConfigurations in interface org.ehcache.config.Configuration
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface org.ehcache.config.Configuration
    • getSharedResourcePools

      public org.ehcache.config.ResourcePools getSharedResourcePools()
      Specified by:
      getSharedResourcePools in interface org.ehcache.config.Configuration
    • derive

      public org.ehcache.config.FluentConfigurationBuilder<?> derive()
      Specified by:
      derive in interface org.ehcache.config.Configuration
    • getClassForName

      public static Class<?> getClassForName(String name, ClassLoader classLoader) throws ClassNotFoundException
      Throws:
      ClassNotFoundException