Package net.sf.saxon
Class Query
- java.lang.Object
-
- net.sf.saxon.Query
-
- Direct Known Subclasses:
JDOMQuery
public class Query extends java.lang.ObjectThis 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
Fields Modifier and Type Field Description protected booleanbackupprotected Configurationconfigprotected booleanexplainprotected java.lang.StringexplainOutputFileNameprotected java.lang.StringmoduleURIResolverClassprotected java.lang.StringoutputFileNameprotected booleanprojectionprotected booleanpullModeprotected java.lang.StringqueryFileNameprotected intrepeatprotected booleanshowTimeprotected java.lang.StringsourceFileNameprotected booleanupdatingprotected java.lang.StringuriResolverClassprotected booleanuseURLsprotected booleanwrapprotected booleanwriteback
-
Constructor Summary
Constructors Constructor Description Query()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbadUsage(java.lang.String name, java.lang.String message)Report incorrect usage of the command line, with a list of the options and arguments that are availableprotected XQueryExpressioncompileQuery(StaticQueryContext staticEnv, java.lang.String queryFileName, boolean useURLs)Compile the queryprotected voiddoQuery(java.lang.String[] args, java.lang.String command)Support method for main program.protected voidexplain(XQueryExpression exp)Explain the results of query compilationprotected ConfigurationgetConfiguration()Get the configuration in useprotected static voidloadAdditionalSchemas(Configuration config, java.lang.String additionalSchemas)static voidmain(java.lang.String[] args)Main program, can be used directly from the command line.protected ConfigurationmakeConfiguration(boolean schemaAware, java.lang.String className)Set the configuration.protected voidparseOptions(java.lang.String[] args, java.lang.String command, DynamicQueryContext dynamicEnv, java.util.Properties outputProps)Parse the options supplied on the command lineprotected voidprocessSource(javax.xml.transform.Source sourceInput, XQueryExpression exp, DynamicQueryContext dynamicEnv)Process the supplied source fileprotected javax.xml.transform.SourceprocessSourceFile(java.lang.String sourceFileName, boolean useURLs)protected static voidquit(java.lang.String message, int code)Exit with a messageprotected voidrunQuery(XQueryExpression exp, DynamicQueryContext dynamicEnv, java.io.OutputStream destination, java.util.Properties outputProps)Run the queryprotected booleantestIfSchemaAware(java.lang.String[] args)Prescan the command line arguments to see if any of them imply use of a schema-aware processor
-
-
-
Field Detail
-
config
protected Configuration config
-
showTime
protected boolean showTime
-
repeat
protected int repeat
-
sourceFileName
protected java.lang.String sourceFileName
-
queryFileName
protected java.lang.String queryFileName
-
useURLs
protected boolean useURLs
-
outputFileName
protected java.lang.String outputFileName
-
moduleURIResolverClass
protected java.lang.String moduleURIResolverClass
-
uriResolverClass
protected java.lang.String uriResolverClass
-
explain
protected boolean explain
-
wrap
protected boolean wrap
-
pullMode
protected boolean pullMode
-
projection
protected boolean projection
-
updating
protected boolean updating
-
writeback
protected boolean writeback
-
backup
protected boolean backup
-
explainOutputFileName
protected java.lang.String explainOutputFileName
-
-
Method Detail
-
makeConfiguration
protected Configuration makeConfiguration(boolean schemaAware, java.lang.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
-
getConfiguration
protected Configuration getConfiguration()
Get the configuration in use- Returns:
- the configuration
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionMain 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:
args- List of arguments supplied on operating system command line- Throws:
java.lang.Exception- Indicates that a compile-time or run-time error occurred
-
doQuery
protected void doQuery(java.lang.String[] args, java.lang.String command)Support method for main program. This support method can also be invoked from subclasses that support the same command line interface- Parameters:
args- the command-line argumentscommand- name of the class, to be used in error messages
-
testIfSchemaAware
protected boolean testIfSchemaAware(java.lang.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
-
parseOptions
protected void parseOptions(java.lang.String[] args, java.lang.String command, DynamicQueryContext dynamicEnv, java.util.Properties outputProps) throws javax.xml.transform.TransformerExceptionParse the options supplied on the command line- Parameters:
args- the command line argumentscommand- the name of the command that was used (for diagnostics only)dynamicEnv- the XQuery dynamic contextoutputProps- the serialization properties- Throws:
javax.xml.transform.TransformerException- if failures occur. Note, the method may also invoke System.exit().
-
loadAdditionalSchemas
protected static void loadAdditionalSchemas(Configuration config, java.lang.String additionalSchemas) throws javax.xml.transform.TransformerException
- Throws:
javax.xml.transform.TransformerException
-
processSourceFile
protected javax.xml.transform.Source processSourceFile(java.lang.String sourceFileName, boolean useURLs) throws javax.xml.transform.TransformerException- Throws:
javax.xml.transform.TransformerException
-
compileQuery
protected XQueryExpression compileQuery(StaticQueryContext staticEnv, java.lang.String queryFileName, boolean useURLs) throws XPathException, java.io.IOException
Compile the query- Parameters:
staticEnv- the static query contextqueryFileName- 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 failsjava.io.IOException- if the query cannot be read
-
explain
protected void explain(XQueryExpression exp) throws java.io.FileNotFoundException, XPathException
Explain the results of query compilation- Parameters:
exp- the compiled expression- Throws:
java.io.FileNotFoundException- if the destination for the explanation doesn't existXPathException- if other failures occur
-
processSource
protected void processSource(javax.xml.transform.Source sourceInput, XQueryExpression exp, DynamicQueryContext dynamicEnv) throws XPathExceptionProcess the supplied source file- Parameters:
sourceInput- the supplied sourceexp- the compiled XQuery expressiondynamicEnv- the dynamic query context- Throws:
XPathException- if processing fails
-
runQuery
protected void runQuery(XQueryExpression exp, DynamicQueryContext dynamicEnv, java.io.OutputStream destination, java.util.Properties outputProps) throws XPathException, java.io.IOException
Run the query- Parameters:
exp- the compiled query expressiondynamicEnv- the dynamic query contextdestination- the destination for serialized resultsoutputProps- serialization properties defining the output format- Throws:
XPathException- if the query failsjava.io.IOException- if input or output fails
-
quit
protected static void quit(java.lang.String message, int code)Exit with a message- Parameters:
message- The message to be outputcode- The result code to be returned to the operating system shell
-
badUsage
protected void badUsage(java.lang.String name, java.lang.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
-
-