Class AbstractCachingXmlProcessor<T>

java.lang.Object
org.openehealth.ipf.commons.xml.AbstractCachingXmlProcessor<T>
Type Parameters:
T - resource type.
Direct Known Subclasses:
XqjTransmogrifier, XsdValidator, XsltTransmogrifier

public abstract class AbstractCachingXmlProcessor<T> extends Object
Abstract parent class for XML validators, transmogrifiers, and other classes which cache static external resources in memory.
On the basis of validator/transmogrifier parameters (Object... params), instances of this class determine: The main method to get a ready-to-use resource instance is resource(Object...), which takes over instantiation, initialization, caching, and other aspects of resource lifecycle. For resource instantiation step, it calls the createResource(Object...) method, which is truly resource-type specific and thus declared as abstract in the given base class.
  • Field Details

  • Constructor Details

    • AbstractCachingXmlProcessor

      protected AbstractCachingXmlProcessor(ClassLoader classLoader)
      Constructor.
      Parameters:
      classLoader - class loader, may be null.
  • Method Details

    • getCache

      protected abstract ConcurrentMap<String,AbstractCachingXmlProcessor.Loader<T>> getCache()
      Returns:
      static cache for the configured resource type. Note that the returned Map is not necessarily synchronized.
    • resourceLocation

      protected String resourceLocation(Object... params)
      Extracts (constructs) resource location from validator/transmogrifier parameters.
      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      resource location as a String.
    • resourceCacheKey

      protected String resourceCacheKey(Object... params)
      Extracts (constructs) resource cache key validator/transmogrifier parameters.

      Per default, the key equals to the resource location.

      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      cache key as a String.
    • resourceParameters

      protected Map<String,Object> resourceParameters(Object... params)
      Extracts (constructs) resource creation/application parameters from validator/transmogrifier parameters.
      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      resource creation/application parameters as a Map, or null if not found.
    • resource

      protected T resource(Object... params) throws Exception
      Retrieves from the cache and returns the resource with the given location and further attributes. If necessary, creates the resource by means of createResource(Object...) and stores it into the cache. The cache key is a combination of the location and further attributes.

      This method MUST be re-entrant, its result MUST be thread-safe.

      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      resource instance.
      Throws:
      Exception
    • createResource

      protected abstract T createResource(Object... params)
      Creates a ready-to-use resource (e.g. an XML Schema instance) for the given key. Insertion into the cache will happen externally, this method's purpose is only to instantiate the resource to be cached.

      This method does not need to be re-entrant, but its result MUST be thread-safe.

      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      resource of the configured type.
    • resourceContent

      protected StreamSource resourceContent(Object... params)
      Loads the resource into memory and returns it as a Stream.

      This method does not need to be re-entrant.

      Parameters:
      params - validator/transmogrifier parameters.
      Returns:
      resource of the configured type.