Package org.openehealth.ipf.commons.xml
Class AbstractCachingXmlProcessor<T>
java.lang.Object
org.openehealth.ipf.commons.xml.AbstractCachingXmlProcessor<T>
- Type Parameters:
T
- resource type.
- Direct Known Subclasses:
XqjTransmogrifier
,XsdValidator
,XsltTransmogrifier
Abstract parent class for XML validators, transmogrifiers, and other classes
which cache static external resources in memory.
On the basis of validator/transmogrifier parameters (
On the basis of validator/transmogrifier parameters (
Object... params
),
instances of this class determine:
- Location of the raw resource (i.e. an unparsed XSLT document as opposed
to its compiled representation in memory) — method
resourceLocation(Object...)
, - Parameters of resource instantiation (compilation) and execution (application) —
method
resourceParameters(Object...)
, - Key to store the compiled resource in the cache —
method
resourceCacheKey(Object...)
.
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.-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractCachingXmlProcessor
(ClassLoader classLoader) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract T
createResource
(Object... params) Creates a ready-to-use resource (e.g.protected abstract ConcurrentMap<String,
AbstractCachingXmlProcessor.Loader<T>> getCache()
protected T
Retrieves from the cache and returns the resource with the given location and further attributes.protected String
resourceCacheKey
(Object... params) Extracts (constructs) resource cache key validator/transmogrifier parameters.protected StreamSource
resourceContent
(Object... params) Loads the resource into memory and returns it as a Stream.protected String
resourceLocation
(Object... params) Extracts (constructs) resource location from validator/transmogrifier parameters.resourceParameters
(Object... params) Extracts (constructs) resource creation/application parameters from validator/transmogrifier parameters.
-
Field Details
-
RESOURCE_LOCATION
- See Also:
-
-
Constructor Details
-
AbstractCachingXmlProcessor
Constructor.- Parameters:
classLoader
- class loader, may benull
.
-
-
Method Details
-
getCache
- Returns:
- static cache for the configured resource type. Note that the returned Map is not necessarily synchronized.
-
resourceLocation
Extracts (constructs) resource location from validator/transmogrifier parameters.- Parameters:
params
- validator/transmogrifier parameters.- Returns:
- resource location as a String.
-
resourceCacheKey
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
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
Retrieves from the cache and returns the resource with the given location and further attributes. If necessary, creates the resource by means ofcreateResource(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
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
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.
-