net.sf.saxon

Class Query

Known Direct Subclasses:
JDOMQuery

public class Query
extends java.lang.Object

This Query class provides a command-line interface to the Saxon XQuery processor.

The XQuery syntax supported conforms to the W3C XQuery 1.0 drafts.

Author:
Michael H. Kay

Field Summary

protected Configuration
config
protected boolean
explain
protected String
explainOutputFileName
protected String
moduleURIResolverClass
protected String
outputFileName
protected boolean
projection
protected boolean
pullMode
protected String
queryFileName
protected int
repeat
protected boolean
showTime
protected String
sourceFileName
protected String
uriResolverClass
protected boolean
useURLs
protected boolean
wrap

Method Summary

protected void
badUsage(String name, String message)
Report incorrect usage of the command line, with a list of the options and arguments that are available
protected XQueryExpression
compileQuery(StaticQueryContext staticEnv, String queryFileName, boolean useURLs)
Compile the query
protected void
doQuery(args[] , String command)
Support method for main program.
protected void
explain(XQueryExpression exp)
Explain the results of query compilation
protected Configuration
getConfiguration()
Get the configuration in use
static void
main(args[] )
Main program, can be used directly from the command line.
protected Configuration
makeConfiguration(boolean schemaAware, String className)
Set the configuration.
protected void
parseOptions(String[] args, String command, DynamicQueryContext dynamicEnv, Properties outputProps)
Parse the options supplied on the command line
protected void
processSource(Source sourceInput, XQueryExpression exp, DynamicQueryContext dynamicEnv)
Process the supplied source file
protected Source
processSourceFile(String sourceFileName, boolean useURLs)
protected static void
quit(String message, int code)
Exit with a message
protected void
runQuery(XQueryExpression exp, DynamicQueryContext dynamicEnv, OutputStream destination, Properties outputProps)
Run the query
protected boolean
testIfSchemaAware(String[] args)
Prescan the command line arguments to see if any of them imply use of a schema-aware processor

Field Details

config

protected Configuration config

explain

protected boolean explain

explainOutputFileName

protected String explainOutputFileName

moduleURIResolverClass

protected String moduleURIResolverClass

outputFileName

protected String outputFileName

projection

protected boolean projection

pullMode

protected boolean pullMode

queryFileName

protected String queryFileName

repeat

protected int repeat

showTime

protected boolean showTime

sourceFileName

protected String sourceFileName

uriResolverClass

protected String uriResolverClass

useURLs

protected boolean useURLs

wrap

protected boolean wrap

Method Details

badUsage

protected void badUsage(String name,
                        String message)
Report incorrect usage of the command line, with a list of the options and arguments that are available
Parameters:
name - The name of the command being executed (allows subclassing)
message - The error message

compileQuery

protected XQueryExpression compileQuery(StaticQueryContext staticEnv,
                                        String queryFileName,
                                        boolean useURLs)
            throws XPathException,
                   IOException
Compile the query
Parameters:
staticEnv - the static query context
queryFileName - the filename holding the query (or "-" for the standard input)
useURLs - true if the filename is in the form of a URI
Returns:
the compiled query
Throws:
XPathException - if query compilation fails

doQuery

protected void doQuery(args[] ,
                       String command)
Support method for main program. This support method can also be invoked from subclasses that support the same command line interface
Parameters:
command - name of the class, to be used in error messages

explain

protected void explain(XQueryExpression exp)
            throws FileNotFoundException,
                   XPathException
Explain the results of query compilation
Parameters:
exp - the compiled expression
Throws:
XPathException - if other failures occur

getConfiguration

protected Configuration getConfiguration()
Get the configuration in use
Returns:
the configuration

main

public static void main(args[] )
            throws Exception
Main program, can be used directly from the command line.

The format is:

java net.sf.saxon.Query [options] query-file >output-file

followed by any number of parameters in the form {keyword=value}... which can be referenced from within the query.

This program executes the query in query-file.

Parameters:

makeConfiguration

protected Configuration makeConfiguration(boolean schemaAware,
                                          String className)
Set the configuration. This is designed to be overridden in a subclass
Parameters:
schemaAware - true if a schema-aware configuration is required (in this case Saxon-SA must be installed and licensed)
className - the name of the class to be loaded, representing the Configuration. This allows additional control of the loading process under .NET
Returns:
the successfully loaded Configuration

parseOptions

protected void parseOptions(String[] args,
                            String command,
                            DynamicQueryContext dynamicEnv,
                            Properties outputProps)
            throws TransformerException
Parse the options supplied on the command line
Parameters:
args - the command line arguments
command - the name of the command that was used (for diagnostics only)
dynamicEnv - the XQuery dynamic context
outputProps - the serialization properties

processSource

protected void processSource(Source sourceInput,
                             XQueryExpression exp,
                             DynamicQueryContext dynamicEnv)
            throws XPathException
Process the supplied source file
Parameters:
sourceInput - the supplied source
exp - the compiled XQuery expression
dynamicEnv - the dynamic query context
Throws:
XPathException - if processing fails

processSourceFile

protected Source processSourceFile(String sourceFileName,
                                   boolean useURLs)
            throws TransformerException

quit

protected static void quit(String message,
                           int code)
Exit with a message
Parameters:
message - The message to be output
code - The result code to be returned to the operating system shell

runQuery

protected void runQuery(XQueryExpression exp,
                        DynamicQueryContext dynamicEnv,
                        OutputStream destination,
                        Properties outputProps)
            throws XPathException,
                   IOException
Run the query
Parameters:
exp - the compiled query expression
dynamicEnv - the dynamic query context
destination - the destination for serialized results
outputProps - serialization properties defining the output format
Throws:
XPathException - if the query fails

testIfSchemaAware

protected boolean testIfSchemaAware(String[] args)
Prescan the command line arguments to see if any of them imply use of a schema-aware processor
Parameters:
args - the command line arguments
Returns:
true if a schema-aware processor is needed