com.saxonica.codegen
Class QueryCompiler

java.lang.Object
  extended by com.saxonica.codegen.QueryCompiler

public class QueryCompiler
extends Object

This class handles the compilation (to Java) of a query


Constructor Summary
QueryCompiler(Configuration config)
          Create a QueryCompiler
 
Method Summary
 File compileQueryToJava(InputStream input, String encoding)
          Compile a query to Java source code
 String getBaseURI()
          Get the static base URI of the query
 String getClassName()
          Get the name of the Java class containing the compiled query
 File getErrorFile()
          Get the file that is used to contain any output from the Java compiler, such as error or warning messages
 File getOutputDirectory()
          Get the output directory used to contain the generated .class files
 String getSuperClassName()
          Get the name of the Java class to be used as the superclass the compiled query.
 boolean isExplain()
          Determine whether explanation of the optimized query has been requested
 boolean isInServletMode()
          Determine whether explanation of the optimized query has been requested
static void main(String[] args)
           
 void runQuery(DynamicQueryContext dqc, Result result)
          Load and run the compiled query.
 void setBaseURI(String baseURI)
          Set the static base URI for the query
 void setClassName(String className)
          Set the name of the Java class to be created to hold the compiled query.
 void setErrorFile(File errorFile)
          Set the file that is used to contain any output from the Java compiler, such as error or warning messages
 void setExplain(boolean explain)
          Set option to explain the optimized query by displaying the abstract syntax tree on System.err
 void setOutputDirectory(File outputDirectory)
          Set the output directory to contain the generated .class files.
 void setServletMode(boolean servlet)
          Set option to generate the compiled query as a servlet
 void setSuperClassName(String className)
          Set the name of the Java class to be used as the superclass the compiled query.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryCompiler

public QueryCompiler(Configuration config)
Create a QueryCompiler

Parameters:
config - the Saxon configuration
Method Detail

setBaseURI

public void setBaseURI(String baseURI)
Set the static base URI for the query

Parameters:
baseURI - the static base URI of the query

getBaseURI

public String getBaseURI()
Get the static base URI of the query

Returns:
the static base URI of the query

setErrorFile

public void setErrorFile(File errorFile)
Set the file that is used to contain any output from the Java compiler, such as error or warning messages

Parameters:
errorFile - the file that is used to contain any output from the Java compiler, such as error or warning messages. If no file is supplied, a file name is constructed by appending ".errors.txt" to the Java file name

getErrorFile

public File getErrorFile()
Get the file that is used to contain any output from the Java compiler, such as error or warning messages

Returns:
the file that is used to contain any output from the Java compiler, such as error or warning messages. If no file was supplied by the user, then before the compilation, the returned value will be null; after the compilation, it will be the name of the file allocated by the system.

setExplain

public void setExplain(boolean explain)
Set option to explain the optimized query by displaying the abstract syntax tree on System.err


isExplain

public boolean isExplain()
Determine whether explanation of the optimized query has been requested


setServletMode

public void setServletMode(boolean servlet)
Set option to generate the compiled query as a servlet


isInServletMode

public boolean isInServletMode()
Determine whether explanation of the optimized query has been requested


setClassName

public void setClassName(String className)
Set the name of the Java class to be created to hold the compiled query. If no class name is specified, the generated class will be named "Query".

Parameters:
className - the fully qualified class name, for example "com.saxonica.compquery.AccountsQuery"

getClassName

public String getClassName()
Get the name of the Java class containing the compiled query

Returns:
the fully qualified class name, for example "com.saxonica.compquery.AccountsQuery"

setSuperClassName

public void setSuperClassName(String className)
Set the name of the Java class to be used as the superclass the compiled query. This can be a user-written subclass of CompiledUserQuery or CompiledQueryServlet, or potentially any other class that contains the methods called by the generated Java code. It is not necessary to supply a superclass; if none is supplied, the superclass will be CompiledQueryServlet if servlet mode is requested, or CompiledUserQuery otherwise.

Parameters:
className - the fully qualified name of the superclass

getSuperClassName

public String getSuperClassName()
Get the name of the Java class to be used as the superclass the compiled query.

Returns:
the fully qualified class name, for example "com.saxonica.compquery.AccountsQuery"

setOutputDirectory

public void setOutputDirectory(File outputDirectory)
Set the output directory to contain the generated .class files.

Parameters:
outputDirectory - the output directory to contain the generated .class files. If no file is supplied for the generated Java source code, then this directory will also be used for the Java source.

getOutputDirectory

public File getOutputDirectory()
Get the output directory used to contain the generated .class files

Returns:
the output directory used to contain the generated .class files

compileQueryToJava

public File compileQueryToJava(InputStream input,
                               String encoding)
                        throws XPathException
Compile a query to Java source code

Parameters:
input - An InputStream giving access to the text of the XQuery query to be compiled, as a stream of octets
encoding - The encoding used to translate characters to octets in the query source. The parameter may be null: in this case the query parser attempts to infer the encoding by inspecting the source, and if that fails, it assumes UTF-8 encoding
Returns:
the file object representing the file that contains the generated Java code
Throws:
XPathException - if any failure occurs compiling the query

runQuery

public void runQuery(DynamicQueryContext dqc,
                     Result result)
              throws MalformedURLException,
                     ClassNotFoundException,
                     InstantiationException,
                     IllegalAccessException,
                     XPathException
Load and run the compiled query. Before calling this method, the Java source code must be compiled with the class files held in the same outputDirectory as the Java source.

Parameters:
dqc - The dynamic query context.
result - The destination for the query output
Throws:
MalformedURLException
ClassNotFoundException
InstantiationException
IllegalAccessException
XPathException

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright (C) Michael H. Kay. All rights reserved.