net.sf.saxon.xpath
Class StandaloneContext

java.lang.Object
  |
  +--net.sf.saxon.xpath.StandaloneContext
All Implemented Interfaces:
StaticContext

public class StandaloneContext
extends java.lang.Object
implements StaticContext

A StandaloneContext provides a context for parsing an expression or pattern appearing in a context other than a stylesheet.


Constructor Summary
StandaloneContext()
          Create a StandaloneContext using the default Configuration and NamePool
StandaloneContext(Configuration config)
          Create a StandaloneContext using a specific NamePool
StandaloneContext(NodeInfo node)
          Create a StandaloneContext using a specific Node.
 
Method Summary
 Expression bindFunction(java.lang.String qname, Expression[] arguments)
          Identify a (namespace-prefixed) function appearing in the expression
 VariableDeclaration bindVariable(int fingerprint)
          Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared.
 void clearAllNamespaces()
          Clear all the declared namespaces, including the standard ones (xml, xslt, saxon).
 void clearNamespaces()
          Clear all the declared namespaces, except for the standard ones (xml, xslt, saxon, xdt)
 void declareCollation(java.lang.String name, java.util.Comparator comparator, boolean isDefault)
          Declare a named collation
 void declareNamespace(java.lang.String prefix, java.lang.String uri)
          Declare a namespace whose prefix can be used in expressions
 Variable declareVariable(java.lang.String qname, java.lang.Object initialValue)
          Declare a variable.
 java.lang.String getBaseURI()
          Get the Base URI of the stylesheet element, for resolving any relative URI's used in the expression.
 java.util.Comparator getCollation(java.lang.String name)
          Get a named collation.
 Configuration getConfiguration()
          Get the system configuration
 java.lang.String getDefaultCollationName()
          Get the name of the default collation.
 short getDefaultElementNamespace()
          Get the default XPath namespace, as a namespace code that can be looked up in the NamePool
 int getLineNumber()
          Get the line number of the expression within that container.
 NamePool getNamePool()
          Get the NamePool used for compiling expressions
protected  int getNumberOfVariables()
          Determine the number of variables that have been declared
 java.lang.String getSystemId()
          Get the system ID of the container of the expression.
 java.lang.String getURIForPrefix(java.lang.String prefix)
          Get the URI for a prefix, using the declared namespaces as the context for namespace resolution.
 boolean isImportedSchema(java.lang.String namespace)
          Determine whether a Schema for a given target namespace has been imported
 boolean isInBackwardsCompatibleMode()
          Determine whether Backwards Compatible Mode is used
 void issueWarning(java.lang.String s)
          Issue a compile-time warning.
 void setNamespaces(NodeInfo node)
          Set all the declared namespaces to be the namespaces that are in-scope for a given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandaloneContext

public StandaloneContext()
Create a StandaloneContext using the default Configuration and NamePool


StandaloneContext

public StandaloneContext(Configuration config)
Create a StandaloneContext using a specific NamePool


StandaloneContext

public StandaloneContext(NodeInfo node)
Create a StandaloneContext using a specific Node. This node is used to initialize the NamePool and also to establish the initial set of in-scope namespaces

Method Detail

getConfiguration

public Configuration getConfiguration()
Get the system configuration

Specified by:
getConfiguration in interface StaticContext

declareNamespace

public void declareNamespace(java.lang.String prefix,
                             java.lang.String uri)
Declare a namespace whose prefix can be used in expressions

Parameters:
prefix - The namespace prefix. Must not be null. Must not be the empty string ("") - unqualified names in an XPath expression always refer to the null namespace.
uri - The namespace URI. Must not be null.

clearNamespaces

public void clearNamespaces()
Clear all the declared namespaces, except for the standard ones (xml, xslt, saxon, xdt)


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="")


setNamespaces

public void setNamespaces(NodeInfo node)
Set all the declared namespaces to be the namespaces that are in-scope for a given node. In addition, the standard namespaces (xml, xslt, saxon) are declared.

