Interface ProcessingContext
- All Superinterfaces:
ResourceResolver
- All Known Implementing Classes:
DefaultProcessingContext
ProcessingContext
provides contextual information concerning the processing of content in an xml document.
ProcessingContext
s additionally provide mechanisms to:
- Request processing of other, typically sub xml content, like child
XmlElement
s. - Access the
ResourceRegistry
provided to theDocumentProcessor
associated with theXmlDocument
being processed. - Access the
ParameterResolver
provided to theDocumentProcessor
associated with theXmlDocument
being processed. - Define additional contextual state (such as cookies) that may be used for injecting values into beans during processing.
- Define specialized
ElementProcessor
s andAttributeProcessor
s that may be used for processing and injecting beans in theProcessingContext
.
- Since:
- Coherence 12.1.2
- Author:
- bo 2011.06.15
-
Method Summary
Modifier and TypeMethodDescription<T> void
Adds the specified named and typed cookie to theProcessingContext
.<T> void
Adds the specified cookie to theProcessingContext
.void
definePropertyPath
(String sBeanPropertyName, String sXmlPath) Defines the xml path to locate a specific Java Bean property with in anXmlElement
in theProcessingContext
.ensureNamespaceHandler
(String sPrefix, NamespaceHandler handler) Ensures that the specifiedNamespaceHandler
for the specified prefix is defined in thisProcessingContext
.ensureNamespaceHandler
(String sPrefix, URI uri) Ensures that anNamespaceHandler
with the specifiedURI
is available for use in theProcessingContext
with the specified prefix.Obtains theClassLoader
to use for loading classes in theProcessingContext
.<T> T
Locates and returns the cookie with the specified type.<T> T
Locates and returns the cookie with the specified type and name.Obtains theParameterResolver
to use for resolving parameters defined externally to the document being processed (ie: the operating system or container)Obtains the configuredExpressionParser
for thisProcessingContext
.<T> T
getMandatoryProperty
(String sPath, Type typeProperty, XmlElement xmlElement) Obtains the strongly typed value for the property defined at the path relative to the specifiedXmlElement
.getNamespaceHandler
(String sPrefix) Obtains theNamespaceHandler
which is capable of processing the namespace with the specified prefix.getNamespaceHandler
(URI uri) Obtains theNamespaceHandler
that is capable of processing the namespace defined with the specifiedURI
.Obtains theNamespaceHandler
s that are currently in scope for thisProcessingContext
.getNamespaceURI
(String sPrefix) Obtains theURI
that is associated with the specified prefix.<T> T
getOptionalProperty
(String sPath, Type typeProperty, T defaultValue, XmlElement xmlElement) Obtains the strongly typed value for the property defined at the path relative to the specifiedXmlElement
.Obtains theResourceRegistry
associated with theProcessingContext
.<B> B
inject
(B bean, XmlElement xmlElement) Given the information available in theProcessingContext
, including the cookies, theResourceRegistry
theXmlElement
, itsXmlAttribute
s and/or children, inject appropriately named and typed values into the specified bean (using setter injection).boolean
isPropertyDefined
(String sPath, XmlElement xmlElement) Determines if the specified property is defined at the path relative to the specifiedXmlElement
.void
loadNamespaceHandlers
(XmlElement xmlElement) Load all the customNamespaceHandler
instances for the specifiedXmlElement
.processDocument
(XmlElement xmlElement) Request that the specifiedXmlElement
(representing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.processDocument
(String sXml) Request that the specified xml string (representing an xml document) be processed with appropriateNamespaceHandler
s.processDocumentAt
(String sLocation) Request that the document specified by the URI/filename (containing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.processDocumentAt
(URI uri) Request that the document specified by the URI/filename (containing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.processElement
(XmlElement xmlElement) Request the specifiedXmlElement
to be processed with an appropriateNamespaceHandler
known by theProcessingContext
or outerProcessingContext
s.processElement
(String sXml) Request the specified xml string be processed with an appropriateNamespaceHandler
known by theProcessingContext
.processElementsOf
(XmlElement xmlElement) Request that all of the child elements contained with in the specifiedXmlElement
be processed using appropriateNamespaceHandler
s known by theProcessingContext
.processForeignElementsOf
(XmlElement xmlElement) Request that all of the child elements contained within the specifiedXmlElement
that do not belong to the namespace of the saidXmlElement
are processed using appropriate processes.<T> T
processOnlyElementOf
(XmlElement xmlElement) Request that the only child element contained within theXmlElement
is processed using an appropriateNamespaceHandler
known by theProcessingContext
.<T> T
processRemainingElementOf
(XmlElement xmlElement) Request that the last remaining unprocessed child element contained within the specifiedXmlElement
is processed using an appropriateElementProcessor
.processRemainingElementsOf
(XmlElement xmlElement) Request that the last remaining unprocessed children contained within the specifiedXmlElement
are processed using appropriateElementProcessor
s.<T> void
registerAttributeType
(Class<T> clzType) Automatically creates and registers anAttributeProcessor
for the specified type.<T> void
registerElementType
(Class<T> clzType) Automatically creates and registers anElementProcessor
for the specified type.<T> void
registerProcessor
(Class<T> clzType, AttributeProcessor<T> processor) Registers anAttributeProcessor
that may be used to process specific types of values contained inXmlAttribute
s with in theProcessingContext
.<T> void
registerProcessor
(Class<T> clzType, ElementProcessor<T> processor) Registers anElementProcessor
that may be used to process specific types of values contained inXmlElement
s with in theProcessingContext
.Methods inherited from interface com.tangosol.util.ResourceResolver
getResource, getResource
-
Method Details
-
getResourceRegistry
ResourceRegistry getResourceRegistry()Obtains theResourceRegistry
associated with theProcessingContext
.- Returns:
- a
ResourceRegistry
-
getContextClassLoader
ClassLoader getContextClassLoader()Obtains theClassLoader
to use for loading classes in theProcessingContext
.- Returns:
ClassLoader
-
getDefaultParameterResolver
ParameterResolver getDefaultParameterResolver()Obtains theParameterResolver
to use for resolving parameters defined externally to the document being processed (ie: the operating system or container)- Returns:
- the default
ParameterResolver
.
-
addCookie
Adds the specified named and typed cookie to theProcessingContext
.If a cookie with the same name and type exists in the
ProcessingContext
, it will be replaced by the specified cookie. If a cookie with the same name and type has been defined in an outerProcessingContext
, the specified cookie will hide the cookie defined in the outerProcessingContext
.- Type Parameters:
T
- the type of the cookie- Parameters:
clzCookie
- the class of the cookiesCookieName
- the name of the cookiecookie
- the cookie value
-
addCookie
Adds the specified cookie to theProcessingContext
.If a cookie of the same type and name (being the name of the class of the said cookie) is already registered with the
ProcessingContext
, it will be replaced by the specified cookie.If a cookie of the same type and name has been defined in an outer
ProcessingContext
, the specified cookie will hide the cookie defined in the outerProcessingContext
.This method is equivalent to calling:
addCookie(clz, clz.getName(), cookie);
- Type Parameters:
T
- the type of the cookie- Parameters:
clzCookie
- the class of the cookiecookie
- the cookie value
-
getCookie
Locates and returns the cookie with the specified type and name.Locating the cookie involves searching the current
ProcessingContext
for a matching cookie. If one is not found, the search continues with outerProcessingContext
s until a cookie is either located or there are no moreProcessingContext
s, in which casenull
is returned.- Type Parameters:
T
- the type of the cookie- Parameters:
clzCookie
- the class of the cookiesCookieName
- the name of the cookie- Returns:
- the cookie or
null
if not defined
-
getCookie
Locates and returns the cookie with the specified type.Locating the cookie involves searching the current
ProcessingContext
for a matching cookie. If one is not found, the search continues with outerProcessingContext
s until a cookie is either located or there are no moreProcessingContext
s, in which casenull
is returned.This method is equivalent to calling:
getCookie(clz, clz.getName());
- Type Parameters:
T
- the type of the cookie- Parameters:
clzCookie
- the class of the cookie- Returns:
- the cookie or
null
if not defined
-
definePropertyPath
Defines the xml path to locate a specific Java Bean property with in anXmlElement
in theProcessingContext
.This method allows "alias" paths for Java Bean properties to be defined so that
inject(Object, XmlElement)
calls may resolve property values correctly.This is an advanced feature. Typically this is only used when:
- A Java Bean property name does not match a named value,
XmlElement
orXmlAttribute
with in aProcessingContext
. - A Java Bean property can not be located with in the
ProcessingContext
.
- Parameters:
sBeanPropertyName
- the property name of the beansXmlPath
- the xmlPath to the property value
- A Java Bean property name does not match a named value,
-
registerProcessor
Registers anAttributeProcessor
that may be used to process specific types of values contained inXmlAttribute
s with in theProcessingContext
.When an
AttributeProcessor
isn't provided by the associatedNamespaceHandler
for anXmlAttribute
, an attempt is made to use a type specificAttributeProcessor
to process anXmlAttribute
for injection (withinject(Object, XmlElement)
).- Type Parameters:
T
- the type- Parameters:
clzType
- theClass
typeprocessor
- theAttributeProcessor
for the type
-
registerProcessor
Registers anElementProcessor
that may be used to process specific types of values contained inXmlElement
s with in theProcessingContext
.When an
ElementProcessor
isn't provided by the associatedNamespaceHandler
for anXmlElement
, an attempt is made to use a type specificElementProcessor
to process anXmlElement
for injection (withinject(Object, XmlElement)
).- Type Parameters:
T
- the type- Parameters:
clzType
- theClass
typeprocessor
- theElementProcessor
for the type
-
registerAttributeType
Automatically creates and registers anAttributeProcessor
for the specified type.Note: This assumes the type supports a
String
-based orXmlAttribute
-based constructor.- Type Parameters:
T
- the type- Parameters:
clzType
- the type for which to create and register anAttributeProcessor
-
registerElementType
Automatically creates and registers anElementProcessor
for the specified type.Note: This assumes the type supports a
String
-based orXmlElement
-based constructor.- Type Parameters:
T
- the type- Parameters:
clzType
- the type for which to create and register anElementProcessor
-
getExpressionParser
ExpressionParser getExpressionParser()Obtains the configuredExpressionParser
for thisProcessingContext
.- Returns:
- the
ExpressionParser
-
ensureNamespaceHandler
Ensures that anNamespaceHandler
with the specifiedURI
is available for use in theProcessingContext
with the specified prefix. If aNamespaceHandler
with the specified prefix andURI
is not defined by theProcessingContext
, one is instantiated, registered and returned.- Parameters:
sPrefix
- the prefix of the Xml Namespace to use for theNamespaceHandler
uri
- theURI
detailing the location of theNamespaceHandler
. Typically this will be a java class URI, specified as "class://fully.qualified.class.name"- Returns:
- an instance of the
NamespaceHandler
that is suitable for processing the prefix andURI
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
ensureNamespaceHandler
Ensures that the specifiedNamespaceHandler
for the specified prefix is defined in thisProcessingContext
.If a
NamespaceHandler
for the prefix does not exist in theProcessingContext
, it is added. Otherwise the existingNamespaceHandler
for the prefix is returned.- Parameters:
sPrefix
- the prefix of the xml Namespace to be associated with theNamespaceHandler
handler
- theNamespaceHandler
- Returns:
- the registered
NamespaceHandler
for theProcessingContext
-
loadNamespaceHandlers
Load all the customNamespaceHandler
instances for the specifiedXmlElement
.- Parameters:
xmlElement
- theXmlElement
to loadNamespaceHandler
instances for- Throws:
NullPointerException
- if thexmlElement
parameter isnull
-
getNamespaceHandler
Obtains theNamespaceHandler
that is capable of processing the namespace defined with the specifiedURI
.- Parameters:
uri
- the Xml NamespaceURI
of theNamespaceHandler
to locate- Returns:
null
if aNamespaceHandler
could not be located for the specifiedURI
-
getNamespaceHandler
Obtains theNamespaceHandler
which is capable of processing the namespace with the specified prefix.- Parameters:
sPrefix
- the prefix of the xml namespace- Returns:
null
if aNamespaceHandler
could not be located for the specified prefix
-
getNamespaceURI
Obtains theURI
that is associated with the specified prefix. -
getNamespaceHandlers
Iterable<NamespaceHandler> getNamespaceHandlers()Obtains theNamespaceHandler
s that are currently in scope for thisProcessingContext
.- Returns:
- An
Iterable
over theNamespaceHandler
s in scope.
-
processDocumentAt
Request that the document specified by the URI/filename (containing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.Should the document root contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements in the document.- Parameters:
uri
- theURI
of the XmlDocument to process- Returns:
- the result of the processing the root element of the document
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processDocumentAt
Request that the document specified by the URI/filename (containing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.Should the document root contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements in the document.- Parameters:
sLocation
- the URI/filename of the XmlDocument to process- Returns:
- the result of the processing the root element of the document
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processDocument
Request that the specifiedXmlElement
(representing the root of an XmlDocument) be processed with appropriateNamespaceHandler
s.Should the document root contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements in the document.- Parameters:
xmlElement
- the rootXmlElement
of the XmlDocument to process- Returns:
- the result of the processing the root element of the document
represented by the
XmlElement
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processDocument
Request that the specified xml string (representing an xml document) be processed with appropriateNamespaceHandler
s.Should the document root contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements in the document.- Parameters:
sXml
- a string containing an xml document to process- Returns:
- the result of processing the root element of the document
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processElement
Request the specifiedXmlElement
to be processed with an appropriateNamespaceHandler
known by theProcessingContext
or outerProcessingContext
s.Note: Should the element contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements.- Parameters:
xmlElement
- theXmlElement
to process- Returns:
- the result of processing the
XmlElement
with an appropriateElementProcessor
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processElement
Request the specified xml string be processed with an appropriateNamespaceHandler
known by theProcessingContext
.Note: Should the element contain any unrecognized xml namespaces, an attempt will be made to load appropriate
NamespaceHandler
s that of which will be used to process said elements.- Parameters:
sXml
- the xml to process- Returns:
- the result of processing the root element of the specified xml
- Throws:
ConfigurationException
- when a configuration problem was encountered
-
processElementsOf
Request that all of the child elements contained with in the specifiedXmlElement
be processed using appropriateNamespaceHandler
s known by theProcessingContext
.This is a convenience method to aid in the processing of all children of an
XmlElement
. The keys of the returnedMap
represent the id attributes each childXmlElement
. If anXmlElement
does not have a specified id attribute, a UUID is generated in it's place.- Parameters:
xmlElement
- the parentXmlElement
of the children to process- Returns:
- a
Map
from identifiable childXmlElement
s (with id="..." attributes) and their corresponding processed values - Throws:
ConfigurationException
- when a configuration problem was encountered
-
processForeignElementsOf
Request that all of the child elements contained within the specifiedXmlElement
that do not belong to the namespace of the saidXmlElement
are processed using appropriate processes.This is a convenience method to aid in the processing of all children of an
XmlElement
. The keys of the returnedMap
represent the id attributes each childXmlElement
. If anXmlElement
does not have a specified id attribute, a UUID is generated in it's place.- Parameters:
xmlElement
- the parentXmlElement
of the children to process- Returns:
- a
Map
from identifiable childXmlElement
s (with id="..." attributes) and their corresponding processed values - Throws:
ConfigurationException
- when a configuration problem was encountered
-
processOnlyElementOf
Request that the only child element contained within theXmlElement
is processed using an appropriateNamespaceHandler
known by theProcessingContext
.- Type Parameters:
T
- the type- Parameters:
xmlElement
- theXmlElement
in which the child is defined- Returns:
- the result of processing the child element
- Throws:
ConfigurationException
- when a configuration problem was encountered, especially if there is zero or more than one child
-
processRemainingElementOf
Request that the last remaining unprocessed child element contained within the specifiedXmlElement
is processed using an appropriateElementProcessor
.This is a convenience method to aid in the processing of an unprocessed child
XmlElement
of an element.- Type Parameters:
T
- the type- Parameters:
xmlElement
- the parentXmlElement
of the unprocessed child to process- Returns:
- the result of processing the child element
- Throws:
ConfigurationException
- if there are zero or more than one unprocessed child in the element, or if some otherConfigurationException
occurred
-
processRemainingElementsOf
Request that the last remaining unprocessed children contained within the specifiedXmlElement
are processed using appropriateElementProcessor
s.This is a convenience method to aid in the processing of an unprocessed child
XmlElement
s of an element. The keys of the returnedMap
represent the id attributes each childXmlElement
. If anXmlElement
does not have a specified id attribute, a UUID is generated in it's place.- Parameters:
xmlElement
- the parentXmlElement
of the unprocessed children to process- Returns:
- a
Map
from identifiable childXmlElement
s (with id="..." attributes) and their corresponding processed values - Throws:
ConfigurationException
- when a configuration problem was encountered
-
inject
Given the information available in theProcessingContext
, including the cookies, theResourceRegistry
theXmlElement
, itsXmlAttribute
s and/or children, inject appropriately named and typed values into the specified bean (using setter injection).The order in which values are located for injection is as follows; attributed defined by the element, child elements defined by the element, alternative paths to values defined in the
ProcessingContext
, cookies defined by theProcessingContext
and finally theResourceRegistry
associated with theProcessingContext
.- Type Parameters:
B
- the bean type- Parameters:
bean
- the bean to be injectedxmlElement
- theXmlElement
from which values will be derived for injection into the bean- Returns:
- the provided bean but with properties set based on the available values in the
ProcessingContext
- Throws:
ConfigurationException
- if a configuration is not valid
-
isPropertyDefined
Determines if the specified property is defined at the path relative to the specifiedXmlElement
.- Parameters:
sPath
- the path to the propertyxmlElement
- theXmlElement
in which the property should be searched- Returns:
true
if the property is defined,false
otherwise- Throws:
ConfigurationException
- if a configuration is not valid
-
getMandatoryProperty
<T> T getMandatoryProperty(String sPath, Type typeProperty, XmlElement xmlElement) throws ConfigurationException Obtains the strongly typed value for the property defined at the path relative to the specifiedXmlElement
. If the property is not defined or is of the incorrect type, aConfigurationException
is thrown.- Type Parameters:
T
- the type of the property- Parameters:
sPath
- the path to the propertytypeProperty
- the type of the propertyxmlElement
- theXmlElement
containing the properties for the object- Returns:
- the property value
- Throws:
ConfigurationException
- if a configuration is not valid, the property can't be located or is of the wrong type
-
getOptionalProperty
<T> T getOptionalProperty(String sPath, Type typeProperty, T defaultValue, XmlElement xmlElement) throws ConfigurationException Obtains the strongly typed value for the property defined at the path relative to the specifiedXmlElement
. If the property is not defined, the defaultValue is returned.- Type Parameters:
T
- the type of the property- Parameters:
sPath
- the path to the propertytypeProperty
- the type of the propertydefaultValue
- the value to return if the property is not foundxmlElement
- theXmlElement
containing the properties for the object- Returns:
- the property value
- Throws:
ConfigurationException
- if a configuration is not valid
-