Package net.sf.saxon.sxpath
Class AbstractStaticContext
java.lang.Object
net.sf.saxon.sxpath.AbstractStaticContext
- All Implemented Interfaces:
StaticContext
- Direct Known Subclasses:
IndependentContext,JAXPXPathStaticContext,UseWhenStaticContext
An abstract and configurable implementation of the StaticContext interface,
which defines the static context of an XPath expression.
This class implements those parts of the functionality of a static context that tend to be common to most implementations: simple-valued properties such as base URI and default element namespace; availability of the standard function library; and support for collations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface defining a callback for handling warnings -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddFunctionLibrary(FunctionLibrary library) Add a function library to the list of function librariesGet the system configurationGet the containing location.Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.Get the name of the default collation.Get the default namespace URI for elements and types Return NamespaceConstant.NULL (that is, the zero-length string) for the non-namespaceGet the default function namespace.Get the function library containing all the in-scope functions available in this static context.Get the KeyManager, containing definitions of keys available for use.Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongsGet the required type of the context item.Get the Base URI, for resolving any relative URI's used in the expression.Get the system ID of the container of the expression.Get the policy for matching unprefixed element names.Get the callback function that will be called to handle any static warnings found while processing warnings from the XPath parserintGet the XPath language level supported, as an integer (being the actual version number times ten).booleanDetermine whether Backwards Compatible Mode is usedvoidissueWarning(String s, String errorCode, Location locator) Issue a compile-time warning.Construct a dynamic context for early evaluation of constant subexpressionsConstruct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluationresolveTypeAlias(StructuredQName typeName) Get type alias.voidsetBackwardsCompatibilityMode(boolean option) Set XPath 1.0 backwards compatibility mode on or offvoidsetBaseURI(String baseURI) Set the base URI in the static contextprotected voidsetConfiguration(Configuration config) Set the Configuration.voidsetContainingLocation(Location location) Set the containing location, which represents the location of the outermost expression using this static context (typically, subexpressions will have a nested location that refers to this outer containing location)voidSet the DecimalFormatManager used to resolve the names of decimal formats used in calls to the format-number() function.voidsetDefaultCollationName(String collationName) Set the name of the default collation for this static context.voidSet the default namespace for elements and typesprotected final voidInitialize the default function library for XPath.final voidsetDefaultFunctionLibrary(int version) voidSet the default function namespacevoidSet the function library to be usedvoidsetPackageData(PackageData packageData) Set data about the unit of compilation (XQuery module, XSLT package)voidsetSchemaAware(boolean aware) Say whether this static context is schema-awarevoidsetTypeAlias(StructuredQName name, ItemType type) Register an alias for an ItemType.voidSet the policy for matching unprefixed element names.voidsetWarningHandler(BiConsumer<String, Location> handler) Set a callback function that will be called to handle any static warnings found while processing warnings from the XPath parser.voidSet a callback function that will be called to handle any static warnings found while processing warnings from the XPath parservoidsetXPathLanguageLevel(int level) Set the XPath language level supported.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.sf.saxon.expr.StaticContext
bindVariable, getImportedSchemaNamespaces, getNamespaceResolver, getOptimizerOptions, isImportedSchema
-
Constructor Details
-
AbstractStaticContext
public AbstractStaticContext()
-
-
Method Details
-
setConfiguration
Set the Configuration. This is protected so it can be used only by subclasses; the configuration will normally be set at construction time- Parameters:
config- the configuration
-
getConfiguration
Get the system configuration- Specified by:
getConfigurationin interfaceStaticContext- Returns:
- the Saxon configuration
-
setPackageData
Set data about the unit of compilation (XQuery module, XSLT package)- Parameters:
packageData- the package data
-
getPackageData
Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongs- Specified by:
getPackageDatain interfaceStaticContext- Returns:
- the package data
-
setSchemaAware
public void setSchemaAware(boolean aware) Say whether this static context is schema-aware- Parameters:
aware- true if this static context is schema-aware
-
makeRetainedStaticContext
Construct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluation- Specified by:
makeRetainedStaticContextin interfaceStaticContext- Returns:
- a RetainedStaticContext object: either a newly created one, or one that is reused from a previous invocation.
-
setDefaultFunctionLibrary
protected final void setDefaultFunctionLibrary()Initialize the default function library for XPath. This can be overridden using setFunctionLibrary(). -
setDefaultFunctionLibrary
public final void setDefaultFunctionLibrary(int version) -
addFunctionLibrary
Add a function library to the list of function libraries- Parameters:
library- the function library to be added
-
makeEarlyEvaluationContext
Construct a dynamic context for early evaluation of constant subexpressions- Specified by:
makeEarlyEvaluationContextin interfaceStaticContext- Returns:
- a newly constructed dynamic context
-
getContainingLocation
Description copied from interface:StaticContextGet the containing location. This is location information relevant to an expression or query as a whole. In the case of an XPath expression held in a node of an XML document, it will provide the location of that node. In the case of a query held in a file, it contains the location of the file (in its systemId property). The method does NOT provide fine-grained location information for each contained subexpression. The location that is returned should be immutable for the duration of parsing of an XPath expression or query.- Specified by:
getContainingLocationin interfaceStaticContext- Returns:
- the containing location
-
setContainingLocation
Set the containing location, which represents the location of the outermost expression using this static context (typically, subexpressions will have a nested location that refers to this outer containing location)- Parameters:
location- the location map to be used
-
setBaseURI
Set the base URI in the static context- Parameters:
baseURI- the base URI of the expression; the value null is allowed to indicate that the base URI is not available.
-
getStaticBaseURI
Get the Base URI, for resolving any relative URI's used in the expression. Used by the document() function, resolve-uri(), etc.- Specified by:
getStaticBaseURIin interfaceStaticContext- Returns:
- "" if no base URI has been set
-
getFunctionLibrary
Get the function library containing all the in-scope functions available in this static context. This method is called by the XPath parser when binding a function call in the XPath expression to an implementation of the function.- Specified by:
getFunctionLibraryin interfaceStaticContext- Returns:
- the function library
-
setFunctionLibrary
Set the function library to be used- Parameters:
lib- the function library
-
setDefaultCollationName
Set the name of the default collation for this static context.- Parameters:
collationName- the name of the default collation
-
getDefaultCollationName
Get the name of the default collation.- Specified by:
getDefaultCollationNamein interfaceStaticContext- Returns:
- the name of the default collation; or the name of the codepoint collation if no default collation has been defined
-
setWarningHandler
Set a callback function that will be called to handle any static warnings found while processing warnings from the XPath parser.Superseded in 12.0 by
setWarningHandler(WarningHandler), which allows the callback to receive the error code information as well as the error message and originating location.- Parameters:
handler- the function to be called to handle static warnings. When a warning is issued, the handler'sacceptmethod is called, supplying the string of the warning message and a location as the arguments. The default warning handler sends the information to the defaultErrorReporterassociated with the SaxonConfiguration.- Since:
- 10.0
-
setWarningHandler
Set a callback function that will be called to handle any static warnings found while processing warnings from the XPath parser- Parameters:
handler- the function to be called to handle static warnings. When a warning is issued, the handler'sacceptmethod is called, supplying the string of the warning message, an error code, and a location as the arguments. The default warning handler sends the information to the defaultErrorReporterassociated with the SaxonConfiguration.- Since:
- 12.0
-
getWarningHandler
Get the callback function that will be called to handle any static warnings found while processing warnings from the XPath parser- Returns:
- the function to be called to handle static warnings, if one has been supplied.
When a warning is
issued, the handler's
acceptmethod is called, supplying the string of the warning message and the location information as the two arguments. - Since:
- 10.0. Modified in 12.0 to return a
AbstractStaticContext.WarningHandler, which is a three-argument callback accepting the error message, error code, and location.
-
issueWarning
Issue a compile-time warning. This method is used during XPath expression compilation to output warning conditions. The default implementation writes the message to the error reporter registered with the Configuration.- Specified by:
issueWarningin interfaceStaticContext- Parameters:
s- The warning message. This should not contain any prefix such as "Warning".errorCode- Error code identifying the warning conditionlocator- the location of the construct in question. May be null.
-
getSystemId
Get the system ID of the container of the expression. Used to construct error messages.- Specified by:
getSystemIdin interfaceStaticContext- Returns:
- "" always
-
getDefaultElementNamespace
Get the default namespace URI for elements and types Return NamespaceConstant.NULL (that is, the zero-length string) for the non-namespace- Specified by:
getDefaultElementNamespacein interfaceStaticContext- Returns:
- the default namespace for elements and type
-
setDefaultElementNamespace
Set the default namespace for elements and types- Parameters:
uri- the namespace to be used for unprefixed element and type names. The value "" (or NamespaceConstant.NULL) represents the non-namespace
-
setDefaultFunctionNamespace
Set the default function namespace- Parameters:
uri- the namespace to be used for unprefixed function names. The value "" (or NamespaceConstant.NULL) represents the non-namespace
-
getDefaultFunctionNamespace
Get the default function namespace. The value "" (or NamespaceConstant.NULL) represents the non-namespace- Specified by:
getDefaultFunctionNamespacein interfaceStaticContext- Returns:
- the default namesapce for functions
-
setXPathLanguageLevel
public void setXPathLanguageLevel(int level) Set the XPath language level supported. The current levels supported are 20 (=2.0), 31 (=3.1), and 40 (=4.0). The default is 3.1.- Parameters:
level- the XPath language level- Since:
- 9.3. From 9.8 this only affects the XPath syntax that is accepted;
it does not affect the function library that is available, which must be
set separately using
setFunctionLibrary(FunctionLibraryList)
-
getXPathVersion
public int getXPathVersion()Get the XPath language level supported, as an integer (being the actual version number times ten). In Saxon 9.9 the possible values are 20 (XPath 2.0), 30 (XPath 3.0), 31 (XPath 3.1), and 305 (XPath 3.0 plus the extensions defined in XSLT 3.0).- Specified by:
getXPathVersionin interfaceStaticContext- Returns:
- the XPath language level; the return value will be either 20, 30, 305, or 31
- Since:
- 9.7
-
setBackwardsCompatibilityMode
public void setBackwardsCompatibilityMode(boolean option) Set XPath 1.0 backwards compatibility mode on or off- Parameters:
option- true if XPath 1.0 compatibility mode is to be set to true; otherwise false
-
isInBackwardsCompatibleMode
public boolean isInBackwardsCompatibleMode()Determine whether Backwards Compatible Mode is used- Specified by:
isInBackwardsCompatibleModein interfaceStaticContext- Returns:
- true if XPath 1.0 compatibility mode is to be set to true; otherwise false
-
setDecimalFormatManager
Set the DecimalFormatManager used to resolve the names of decimal formats used in calls to the format-number() function.- Parameters:
manager- the decimal format manager for this static context, or null if no named decimal formats are available in this environment.
-
getRequiredContextItemType
Get the required type of the context item. If no type has been explicitly declared for the context item, an instance of AnyItemType (representing the type item()) is returned.- Specified by:
getRequiredContextItemTypein interfaceStaticContext- Returns:
- the required type of the context item
- Since:
- 9.3
-
getDecimalFormatManager
Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.- Specified by:
getDecimalFormatManagerin interfaceStaticContext- Returns:
- the decimal format manager for this static context; a newly created empty DecimalFormatManager if none has been supplied
- Since:
- 9.2
-
getKeyManager
Get the KeyManager, containing definitions of keys available for use.- Specified by:
getKeyManagerin interfaceStaticContext- Returns:
- the KeyManager. This is used to resolve key names, both explicit calls on key() used in XSLT, and system-generated calls on key() which may also appear in XQuery and XPath
-
setTypeAlias
Register an alias for an ItemType. This is a Saxon extension. Iftypenamehas been registered as an alias for, say, map{xs:string, xs:integer*}, then the syntaxtype(typename)is accepted anywhere this ItemType would be accepted.- Parameters:
name- the alias name of the typetype- the type to which this alias refers
-
resolveTypeAlias
Get type alias. This is a Saxon extension. A type alias is a QName which can be used as a shorthand for an itemtype, using the syntax ~typename anywhere that an item type is permitted.- Specified by:
resolveTypeAliasin interfaceStaticContext- Parameters:
typeName- the name of the type alias- Returns:
- the corresponding item type, if the name is recognised; otherwise null.
-
setUnprefixedElementMatchingPolicy
Set the policy for matching unprefixed element names.- Parameters:
policy- the policy to be used
-
getUnprefixedElementMatchingPolicy
Get the policy for matching unprefixed element names.- Specified by:
getUnprefixedElementMatchingPolicyin interfaceStaticContext- Returns:
- the policy to be used
-