Parameters:
node - The node whose in-scope namespaces are to be used as the context namespaces. Note that this will have no effect unless this node is an element.

declareCollation

public void declareCollation(java.lang.String name,
                             java.util.Comparator comparator,
                             boolean isDefault)
Declare a named collation

Parameters:
name - The name of the collation (technically, a URI)
comparator - The Java Comparator used to implement the collating sequence
isDefault - True if this is to be used as the default collation

declareVariable

public Variable declareVariable(java.lang.String qname,
                                java.lang.Object initialValue)
                         throws XPathException
Declare a variable. A variable must be declared before an expression referring to it is compiled.

XPathException

getNamePool

public NamePool getNamePool()
Get the NamePool used for compiling expressions

Specified by:
getNamePool in interface StaticContext

issueWarning

public void issueWarning(java.lang.String s)
Issue a compile-time warning. This method is used during XPath expression compilation to output warning conditions. The default implementation writes the message to System.err. To change the destination of messages, create a subclass of StandaloneContext that overrides this method.

Specified by:
issueWarning in interface StaticContext

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 interface StaticContext
Returns:
"" always

getBaseURI

public java.lang.String getBaseURI()
Get the Base URI of the stylesheet element, for resolving any relative URI's used in the expression. Used by the document() function.

Specified by:
getBaseURI in interface StaticContext
Returns:
"" always

getLineNumber

public int getLineNumber()
Get the line number of the expression within that container. Used to construct error messages.

Specified by:
getLineNumber in interface StaticContext
Returns:
-1 always

getURIForPrefix

public java.lang.String getURIForPrefix(java.lang.String prefix)
                                 throws XPathException
Get the URI for a prefix, using the declared namespaces as the context for namespace resolution. This method is provided for use by the XPath parser.

Specified by:
getURIForPrefix in interface StaticContext
Parameters:
prefix - The prefix
Throws:
XPathException - if the prefix is not declared

bindVariable

public VariableDeclaration bindVariable(int fingerprint)
                                 throws XPathException
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:
bindVariable in interface StaticContext
XPathException

getNumberOfVariables

protected int getNumberOfVariables()
Determine the number of variables that have been declared


bindFunction

public Expression bindFunction(java.lang.String qname,
                               Expression[] arguments)
                        throws XPathException
Identify a (namespace-prefixed) function appearing in the expression

Specified by:
bindFunction in interface StaticContext
Returns:
an Expression representing the function call. This will normally be a FunctionCall, but it may be rewritten as some other expression.
Throws:
XPathException - if the function is not in scope (note, this doesn't happen in XSLT, where a reference to an unknown function is a dynamic error).

getCollation

public java.util.Comparator getCollation(java.lang.String name)
Get a named collation.

Specified by:
getCollation in interface StaticContext
Parameters:
name - The name of the required collation. Supply null to get the default collation.
Returns:
the collation identified by the given name, as set previously using declareCollation. Return null if no collation with this name is found.

getDefaultCollationName

public java.lang.String getDefaultCollationName()
Get the name of the default collation.

Specified by:
getDefaultCollationName in interface StaticContext
Returns:
the name of the default collation; or the name of the codepoint collation if no default collation has been defined

getDefaultElementNamespace

public short getDefaultElementNamespace()
Get the default XPath namespace, as a namespace code that can be looked up in the NamePool

Specified by:
getDefaultElementNamespace in interface StaticContext

isInBackwardsCompatibleMode

public boolean isInBackwardsCompatibleMode()
Determine whether Backwards Compatible Mode is used

Specified by:
isInBackwardsCompatibleMode in interface StaticContext
Returns:
false; XPath 1.0 compatibility mode is not supported in the standalone XPath API

isImportedSchema

public boolean isImportedSchema(java.lang.String namespace)
Description copied from interface: StaticContext
Determine whether a Schema for a given target namespace has been imported

Specified by:
isImportedSchema in interface StaticContext