com.saxonica.deploy
Class CompiledQueryServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.saxonica.deploy.CompiledQueryServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class CompiledQueryServlet
extends javax.servlet.http.HttpServlet

This abstract class acts as a superclass for every query generated by the Saxon code generator in servlet mode. In this mode the generated code is thread-safe: it is possible to have a single instance of the class running in multiple threads concurrently.

It is possible to define a user-defined subclass of this class that specializes the behaviour of the init() and service() methods. When a query is compiled, the -superclass option on the command line determines the immediate superclass of the compiled code. Such a class will be needed, for example, if different queries are to share access to the same in-memory documents.

During servlet initialization, the init() method attempts to determine whether the servlet context includes an attribute named com.saxonica.servlet.applicationdata that is an instance of the interface SharedApplicationDataHandler. If this object exists, it is called on each servlet request, at which point it has the opportunity to configure the Controller for the query execution, for example by supplying parameter values, setting a URIResolver, or otherwise.

If no SharedApplicationDataHandler object is available, external variables for the query can be specified as query parameters in the request URL. The names of query parameters are taken as local names of no-namespace variables, and the values are treated as UntypedAtomic strings (which will be converted to the declared type of the variable if necessary). Any query parameters that do not correspond to declared external variables in the query will be ignored.

See Also:
Serialized Form

Constructor Summary
CompiledQueryServlet()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Run the query as a servlet
 Configuration getConfiguration()
          Get the Configuration.
 Executable getExecutable()
          Get the Executable.
 void init()
          Servlet initialization method
abstract  void initializeGlobals()
          Run the query-specific initialization code.
abstract  void process(XPathContext context)
          Run the query, sending the results to the current output destination.
 void setConfiguration(Configuration config)
          Supply the configuration in which the query will be executed.
 
Methods inherited from class javax.servlet.http.HttpServlet
service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, log, log
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompiledQueryServlet

public CompiledQueryServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Servlet initialization method

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

initializeGlobals

public abstract void initializeGlobals()
                                throws XPathException
Run the query-specific initialization code. This method is present in each compiled query.

Throws:
XPathException

setConfiguration

public final void setConfiguration(Configuration config)
Supply the configuration in which the query will be executed. Note that this is not required to be the same as the configuration under which the query was compiled. However, any schemas that are present in the run-time configuration must be unchanged from the versions that were used at compile time. If no configuration is supplied then the query will run with a default configuration.

This method should be called during initialization by the init() method. If a user-defined subclass of CompiledQueryServlet is in use, the subclass may call this method directly. In the absence of such a class, the default implementation will call the SharedApplicationDataHandler to supply a Configuration; and in the absence of SharedApplicationDataHandler it will construct a Configuration specific to this servlet instance.

Parameters:
config - the Configuration to be used. If the query is schema-aware, this must be an instance of SchemaAwareConfiguration

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException,
                  IOException
Run the query as a servlet

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

getConfiguration

public final Configuration getConfiguration()
Get the Configuration. This method is provided for use by the compiled query code.

Returns:
the configuration in use.

getExecutable

public Executable getExecutable()
Get the Executable. This method is provided for use by the compiled query code.

Returns:
the Executable in use.

process

public abstract void process(XPathContext context)
                      throws XPathException
Run the query, sending the results to the current output destination. This method is provided in each compiled query.

Throws:
XPathException


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