Class XFactory
- java.lang.Object
-
- com.ibm.xml.xapi.XFactory
-
public abstract class XFactory extends java.lang.ObjectThe
XFactoryclass is the main factory class for creating executables for XPath, XQuery, and XSLT. It is also the means for creating instances of other classes and factories such as theXStaticContext,XDynamicContext,XItemFactory, andXSequenceTypeFactoryclasses. Use thenewInstancemethod to get a concreteXFactoryobject.An instance of
XFactorymaintains a set of registered schemas and can be validating or non-validating. A validating factory produces schema-aware executables and ensures that source documents get validated against the set of registered schemas before they are processed. If a source document includes a schema location and that schema is not already registered then it will be registered automatically when the source document is processed. If different sets of stylesheets, queries or expressions need different sets of schemas, these can be kept separate by using more than one XFactory instance.An instance of
XFactoryis thread safe as long as the settings remain stable.
-
-
Field Summary
Fields Modifier and Type Field and Description static intFULL_VALIDATIONConstant indicating that executables should be schema aware and input documents will be validated.static intNO_VALIDATIONConstant indicating that executables should not be schema aware and input documents will not be validated.
-
Constructor Summary
Constructors Constructor and Description XFactory()
-
Method Summary
Methods Modifier and Type Method and Description abstract XCompilationFactorygetCompilationFactory()Get the compilation factory.abstract XItemFactorygetItemFactory()Get the item factory.abstract XMessageHandlergetMessageHandler()Get the message handler.abstract XSchemaResolvergetSchemaResolver()Get the currently registered schema resolver.abstract XSequenceTypeFactorygetSequenceTypeFactory()Get the sequence type factory.abstract org.w3c.dom.DocumentgetValidatedDOM(org.w3c.dom.Document document)Get a validated DOM.abstract org.w3c.dom.DocumentgetValidatedDOM(javax.xml.transform.stream.StreamSource source)Get a validated DOM.abstract intgetValidating()Get the validation setting.static java.lang.StringgetVersion()Get the version of theXFactory.abstract XDynamicContextnewDynamicContext()Create a newXDynamicContext.static XFactorynewInstance()Create the defaultXFactoryinstance.abstract XOutputParametersnewOutputParameters()Create a newXOutputParameters.abstract XStaticContextnewStaticContext()Create a newXStaticContext.abstract XPathExecutableprepareXPath(javax.xml.transform.stream.StreamSource expression)Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.abstract XPathExecutableprepareXPath(javax.xml.transform.stream.StreamSource expression, XStaticContext context)Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.abstract XPathExecutableprepareXPath(java.lang.String expression)Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.abstract XPathExecutableprepareXPath(java.lang.String expression, XStaticContext context)Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.abstract XQueryExecutableprepareXQuery(javax.xml.transform.stream.StreamSource query)Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.abstract XQueryExecutableprepareXQuery(javax.xml.transform.stream.StreamSource query, XStaticContext context)Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.abstract XQueryExecutableprepareXQuery(java.lang.String query)Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.abstract XQueryExecutableprepareXQuery(java.lang.String query, XStaticContext context)Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.abstract XSLTExecutableprepareXSLT(javax.xml.transform.Source stylesheet)Create anXSLTransformExecutablefor an XSL stylesheet which can then be used to apply that stylesheet to input documents.abstract XSLTExecutableprepareXSLT(javax.xml.transform.Source stylesheet, XStaticContext context)Create anXSLTransformExecutablefor an XSL stylesheet which can then be used to apply that stylesheet to input documents.abstract voidregisterSchema(javax.xml.transform.Source source)Register a schema.abstract voidregisterSchemas(java.util.List<? extends javax.xml.transform.Source> schemas)Register a list of schemas.abstract voidsetMessageHandler(XMessageHandler handler)Set the message handler to be used when registering schemas, creating new items and sequences, and preparing and executing expressions, queries and stylesheets.abstract voidsetSchemaResolver(XSchemaResolver resolver)Set the schema resolver to be used for imports in schemas registered using theregisterSchemamethod or for schemas imported in XSLT using thexsl:import-schemadeclaration.abstract voidsetValidating(int value)When full validation is enabled the factory will create validating executables and the input document will be validated on execution.
-
-
-
Field Detail
-
NO_VALIDATION
public static final int NO_VALIDATION
Constant indicating that executables should not be schema aware and input documents will not be validated.- See Also:
setValidating(int), Constant Field Values
-
FULL_VALIDATION
public static final int FULL_VALIDATION
Constant indicating that executables should be schema aware and input documents will be validated.- See Also:
setValidating(int), Constant Field Values
-
-
Method Detail
-
newInstance
public static XFactory newInstance() throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException
Create the defaultXFactoryinstance.- Returns:
- The new
XFactoryinstance. - Throws:
java.lang.ClassNotFoundException- if the class cannot be found.java.lang.IllegalAccessException- if the class is not accessible.java.lang.InstantiationException- if the class cannot be instantiated.
-
getVersion
public static java.lang.String getVersion()
Get the version of theXFactory. Use this method to determine what features are available.- Returns:
- The version as a string.
-
prepareXPath
public abstract XPathExecutable prepareXPath(java.lang.String expression)
Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents. The default static context settings are used.- Parameters:
expression- The XPath expression as aString.- Returns:
- An XPathExecutable object for the XPath expression.
- Throws:
java.lang.NullPointerException- if the expression is null.XProcessException- if the prepare fails because of errors in the expression.
-
prepareXPath
public abstract XPathExecutable prepareXPath(java.lang.String expression, XStaticContext context)
Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.- Parameters:
expression- The XPath expression as aString.context- The static context.- Returns:
- An XPathExecutable object for the XPath expression.
- Throws:
java.lang.NullPointerException- if the expression is null.XProcessException- if the prepare fails because of errors in the expression.
-
prepareXPath
public abstract XPathExecutable prepareXPath(javax.xml.transform.stream.StreamSource expression)
Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents. The default static context settings are used.- Parameters:
expression- The XPath expression as aStreamSource.- Returns:
- An XPathExecutable object for the XPath expression.
- Throws:
java.lang.NullPointerException- if the expression is null.XProcessException- if the prepare fails because of errors in the expression.
-
prepareXPath
public abstract XPathExecutable prepareXPath(javax.xml.transform.stream.StreamSource expression, XStaticContext context)
Create anXPathExecutablefor an XPath expression which can then be used to apply that expression to input documents.- Parameters:
expression- The XPath expression as aStreamSource.context- The static context.- Returns:
- An XPathExecutable object for the XPath expression.
- Throws:
java.lang.NullPointerException- if the expression is null.XProcessException- if the prepare fails because of errors in the expression.
-
prepareXQuery
public abstract XQueryExecutable prepareXQuery(java.lang.String query)
Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents. The default static context settings are used.- Parameters:
query- The XQuery expression as anString.- Returns:
- An XQueryExecutable object for the XQuery expression.
- Throws:
java.lang.NullPointerException- if the query is null.XProcessException- if the prepare fails because of errors in the query.
-
prepareXQuery
public abstract XQueryExecutable prepareXQuery(java.lang.String query, XStaticContext context)
Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.- Parameters:
query- The XQuery expression as aString.context- The static context.- Returns:
- An XQueryExecutable object for the XQuery expression.
- Throws:
java.lang.NullPointerException- if the query is null.XProcessException- if the prepare fails because of errors in the query.
-
prepareXQuery
public abstract XQueryExecutable prepareXQuery(javax.xml.transform.stream.StreamSource query)
Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents. The default static context settings are used.- Parameters:
query- The XQuery expression as aStreamSource.- Returns:
- An XQueryExecutable object for the XQuery expression.
- Throws:
java.lang.NullPointerException- if the query is null.XProcessException- if the prepare fails because of errors in the query.
-
prepareXQuery
public abstract XQueryExecutable prepareXQuery(javax.xml.transform.stream.StreamSource query, XStaticContext context)
Create anXQueryExecutablefor an XQuery expression which can then be used to apply that expression to input documents.- Parameters:
query- The XQuery expression as aStreamSource.context- The static context.- Returns:
- An XQueryExecutable object for the XQuery expression.
- Throws:
java.lang.NullPointerException- if the query is null.XProcessException- if the prepare fails because of errors in the query.
-
prepareXSLT
public abstract XSLTExecutable prepareXSLT(javax.xml.transform.Source stylesheet)
Create anXSLTransformExecutablefor an XSL stylesheet which can then be used to apply that stylesheet to input documents. The default static context settings are used.- Parameters:
stylesheet- The XSL stylesheet as aSourceobject.- Returns:
- An XSLTransformExecutable object for the XSL stylesheet.
- Throws:
java.lang.NullPointerException- if the stylesheet is null.XProcessException- if the prepare fails because of errors in the stylesheet.
-
prepareXSLT
public abstract XSLTExecutable prepareXSLT(javax.xml.transform.Source stylesheet, XStaticContext context)
Create anXSLTransformExecutablefor an XSL stylesheet which can then be used to apply that stylesheet to input documents.- Parameters:
stylesheet- The XSL stylesheet as aSourceobject.context- The static context.- Returns:
- An XSLTransformExecutable object for the XSL stylesheet.
- Throws:
java.lang.NullPointerException- if the stylesheet is null.XProcessException- if the prepare fails because of errors in the stylesheet.
-
newStaticContext
public abstract XStaticContext newStaticContext()
Create a newXStaticContext.- Returns:
- A new
XStaticContextobject.
-
newDynamicContext
public abstract XDynamicContext newDynamicContext()
Create a newXDynamicContext.- Returns:
- A new
XDynamicContextobject.
-
setValidating
public abstract void setValidating(int value)
When full validation is enabled the factory will create validating executables and the input document will be validated on execution. Depends on the schemas that have been registered. The default isNO_VALIDATION.- Parameters:
value- Set toFULL_VALIDATIONfor full schema validation,NO_VALIDATIONfor no schema validation.- See Also:
registerSchema(Source),FULL_VALIDATION,NO_VALIDATION
-
getValidating
public abstract int getValidating()
Get the validation setting.
-
registerSchema
public abstract void registerSchema(javax.xml.transform.Source source)
Register a schema. Has no effect if validating is not enabled. ValidSourcetypes are:StreamSourceSAXSourceDOMSourceStAXSource
- Parameters:
source- The schema to register.- Throws:
java.lang.NullPointerException- if the source is null.- See Also:
setValidating(int)
-
registerSchemas
public abstract void registerSchemas(java.util.List<? extends javax.xml.transform.Source> schemas)
Register a list of schemas. Has no effect if validating is not enabled. ValidSourcetypes are:StreamSourceSAXSourceDOMSourceStAXSource
- Parameters:
schemas- A list of schemas to register.- Throws:
java.lang.NullPointerException- if the list is null.- See Also:
setValidating(int)
-
setSchemaResolver
public abstract void setSchemaResolver(XSchemaResolver resolver)
Set the schema resolver to be used for imports in schemas registered using the
registerSchemamethod or for schemas imported in XSLT using thexsl:import-schemadeclaration.The default behaviour for resolving imports within a schema is to use the base URI of the schema to resolve the imported schema's location. The default behaviour for XSLT schema imports is to use the base URI of the
xsl:import-schemadeclaration to resolve the location specified in the declaration.- Parameters:
resolver- The schema resolver implementation or null to revert to the default schema resolution behaviour.
-
getSchemaResolver
public abstract XSchemaResolver getSchemaResolver()
Get the currently registered schema resolver.- Returns:
- The schema resolver implementation or null if none was set.
-
getItemFactory
public abstract XItemFactory getItemFactory()
Get the item factory.There is a direct association between an item factory and an
XFactoryinstance since the item factory depends on the registered schemas and whether validating is enabled when processingSourceobjects. New schemas registered using theregisterSchemamethod will be visible by the item factory.
-
getSequenceTypeFactory
public abstract XSequenceTypeFactory getSequenceTypeFactory()
Get the sequence type factory.There is a direct association between a sequence type factory and an
XFactoryinstance since the sequence type factory depends on the registered schemas. New schemas registered using theregisterSchemamethod will be visible by the sequence type factory.
-
getCompilationFactory
public abstract XCompilationFactory getCompilationFactory()
Get the compilation factory.There is a direct association between a compilation factory and an
XFactoryinstance since the compilation factory depends on the registered schemas and whether validating is enabled when generating compiled executables. New schemas registered using theregisterSchemamethod will be visible by the compilation factory.
-
newOutputParameters
public abstract XOutputParameters newOutputParameters()
Create a newXOutputParameters.- Returns:
- A new
XOutputParametersobject.
-
getValidatedDOM
public abstract org.w3c.dom.Document getValidatedDOM(javax.xml.transform.stream.StreamSource source)
Get a validated DOM. Required schemas must be registered using theregisterSchemamethod prior to calling this method.- Parameters:
source- The source.- Returns:
- A validated
Document. - See Also:
registerSchema(Source)
-
getValidatedDOM
public abstract org.w3c.dom.Document getValidatedDOM(org.w3c.dom.Document document)
Get a validated DOM. Required schemas must be registered using theregisterSchemamethod prior to calling this method.- Parameters:
document- The document.- Returns:
- A validated
Document. - See Also:
registerSchema(Source)
-
setMessageHandler
public abstract void setMessageHandler(XMessageHandler handler)
Set the message handler to be used when registering schemas, creating new items and sequences, and preparing and executing expressions, queries and stylesheets. The message handler used when preparing an expression, query or stylesheet can be overridden by setting the message handler on the XStaticContext. The message handler used when executing an expression, query or stylesheet can be overridden by setting the message handler on the XDynamicContext.- Parameters:
handler- The message handler. Pass innullto restore the default message handling behaviour.- See Also:
XStaticContext.setMessageHandler(XMessageHandler),XDynamicContext.setMessageHandler(XMessageHandler)
-
getMessageHandler
public abstract XMessageHandler getMessageHandler()
Get the message handler.- Returns:
- The message handler or
nullif not set.
-
-