public class Processor extends java.lang.Object implements Configuration.ApiProvider
Processor
class serves three purposes: it allows global Saxon configuration options to be set;
it acts as a factory for generating XQuery, XPath, and XSLT compilers; and it owns certain shared
resources such as the Saxon NamePool and compiled schemas. This is the first object that a
Saxon application should create. Once established, a Processor may be used in multiple threads.
It is possible to run more than one Saxon Processor concurrently, but only when running completely independent workloads. Nothing can be shared between Processor instances. Within a query or transformation, all source documents and schemas must be built using the same Processor, which must also be used to compile the query or stylesheet.
Constructor and Description |
---|
Processor(boolean licensedEdition)
Create a Processor
|
Processor(Configuration config)
Create a Processor based on an existing Configuration.
|
Processor(javax.xml.transform.Source source)
Create a Processor configured according to the settings in a supplied configuration file.
|
Modifier and Type | Method and Description |
---|---|
void |
declareCollation(java.lang.String uri,
java.util.Comparator collation)
Bind a collation URI to a collation
|
<T> T |
getConfigurationProperty(Feature<T> feature)
Get the value of a configuration property
|
java.lang.Object |
getConfigurationProperty(java.lang.String name)
Deprecated.
since 9.9 - use
getConfigurationProperty(Feature) |
java.lang.String |
getSaxonEdition()
Get the short name of the Saxon product edition, for example "EE".
|
java.lang.String |
getSaxonProductVersion()
Get the user-visible Saxon product version, for example "9.0.0.1"
|
SchemaManager |
getSchemaManager()
Get the associated SchemaManager.
|
Configuration |
getUnderlyingConfiguration()
Get the underlying
Configuration object that underpins this Processor. |
java.lang.String |
getXmlVersion()
Get the version of XML used by this Processor.
|
boolean |
isSchemaAware()
Test whether this processor is schema-aware
|
DocumentBuilder |
newDocumentBuilder()
Create a DocumentBuilder.
|
Serializer |
newSerializer()
Create a Serializer
|
Serializer |
newSerializer(java.io.File file)
Create a Serializer initialized to write to a given File.
|
Serializer |
newSerializer(java.io.OutputStream stream)
Create a Serializer initialized to write to a given OutputStream.
|
Serializer |
newSerializer(java.io.Writer writer)
Create a Serializer initialized to write to a given Writer.
|
XPathCompiler |
newXPathCompiler()
Create an XPathCompiler.
|
XQueryCompiler |
newXQueryCompiler()
Create an XQueryCompiler.
|
XsltCompiler |
newXsltCompiler()
Create an XsltCompiler.
|
void |
registerExtensionFunction(ExtensionFunction function)
Register a simple external/extension function that is to be made available within any stylesheet, query,
or XPath expression compiled under the control of this processor.
|
void |
registerExtensionFunction(ExtensionFunctionDefinition function)
Register an extension function that is to be made available within any stylesheet, query,
or XPath expression compiled under the control of this processor.
|
<T> void |
setConfigurationProperty(Feature<T> feature,
T value)
Set a configuration property
|
void |
setConfigurationProperty(java.lang.String name,
java.lang.Object value)
Deprecated.
since 9.9 - use
setConfigurationProperty(Feature, Object) |
void |
setXmlVersion(java.lang.String version)
Set the version of XML used by this Processor.
|
void |
writeXdmValue(XdmValue value,
Destination destination)
Write an XdmValue to a given destination.
|
public Processor(boolean licensedEdition)
licensedEdition
- indicates whether the Processor requires features of Saxon that need a license
file (that is, features not available in Saxon HE (Home Edition). If true, the method will create
a Configuration appropriate to the version of the software that is running: for example, if running
Saxon-EE, it will create an EnterpriseConfiguration. The method does not at this stage check that a license
is available, and in the absence of a license, it should run successfully provided no features that
require licensing are actually used. If the argument is set to false, a plain Home Edition Configuration
is created unconditionally.public Processor(Configuration config)
config
- the Configuration to be used by this processorpublic Processor(javax.xml.transform.Source source) throws SaxonApiException
source
- the Source of the configuration fileSaxonApiException
- if the configuration file cannot be read, or its contents are invalidpublic DocumentBuilder newDocumentBuilder()
public XPathCompiler newXPathCompiler()
public XsltCompiler newXsltCompiler()
java.lang.UnsupportedOperationException
- if this version of the Saxon product does not support XSLT processingpublic XQueryCompiler newXQueryCompiler()
java.lang.UnsupportedOperationException
- if this version of the Saxon product does not support XQuery processingpublic Serializer newSerializer()
public Serializer newSerializer(java.io.OutputStream stream)
Closing the output stream after use is the responsibility of the caller.
stream
- The OutputStream to which the Serializer will writepublic Serializer newSerializer(java.io.Writer writer)
Closing the writer after use is the responsibility of the caller.
writer
- The Writer to which the Serializer will writepublic Serializer newSerializer(java.io.File file)
file
- The File to which the Serializer will writepublic void registerExtensionFunction(ExtensionFunction function)
This interface provides only for simple extension functions that have no side-effects and no dependencies on the static or dynamic context.
function
- the implementation of the extension function.public void registerExtensionFunction(ExtensionFunctionDefinition function)
ExtensionFunctionDefinition
, using an arbitrary name and namespace.
This interface allows extension functions that have dependencies on the static or dynamic context. It also allows an extension function to declare that it has side-effects, in which case calls to the function will be optimized less aggressively than usual, although the semantics are still to some degree unpredictable.
function
- the implementation of the extension function.public SchemaManager getSchemaManager()
public boolean isSchemaAware()
public java.lang.String getSaxonProductVersion()
public java.lang.String getSaxonEdition()
public void setXmlVersion(java.lang.String version)
Note that source documents specifying xml version="1.0" or "1.1" are accepted regardless of this setting.
version
- must be one of the strings "1.0" or "1.1"java.lang.IllegalArgumentException
- if any string other than "1.0" or "1.1" is suppliedpublic java.lang.String getXmlVersion()
public void setConfigurationProperty(java.lang.String name, java.lang.Object value)
setConfigurationProperty(Feature, Object)
name
- the name of the option to be set. The names of the options available are listed
as constants in class FeatureKeys
.value
- the value of the option to be set.java.lang.IllegalArgumentException
- if the property name is not recognized or if the supplied value
is not a valid value for the named property.public java.lang.Object getConfigurationProperty(java.lang.String name)
getConfigurationProperty(Feature)
name
- the name of the option required. The names of the properties available are listed
as constants in class FeatureKeys
.java.lang.IllegalArgumentException
- if the property name is not recognizedpublic <T> void setConfigurationProperty(Feature<T> feature, T value)
feature
- the option to be set. The names of the options available are listed
as constants in class Feature
.value
- the value of the option to be set (which must be of the appropriate type for the
particular feature.java.lang.IllegalArgumentException
- if the supplied value is not a valid value for the selected feature.setConfigurationProperty(String, Object)
public <T> T getConfigurationProperty(Feature<T> feature)
feature
- the option required. The names of the properties available are listed
as constants in class Feature
.getConfigurationProperty(String)
public void declareCollation(java.lang.String uri, java.util.Comparator collation)
uri
- the absolute collation URIcollation
- a Comparator
object that implements the required collationjava.lang.IllegalArgumentException
- if an attempt is made to rebind the standard URI
for the Unicode codepoint collation or the HTML5 case-blind
collationpublic Configuration getUnderlyingConfiguration()
Configuration
object that underpins this Processor. This method
provides an escape hatch to internal Saxon implementation objects that offer a finer and lower-level
degree of control than the s9api classes and methods. Some of these classes and methods may change
from release to release.public void writeXdmValue(XdmValue value, Destination destination) throws SaxonApiException
If the destination is a Serializer
then the method processor.writeXdmValue(V, S)
is equivalent to calling S.serializeXdmValue(V)
.
In other cases, the sequence represented by the XdmValue is "normalized" as defined in the serialization specification (this is equivalent to constructing a document node in XSLT or XQuery with this sequence as the content expression), and the resulting document is then copied to the destination. Note that the construction of a document tree will fail if the sequence contains items such as maps and arrays.
value
- the value to be writtendestination
- the destination to which the value is to be writtenSaxonApiException
- if any failure occurs, for example a serialization errorCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.