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 boolean
usingDefaultFunctionLibrary
-
Constructor Summary
Constructors Constructor Description AbstractStaticContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFunctionLibrary(FunctionLibrary library)
Add a function library to the list of function librariesConfiguration
getConfiguration()
Get the system configurationLocation
getContainingLocation()
Get the containing location.DecimalFormatManager
getDecimalFormatManager()
Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.java.lang.String
getDefaultCollationName()
Get the name of the default collation.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-namespacejava.lang.String
getDefaultFunctionNamespace()
Get the default function namespace.FunctionLibrary
getFunctionLibrary()
Get the function library containing all the in-scope functions available in this static context.KeyManager
getKeyManager()
Get the KeyManager, containing definitions of keys available for use.PackageData
getPackageData()
Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongsItemType
getRequiredContextItemType()
Get the required type of the context item.java.lang.String
getStaticBaseURI()
Get the Base URI, for resolving any relative URI's used in the expression.java.lang.String
getSystemId()
Get the system ID of the container of the expression.UnprefixedElementMatchingPolicy
getUnprefixedElementMatchingPolicy()
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 parserint
getXPathVersion()
Get the XPath language level supported, as an integer (being the actual version number times ten).boolean
isInBackwardsCompatibleMode()
Determine whether Backwards Compatible Mode is usedvoid
issueWarning(java.lang.String s, Location locator)
Issue a compile-time warning.XPathContext
makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressionsRetainedStaticContext
makeRetainedStaticContext()
Construct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluationItemType
resolveTypeAlias(StructuredQName typeName)
Get type alias.void
setBackwardsCompatibilityMode(boolean option)
Set XPath 1.0 backwards compatibility mode on or offvoid
setBaseURI(java.lang.String baseURI)
Set the base URI in the static contextprotected void
setConfiguration(Configuration config)
Set the Configuration.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)void
setDecimalFormatManager(DecimalFormatManager manager)
Set the DecimalFormatManager used to resolve the names of decimal formats used in calls to the format-number() function.void
setDefaultCollationName(java.lang.String collationName)
Set the name of the default collation for this static context.void
setDefaultElementNamespace(java.lang.String uri)
Set the default namespace for elements and typesprotected void
setDefaultFunctionLibrary()
Initialize the default function library for XPath.void
setDefaultFunctionLibrary(int version)
void
setDefaultFunctionNamespace(java.lang.String uri)
Set the default function namespacevoid
setFunctionLibrary(FunctionLibraryList lib)
Set the function library to be usedvoid
setPackageData(PackageData packageData)
Set data about the unit of compilation (XQuery module, XSLT package)void
setSchemaAware(boolean aware)
Say whether this static context is schema-awarevoid
setTypeAlias(StructuredQName name, ItemType type)
Register an alias for an ItemType.void
setUnprefixedElementMatchingPolicy(UnprefixedElementMatchingPolicy policy)
Set the policy for matching unprefixed element names.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 parservoid
setXPathLanguageLevel(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:
getConfiguration
in 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:
getPackageData
in 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:
makeRetainedStaticContext
in 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:
makeEarlyEvaluationContext
in interfaceStaticContext
- Returns:
- a newly constructed dynamic context
-
getContainingLocation
public Location getContainingLocation()
Description copied from interface:StaticContext
Get 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:
getContainingLocation
in 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:
getStaticBaseURI
in 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:
getFunctionLibrary
in 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:
getDefaultCollationName
in 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'saccept
method is called, supplying the string of the warning message as the argument. The default warning handler sends the information to the defaultErrorReporter
associated 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
accept
method 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:
issueWarning
in 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:
getSystemId
in 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:
getDefaultElementNamespace
in 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:
getDefaultFunctionNamespace
in 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:
getXPathVersion
in 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:
isInBackwardsCompatibleMode
in 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:
getRequiredContextItemType
in 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:
getDecimalFormatManager
in 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:
getKeyManager
in 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. Iftypename
has 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
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:
resolveTypeAlias
in 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:
getUnprefixedElementMatchingPolicy
in interfaceStaticContext
- Returns:
- the policy to be used
-
-