Package net.sf.saxon.sxpath
Class IndependentContext
java.lang.Object
net.sf.saxon.sxpath.AbstractStaticContext
net.sf.saxon.sxpath.IndependentContext
- All Implemented Interfaces:
StaticContext,NamespaceResolver
- Direct Known Subclasses:
SchemaElement.XPathStaticContext
An IndependentContext provides a context for parsing an XPath expression appearing
in a context other than a stylesheet.
This class is used in a number of places where freestanding XPath expressions occur. These include the native Saxon XPath API, the .NET XPath API, XPath expressions used in XML Schema identity constraints, and XPath expressions supplied to saxon:evaluate(). It is not used by the JAXP XPath API (though it shares code with that API through the common superclass AbstractStaticContext).
This class currently provides no mechanism for binding user-defined functions.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.sf.saxon.sxpath.AbstractStaticContext
AbstractStaticContext.WarningHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Executableprotected NamespaceResolverprotected Schemaprotected HashMap<String, NamespaceUri> protected OptimizerOptionsprotected booleanprotected SequenceTypeprotected RetainedStaticContextprotected HashMap<StructuredQName, XPathVariable> Fields inherited from class net.sf.saxon.sxpath.AbstractStaticContext
prologNamespaces, usingDefaultFunctionLibrary, xpathLanguageLevel -
Constructor Summary
ConstructorsConstructorDescriptionCreate an IndependentContext along with a new (non-schema-aware) Saxon ConfigurationIndependentContext(Configuration config) Create an IndependentContext using a specific ConfigurationIndependentContext(Configuration config, int version) Create an IndependentContext using a specific ConfigurationCreate a IndependentContext as a copy of another IndependentContext -
Method Summary
Modifier and TypeMethodDescriptionbindVariable(StructuredQName qName) Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared.voidClear all the declared namespaces, including the standard ones (xml, xslt, saxon).voidClear all the declared namespaces, except for the standard ones (xml, xsl, saxon).voiddeclareNamespace(String prefix, NamespaceUri uri) Declare a namespace whose prefix can be used in expressionsdeclareVariable(NamespaceUri namespaceURI, String localName) Declare a variable.declareVariable(StructuredQName qName) Declare a variable.declareVariable(QNameValue qname) Declare a variable.intGet the declared variable with a given name, if there is oneGet an iterator over all the variables that have been declared, either explicitly by an application call on declareVariable(), or implicitly if the optionallowUndeclaredVariablesis set.Get the imported schema for this static context, if anyintGet a namespace resolver to resolve the namespaces declared in this static context.Get the optimizer options being used for compiling expressions that use this static context.Get the required type of the context item.Get the required type of the context item.intgetSlotNumber(QNameValue qname) Get the slot number allocated to a particular variableGet a Stack Frame Map containing definitions of all the declared variables.getURIForPrefix(String prefix, boolean useDefault) Get the namespace URI corresponding to a given prefix.booleanAsk whether undeclared variables are allowed.booleanAsk whether the context item is known to be parentlessGet an iterator over all the prefixes declared in this namespace context.Construct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluation.voidsetAllowUndeclaredVariables(boolean allow) Say whether undeclared variables are allowed.voidsetContextItemParentless(boolean parentless) Say whether the context item is known to be parentless.voidSet the default namespace for elements and typesvoidsetExecutable(Executable exec) voidsetImportedSchema(Schema schema) Add an imported schema to the static contextvoidsetNamespaceResolver(NamespaceResolver resolver) Set an external namespace resolver.voidsetNamespaces(NodeInfo node) Declares all the namespaces that are in-scope for a supplied node, removing all previous namespace declarations.voidsetOptimizerOptions(OptimizerOptions options) Set the optimizer options to be used for compiling expressions that use this static context.voidDeclare the static type of the context item.voidDeclare the static type of the context item.Methods inherited from class net.sf.saxon.sxpath.AbstractStaticContext
addFunctionLibrary, declarePrologNamespace, getConfiguration, getContainingLocation, getDecimalFormatManager, getDefaultCollationName, getDefaultElementNamespace, getDefaultFunctionNamespace, getFunctionLibrary, getKeyManager, getPackageData, getStaticBaseURI, getSystemId, getUnprefixedElementMatchingPolicy, getWarningHandler, getXPathVersion, isInBackwardsCompatibleMode, issueWarning, makeEarlyEvaluationContext, resolveTypeAlias, setBackwardsCompatibilityMode, setBaseURI, setConfiguration, setContainingLocation, setDecimalFormatManager, setDefaultCollationName, setDefaultFunctionLibrary, setDefaultFunctionNamespace, setFunctionLibrary, setPackageData, setSchemaAware, setTypeAlias, setUnprefixedElementMatchingPolicy, setWarningHandler, setWarningHandler, setXPathLanguageLevel
-
Field Details
-
namespaces
-
variables
-
externalResolver
-
requiredContextValueType
-
importedSchema
-
autoDeclare
protected boolean autoDeclare -
executable
-
retainedStaticContext
-
optimizerOptions
-
parentlessContextItem
protected boolean parentlessContextItem
-
-
Constructor Details
-
IndependentContext
public IndependentContext()Create an IndependentContext along with a new (non-schema-aware) Saxon Configuration -
IndependentContext
Create an IndependentContext using a specific Configuration- Parameters:
config- the Saxon configuration to be used
-
IndependentContext
Create an IndependentContext using a specific Configuration- Parameters:
config- the Saxon configuration to be usedversion- the XPath language version (31 = XPath 3.1, 40 = XPath 4.0)
-
IndependentContext
Create a IndependentContext as a copy of another IndependentContext- Parameters:
ic- the IndependentContext to be copied
-
-
Method Details
-
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. This implementation returns the same RetainedStaticContext object each time, which relies on the information in the static context being effectively immutable while the IndependentContext object remains in use.- Specified by:
makeRetainedStaticContextin interfaceStaticContext- Overrides:
makeRetainedStaticContextin classAbstractStaticContext- Returns:
- a RetainedStaticContext object: either a newly created one, or one that is reused from a previous invocation.
-
declareNamespace
Declare a namespace whose prefix can be used in expressions- Parameters:
prefix- The namespace prefix. Must not be null. Supplying "" sets the default element namespace.uri- The namespace URI. Must not be null.
-
setDefaultElementNamespace
Set the default namespace for elements and types- Overrides:
setDefaultElementNamespacein classAbstractStaticContext- Parameters:
uri- the namespace to be used for unprefixed element and type names. The value "" (or NamespaceConstant.NULL) represents the non-namespace
-
clearNamespaces
public void clearNamespaces()Clear all the declared namespaces, except for the standard ones (xml, xsl, saxon). This also resets the default element namespace to the "null" namespace -
clearAllNamespaces
public void clearAllNamespaces()Clear all the declared namespaces, including the standard ones (xml, xslt, saxon). Leave only the XML namespace and the default namespace (xmlns=""). This also resets the default element namespace to the "null" namespace. -
setNamespaces
Declares all the namespaces that are in-scope for a supplied node, removing all previous namespace declarations. In addition, the standard namespaces (xml, xslt, saxon) are declared. This method also sets the default element namespace to be the same as the default namespace for this node.- Parameters:
node- The node whose in-scope namespaces are to be used as the context namespaces. If the node is an attribute, text node, etc, then the namespaces of its parent element are used.
-
setNamespaceResolver
Set an external namespace resolver. If this is set, then all resolution of namespace prefixes is delegated to the external namespace resolver, and namespaces declared individually on this IndependentContext object are ignored.- Parameters:
resolver- the external NamespaceResolver
-
setAllowUndeclaredVariables
public void setAllowUndeclaredVariables(boolean allow) Say whether undeclared variables are allowed. By default, they are not allowed. When undeclared variables are allowed, it is not necessary to predeclare the variables that may be used in the XPath expression; instead, a variable is automatically declared when a reference to the variable is encountered within the expression.- Parameters:
allow- true if undeclared variables are allowed, false if they are not allowed.- Since:
- 9.2
-
isAllowUndeclaredVariables
public boolean isAllowUndeclaredVariables()Ask whether undeclared variables are allowed. By default, they are not allowed. When undeclared variables are allowed, it is not necessary to predeclare the variables that may be used in the XPath expression; instead, a variable is automatically declared when a reference to the variable is encountered within the expression.- Returns:
- true if undeclared variables are allowed, false if they are not allowed.
- Since:
- 9.2
-
declareVariable
Declare a variable. A variable must be declared before an expression referring to it is compiled. The initial value of the variable will be the empty sequence- Parameters:
qname- The name of the variable- Returns:
- an XPathVariable object representing information about the variable that has been declared.
-
declareVariable
Declare a variable. A variable must be declared before an expression referring to it is compiled. The initial value of the variable will be the empty sequence- Parameters:
namespaceURI- The namespace URI of the name of the variable. Supply "" to represent names in no namespace (null is also accepted)localName- The local part of the name of the variable (an NCName)- Returns:
- an XPathVariable object representing information about the variable that has been declared.
-
declareVariable
Declare a variable. A variable must be declared before an expression referring to it is compiled. The initial value of the variable will be the empty sequence- Parameters:
qName- the name of the variable.- Returns:
- an XPathVariable object representing information about the variable that has been declared.
- Since:
- 9.2
-
getExternalVariables
Get an iterator over all the variables that have been declared, either explicitly by an application call on declareVariable(), or implicitly if the optionallowUndeclaredVariablesis set.- Returns:
- an iterator; the objects returned by this iterator will be instances of XPathVariable
- Since:
- 9.2
-
getExternalVariable
Get the declared variable with a given name, if there is one- Parameters:
qName- the name of the required variable- Returns:
- the explicitly or implicitly declared variable with this name if it exists, or null otherwise
- Since:
- 9.2
-
getSlotNumber
Get the slot number allocated to a particular variable- Parameters:
qname- the name of the variable- Returns:
- the slot number, or -1 if the variable has not been declared
-
getNamespaceResolver
Description copied from interface:StaticContextGet a namespace resolver to resolve the namespaces declared in this static context.- Specified by:
getNamespaceResolverin interfaceStaticContext- Returns:
- a namespace resolver.
-
getURIForPrefix
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.- Specified by:
getURIForPrefixin interfaceNamespaceResolver- Parameters:
prefix- the namespace prefixuseDefault- true if the default namespace is to be used when the prefix is ""- Returns:
- the uri for the namespace, or null if the prefix is not in scope. Return "" if the prefix maps to the null namespace.
-
iteratePrefixes
Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate- Specified by:
iteratePrefixesin interfaceNamespaceResolver- Returns:
- an iterator over all the prefixes for which a namespace binding exists, including the zero-length string to represent the null/absent prefix if it is bound
-
bindVariable
Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared. This method is provided for use by the XPath parser, and it should not be called by the user of the API, or overridden, unless variables are to be declared using a mechanism other than the declareVariable method of this class.- Specified by:
bindVariablein interfaceStaticContext- Parameters:
qName- the name of the variable- Returns:
- the resulting variable reference
- Throws:
XPathException- if the variable cannot be bound (has not been declared)
-
getStackFrameMap
Get a Stack Frame Map containing definitions of all the declared variables. This will return a newly created object that the caller is free to modify by adding additional variables, without affecting the static context itself. -
getDeclaredVariables
-
setImportedSchema
Add an imported schema to the static context -
getImportedSchema
Get the imported schema for this static context, if any- Specified by:
getImportedSchemain interfaceStaticContext- Overrides:
getImportedSchemain classAbstractStaticContext- Returns:
- the imported schema, or the MinimalSchema if no schema has been imported
-
setRequiredContextItemType
Declare the static type of the context item. If this type is declared, and if a context item is supplied when the query is invoked, then the context item must conform to this type (no type conversion will take place to force it into this type).- Parameters:
type- the required type of the context item- Since:
- 9.3
-
setRequiredContextValueType
Declare the static type of the context item. If this type is declared, and if a context value is supplied when the query is invoked, then the context value must conform to this type (no type conversion will take place to force it into this type).- Parameters:
type- the required type of the context item- Since:
- 13.0
-
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- Overrides:
getRequiredContextItemTypein classAbstractStaticContext- Returns:
- the required type of the context item
- Since:
- 9.3
-
getRequiredContextValueType
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:
getRequiredContextValueTypein interfaceStaticContext- Overrides:
getRequiredContextValueTypein classAbstractStaticContext- Returns:
- the required type of the context item
- Since:
- 9.3
-
setOptimizerOptions
Set the optimizer options to be used for compiling expressions that use this static context. By default the optimizer options set in theConfigurationare used.- Parameters:
options- the optimizer options to be used
-
getOptimizerOptions
Get the optimizer options being used for compiling expressions that use this static context. By default the optimizer options set in theConfigurationare used.- Specified by:
getOptimizerOptionsin interfaceStaticContext- Returns:
- the optimizer options being used
-
setExecutable
-
getExecutable
-
getColumnNumber
public int getColumnNumber() -
getPublicId
-
getLineNumber
public int getLineNumber() -
isContextItemParentless
public boolean isContextItemParentless()Ask whether the context item is known to be parentless- Returns:
- true if it is known that the context item for evaluating the expression will have no parent
-
setContextItemParentless
public void setContextItemParentless(boolean parentless) Say whether the context item is known to be parentless. This is used for XSD Assertions; it allows a static warning if an XSD assertion attempts to look outside the element being validated.- Parameters:
parentless- true if it is known that the context item for evaluating the expression will have no parent
-