net.sf.saxon.query
Class QueryProcessor

java.lang.Object
  extended by net.sf.saxon.query.QueryProcessor

public class QueryProcessor
extends Object

A QueryProcessor allows the compilation of XQuery queries for subsequent execution. Compilation consists of parsing, static analysis, optimization, and creation of an internal representation of the query for subsequent evaluation.

The compilation of a query takes context information from a static context, which is represented by a StaticQueryContext object. This provides the necessary information about collations, base URI, etc.


Constructor Summary
QueryProcessor(StaticQueryContext env)
          Default constructor.
 
Method Summary
 DocumentInfo buildDocument(Source source)
          Convenience method for building Saxon's internal representation of a source XML document.
 XQueryExpression compileQuery(Reader source)
          Prepare an XQuery query for subsequent evaluation.
 XQueryExpression compileQuery(String query)
          Prepare an XQuery query for subsequent evaluation.
 Configuration getConfiguration()
          Get the configuration
 StaticQueryContext getStaticContext()
          Get the current static context
 void setConfiguration(Configuration config)
          Set the configuration.
 void setStaticContext(StaticQueryContext context)
          Set the static context for compiling XQuery expressions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryProcessor

public QueryProcessor(StaticQueryContext env)
Default constructor.

Method Detail

buildDocument

public DocumentInfo buildDocument(Source source)
                           throws XPathException
Convenience method for building Saxon's internal representation of a source XML document. The document will be built using the default NamePool, which means that any process that uses it must also use the default NamePool.

Parameters:
source - Any javax.xml.transform.Source object representing the document against which queries will be executed. Note that a Saxon DocumentInfo (indeed any NodeInfo) can be used as a Source. To use a third-party DOM Document as a source, create an instance of javax.xml.transform.dom.DOMSource to wrap it. Note that this currently creates a copy of the document, and any NodeInfo returned as a result of an expression will be a reference to the copy, not to the original node.
Returns:
the DocumentInfo representing the root node of the resulting document object.
Throws:
XPathException

setStaticContext

public void setStaticContext(StaticQueryContext context)
Set the static context for compiling XQuery expressions. This provides control over the environment in which the query is compiled, for example it allows namespace prefixes to be declared, variables to be bound and functions to be defined. For most purposes, the static context can be defined by providing and tailoring an instance of the StandaloneContext class. Until this method is called, a default query context is used, in which no namespaces are defined other than the standard ones (xml, xslt, and saxon), and no variables or functions (other than the core XPath functions) are available.


getStaticContext

public StaticQueryContext getStaticContext()
Get the current static context


setConfiguration

public void setConfiguration(Configuration config)
Set the configuration. The configuration contains parameters that affect the way the query is compiled and executed.


getConfiguration

public Configuration getConfiguration()
Get the configuration


compileQuery

public XQueryExpression compileQuery(String query)
                              throws XPathException
Prepare an XQuery query for subsequent evaluation. The source text of the query is supplied as a String. The base URI of the query is taken from the static context, and defaults to the current working directory.

Parameters:
query - The XQuery query to be evaluated, supplied as a string.
Returns:
an XQueryExpression object representing the prepared expression
Throws:
XPathException - if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared, or contains other static errors.

compileQuery

public XQueryExpression compileQuery(Reader source)
                              throws XPathException,
                                     IOException
Prepare an XQuery query for subsequent evaluation. The Query is supplied in the form of a Reader. The base URI of the query is taken from the static context, and defaults to the current working directory.

Parameters:
source - A Reader giving access to the text of the XQuery query to be compiled.
Returns:
an XPathExpression object representing the prepared expression.
Throws:
XPathException - if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared, or any other static error is reported.
IOException - if a failure occurs reading the supplied input.