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
public abstract class AbstractStaticContext extends java.lang.Object implements StaticContext
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanusingDefaultFunctionLibrary
-
Constructor Summary
Constructors Constructor Description AbstractStaticContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFunctionLibrary(FunctionLibrary library)Add a function library to the list of function librariesConfigurationgetConfiguration()Get the system configurationLocationgetContainingLocation()Get the containing location.DecimalFormatManagergetDecimalFormatManager()Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.java.lang.StringgetDefaultCollationName()Get the name of the default collation.java.lang.StringgetDefaultElementNamespace()Get the default namespace URI for elements and types Return NamespaceConstant.NULL (that is, the zero-length string) for the non-namespacejava.lang.StringgetDefaultFunctionNamespace()Get the default function namespace.FunctionLibrarygetFunctionLibrary()Get the function library containing all the in-scope functions available in this static context.KeyManagergetKeyManager()Get the KeyManager, containing definitions of keys available for use.PackageDatagetPackageData()Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongsItemTypegetRequiredContextItemType()Get the required type of the context item.java.lang.StringgetStaticBaseURI()Get the Base URI, for resolving any relative URI's used in the expression.java.lang.StringgetSystemId()Get the system ID of the container of the expression.UnprefixedElementMatchingPolicygetUnprefixedElementMatchingPolicy()Get the policy for matching unprefixed element names.java.util.function.BiConsumer<java.lang.String,Location>getWarningHandler()Get the callback function that will be called to handle any static warnings found while processing warnings from the XPath parserintgetXPathVersion()Get the XPath language level supported, as an integer (being the actual version number times ten).booleanisInBackwardsCompatibleMode()Determine whether Backwards Compatible Mode is usedvoidissueWarning(java.lang.String s, Location locator)Issue a compile-time warning.XPathContextmakeEarlyEvaluationContext()Construct a dynamic context for early evaluation of constant subexpressionsRetainedStaticContextmakeRetainedStaticContext()Construct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluationItemTyperesolveTypeAlias(StructuredQName typeName)Get type alias.voidsetBackwardsCompatibilityMode(boolean option)Set XPath 1.0 backwards compatibility mode on or offvoidsetBaseURI(java.lang.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)voidsetDecimalFormatManager(DecimalFormatManager manager)Set the DecimalFormatManager used to resolve the names of decimal formats used in calls to the format-number() function.voidsetDefaultCollationName(java.lang.String collationName)Set the name of the default collation for this static context.voidsetDefaultElementNamespace(java.lang.String uri)Set the default namespace for elements and typesprotected voidsetDefaultFunctionLibrary()Initialize the default function library for XPath.voidsetDefaultFunctionLibrary(int version)voidsetDefaultFunctionNamespace(java.lang.String uri)Set the default function namespacevoidsetFunctionLibrary(FunctionLibraryList lib)Set 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.voidsetUnprefixedElementMatchingPolicy(UnprefixedElementMatchingPolicy policy)Set the policy for matching unprefixed element names.voidsetWarningHandler(java.util.function.BiConsumer<java.lang.String,Location> handler)Set 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, wait
-
Methods inherited from interface net.sf.saxon.expr.StaticContext
bindVariable, getImportedSchemaNamespaces, getNamespaceResolver, getOptimizerOptions, isImportedSchema
-
-
-
-
Method Detail
-
setConfiguration
protected void setConfiguration(Configuration config)
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
public Configuration getConfiguration()
Get the system configuration- Specified by:
getConfigurationin interfaceStaticContext- Returns:
- the Saxon configuration
-
setPackageData
public void setPackageData(PackageData packageData)
Set data about the unit of compilation (XQuery module, XSLT package)- Parameters:
packageData- the package data
-
getPackageData
public PackageData 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
public RetainedStaticContext 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
protected final void addFunctionLibrary(FunctionLibrary library)
Add a function library to the list of function libraries- Parameters:
library- the function library to be added
-
makeEarlyEvaluationContext
public XPathContext makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressions- Specified by:
makeEarlyEvaluationContextin interfaceStaticContext- Returns:
- a newly constructed dynamic context
-
getContainingLocation
public Location 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
public void setContainingLocation(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)- Parameters:
location- the location map to be used
-
setBaseURI
public void setBaseURI(java.lang.String baseURI)
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
public java.lang.String 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
public FunctionLibrary 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
public void setFunctionLibrary(FunctionLibraryList lib)
Set the function library to be used- Parameters:
lib- the function library
-
setDefaultCollationName
public void setDefaultCollationName(java.lang.String collationName)
Set the name of the default collation for this static context.- Parameters:
collationName- the name of the default collation
-
getDefaultCollationName
public java.lang.String 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
public void setWarningHandler(java.util.function.BiConsumer<java.lang.String,Location> handler)
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 as the argument. The default warning handler sends the information to the defaultErrorReporterassociated with the SaxonConfiguration.- Since:
- 10.0
-
getWarningHandler
public java.util.function.BiConsumer<java.lang.String,Location> 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
-
issueWarning
public void issueWarning(java.lang.String s, Location locator)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".locator- the location of the construct in question. May be null.
-
getSystemId
public java.lang.String getSystemId()
Get the system ID of the container of the expression. Used to construct error messages.- Specified by:
getSystemIdin interfaceStaticContext- Returns:
- "" always
-
getDefaultElementNamespace
public java.lang.String 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
public void setDefaultElementNamespace(java.lang.String uri)
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
public void setDefaultFunctionNamespace(java.lang.String uri)
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
public java.lang.String 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) and 31 (=3.1). 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
public void setDecimalFormatManager(DecimalFormatManager manager)
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
public ItemType 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
public DecimalFormatManager 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
public KeyManager 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
public void setTypeAlias(StructuredQName name, ItemType type)
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 syntax~typenameis accepted anywhere this ItemType would be accepted.
-
resolveTypeAlias
public ItemType resolveTypeAlias(StructuredQName typeName)
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
public void setUnprefixedElementMatchingPolicy(UnprefixedElementMatchingPolicy policy)
Set the policy for matching unprefixed element names.- Parameters:
policy- the policy to be used
-
getUnprefixedElementMatchingPolicy
public UnprefixedElementMatchingPolicy getUnprefixedElementMatchingPolicy()
Get the policy for matching unprefixed element names.- Specified by:
getUnprefixedElementMatchingPolicyin interfaceStaticContext- Returns:
- the policy to be used
-
-