com.lotus.xsl
Class QueryEngine

java.lang.Object
  |
  +--com.lotus.xsl.QueryEngine

public class QueryEngine
extends java.lang.Object

This class queries a DOM tree, and performs other services relating to XSL Expressions such as pattern matching. The engine primarily does a a level-order traversal of the node tree from the given context (as opposed to a preorder traversal... the position(), count(), and last() functions along with multiple predicates make this hard), based upon the given XSL pattern, collecting the nodes into a vector. It uses the token structure in raw form, sliding up and down the token structure as it traverses and recursis into the nodes. The design hypothesis used is that the optimization gained by pre-tokenizing into a bunch of intelligent objects, as can be seen in some other XSL designs (including some previous incarnations of this engine), can actually be counter-productive in web-sized documents. In other words, I -tried- to keep it very simple and not allocate a bunch of objects along the way. From the experience so far, I'm not happy with the performance, so maybe my hypothesis is somewhat flawed. It looks like I will probably need to create some sort of smart token queue somewhat akin to compiled code, which I can then return to the caller.


Field Summary
static int CLASS_BOOLEAN
           
static int CLASS_DONTCARE
           
static int CLASS_NODESET
           
static int CLASS_NULL
           
static int CLASS_NUMBER
           
static int CLASS_RTREEFRAG
           
static int CLASS_STRING
           
static boolean m_debug
          If this is true, extra programmer error checks will be made.
static boolean m_trace
          If m_trace is set to true, trace strings will be written out to System.out.
static int MATCH_SCORE_NODETEST
          The match score if the pattern consists of just a NodeTest.
static int MATCH_SCORE_NONE
          The match score if no match is made.
static int MATCH_SCORE_OTHER
          The match score if the pattern consists of something other than just a NodeTest or just a qname.
static int MATCH_SCORE_QNAME
          The match score if the pattern has the form of a QName optionally preceded by an @ character.
 
Method Summary
 com.lotus.xsl.NodeListImpl AbsoluteLocationPath(com.lotus.xsl.Node context, com.lotus.xsl.NodeListImpl queryResults, boolean isURI)
          -------------------------------------------------------------------------------- AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath --------------------------------------------------------------------------------
 boolean booleanCast(java.lang.Object obj)
          Cast result object to a boolean.
 java.lang.Object castToType(java.lang.Object obj, int t)
          Cast object to type t.
 void error(com.lotus.xsl.Node sourceNode, java.lang.String msg)
          Tell the user of an error, and probably throw an exception.
 void error(java.lang.String msg)
          Tell the user of an error, and probably throw an exception.
 com.lotus.xsl.Node findAncestor(java.lang.String matchPatternString, com.lotus.xsl.Node context, com.lotus.xsl.Element namespaceContext)
          Given a match pattern and a context, find the first ancestor that matches the pattern (including the context handed in).
 int getClassType(java.lang.Object obj)
          Given an expression object, return what type of class it is...
 com.lotus.xsl.Document getDocByURL(com.lotus.xsl.Node context, java.lang.String url)
          Get a document identified by a URL, parsing it if necessary.
 com.lotus.xsl.Element getElementByID(com.lotus.xsl.Node context, java.lang.String id)
          Get a document identified by a URL, parsing it if necessary.
 java.lang.Object getExpr(Expression expression, com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext, com.lotus.xsl.NodeList contextNodeList)
          Given an expression and a context, return the result, without casting to any specific type.
 java.lang.Object getExpr(java.lang.String expression, com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext, com.lotus.xsl.NodeList contextNodeList)
          Given an expression and a context, return the result, without casting to any specific type.
 java.lang.String getStringExpr(java.lang.String expression, com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext)
          Given an expression and a context, return the results in a string.
 java.util.Vector getTargetElementStrings(java.lang.String expression, com.lotus.xsl.Element namespaceContext)
          Returns a vector of target element strings.
 java.util.Vector getTargetElementStrings(java.lang.String expression, com.lotus.xsl.Element namespaceContext, Expression[] expressionHolder)
          Returns a vector of target element strings.
 boolean isNodeAfter(com.lotus.xsl.Node node1, com.lotus.xsl.Node node2)
          Figure out if node2 should be placed after node1 when placing nodes in a list that is to be sorted in document order.
 double matchAgainstPatterns(Expression expression, com.lotus.xsl.Node node, com.lotus.xsl.Element namespaceContext)
          Match a node against a list of ancestryPatterns.
 double matchAgainstPatterns(java.lang.String expression, com.lotus.xsl.Node node, com.lotus.xsl.Element namespaceContext)
          Match a node against a list of ancestryPatterns.
 java.util.Vector nodelistCast(java.lang.Object obj)
          Cast result object to a nodelist.
 double numberCast(java.lang.Object obj)
          Cast result object to a number.
 com.lotus.xsl.NodeList query(Expression expression, com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext)
          Given a select pattern, query a DOM for elements and/or attributes.
 com.lotus.xsl.NodeList query(com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext)
          Given a select pattern, query a DOM for elements and/or attributes.
 com.lotus.xsl.NodeList query(java.lang.String expression, com.lotus.xsl.Node contextNode, com.lotus.xsl.Element namespaceContext)
          Given a select pattern, query a DOM for elements and/or attributes.
 com.lotus.xsl.DocumentFragment rtreefragCast(java.lang.Object obj)
          Cast result object to a result tree fragment.
 java.lang.String stringCast(java.lang.Object obj)
          Cast result object to a string.
 void warn(com.lotus.xsl.Node sourceNode, java.lang.String msg)
          Warn the user of an problem.
 void warn(java.lang.String msg)
          Warn the user of an problem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_debug

public static final boolean m_debug
If this is true, extra programmer error checks will be made.

m_trace

public static final boolean m_trace
If m_trace is set to true, trace strings will be written out to System.out.

MATCH_SCORE_NONE

public static final int MATCH_SCORE_NONE
The match score if no match is made.

MATCH_SCORE_QNAME

public static final int MATCH_SCORE_QNAME
The match score if the pattern has the form of a QName optionally preceded by an @ character.

MATCH_SCORE_NODETEST

public static final int MATCH_SCORE_NODETEST
The match score if the pattern consists of just a NodeTest.

MATCH_SCORE_OTHER

public static final int MATCH_SCORE_OTHER
The match score if the pattern consists of something other than just a NodeTest or just a qname.

CLASS_NULL

public static final int CLASS_NULL

CLASS_DONTCARE

public static final int CLASS_DONTCARE

CLASS_BOOLEAN

public static final int CLASS_BOOLEAN

CLASS_NUMBER

public static final int CLASS_NUMBER

CLASS_STRING

public static final int CLASS_STRING

CLASS_NODESET

public static final int CLASS_NODESET

CLASS_RTREEFRAG

public static final int CLASS_RTREEFRAG
Method Detail

query

public com.lotus.xsl.NodeList query(Expression expression,
                                    com.lotus.xsl.Node contextNode,
                                    com.lotus.xsl.Element namespaceContext)
                             throws XSLProcessorException,
                                    java.net.MalformedURLException,
                                    java.io.FileNotFoundException,
                                    java.io.IOException
Given a select pattern, query a DOM for elements and/or attributes. This works exactly the opposite of matchAgainstPattern, which starts from the target node and marches inward and outward, qualifying the element matches. Instead, this function starts from the anchor and marches left to right, traversing the tree until it finds the target node (which it then qualifies the same as matchAgainstPattern).
Parameters:
expression - The select expression.
contextNode - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

query

public com.lotus.xsl.NodeList query(java.lang.String expression,
                                    com.lotus.xsl.Node contextNode,
                                    com.lotus.xsl.Element namespaceContext)
                             throws XSLProcessorException,
                                    java.net.MalformedURLException,
                                    java.io.FileNotFoundException,
                                    java.io.IOException
Given a select pattern, query a DOM for elements and/or attributes. This works exactly the opposite of matchAgainstPattern, which starts from the target node and marches inward and outward, qualifying the element matches. Instead, this function starts from the anchor and marches left to right, traversing the tree until it finds the target node (which it then qualifies the same as matchAgainstPattern).
Parameters:
expression - The select expression.
contextNode - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

query

public com.lotus.xsl.NodeList query(com.lotus.xsl.Node contextNode,
                                    com.lotus.xsl.Element namespaceContext)
                             throws XSLProcessorException,
                                    java.net.MalformedURLException,
                                    java.io.FileNotFoundException,
                                    java.io.IOException
Given a select pattern, query a DOM for elements and/or attributes. This works exactly the opposite of matchAgainstPattern, which starts from the target node and marches inward and outward, qualifying the element matches. Instead, this function starts from the anchor and marches left to right, traversing the tree until it finds the target node (which it then qualifies the same as matchAgainstPattern).
Parameters:
expression - The select expression.
contextNode - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

getTargetElementStrings

public java.util.Vector getTargetElementStrings(java.lang.String expression,
                                                com.lotus.xsl.Element namespaceContext,
                                                Expression[] expressionHolder)
                                         throws XSLProcessorException,
                                                java.net.MalformedURLException,
                                                java.io.FileNotFoundException,
                                                java.io.IOException
Returns a vector of target element strings. If the input is "foo", return {"foo"}. If the input is "foo | doo", return {"foo", "doo"}. If the input is "x/foo", return {"foo"}. If the input is "x/foo | z/foo", return {"foo"} -- NOTE the two element names are combined! If the input is "id(xx)/x//z[@aName]//foo[zz]", return {"foo"}. If the input is "id(xx)/x//z[@aName]//foo[zz] | roo/foo", return {"foo"}. If the input is "id(xx)/x//z[@aName]//foo[zz] | roo/doo", return {"foo", "doo"}. If the input is "id(xx)/x//z[@aName]//*[zz]", return {"*"}.
Parameters:
pattern - Valid XSL pattern expression.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

getTargetElementStrings

public java.util.Vector getTargetElementStrings(java.lang.String expression,
                                                com.lotus.xsl.Element namespaceContext)
                                         throws XSLProcessorException,
                                                java.net.MalformedURLException,
                                                java.io.FileNotFoundException,
                                                java.io.IOException
Returns a vector of target element strings. If the input is "foo", return {"foo"}. If the input is "foo | doo", return {"foo", "doo"}. If the input is "x/foo", return {"foo"}. If the input is "x/foo | z/foo", return {"foo"} -- NOTE the two element names are combined! If the input is "id(xx)/x//z[@aName]//foo[zz]", return {"foo"}. If the input is "id(xx)/x//z[@aName]//foo[zz] | roo/foo", return {"foo"}. If the input is "id(xx)/x//z[@aName]//foo[zz] | roo/doo", return {"foo", "doo"}. If the input is "id(xx)/x//z[@aName]//*[zz]", return {"*"}.
Parameters:
pattern - Valid XSL pattern expression.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

matchAgainstPatterns

public double matchAgainstPatterns(Expression expression,
                                   com.lotus.xsl.Node node,
                                   com.lotus.xsl.Element namespaceContext)
                            throws XSLProcessorException,
                                   java.net.MalformedURLException,
                                   java.io.FileNotFoundException,
                                   java.io.IOException
Match a node against a list of ancestryPatterns.
Parameters:
expression - The select expression.
node - The node that is being tested.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

matchAgainstPatterns

public double matchAgainstPatterns(java.lang.String expression,
                                   com.lotus.xsl.Node node,
                                   com.lotus.xsl.Element namespaceContext)
                            throws XSLProcessorException,
                                   java.net.MalformedURLException,
                                   java.io.FileNotFoundException,
                                   java.io.IOException
Match a node against a list of ancestryPatterns.
Parameters:
expression - The select expression.
node - The node that is being tested.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

findAncestor

public com.lotus.xsl.Node findAncestor(java.lang.String matchPatternString,
                                       com.lotus.xsl.Node context,
                                       com.lotus.xsl.Element namespaceContext)
                                throws XSLProcessorException,
                                       java.net.MalformedURLException,
                                       java.io.FileNotFoundException,
                                       java.io.IOException
Given a match pattern and a context, find the first ancestor that matches the pattern (including the context handed in).
Parameters:
matchPatternString - The match pattern.
node - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

getStringExpr

public java.lang.String getStringExpr(java.lang.String expression,
                                      com.lotus.xsl.Node contextNode,
                                      com.lotus.xsl.Element namespaceContext)
                               throws XSLProcessorException,
                                      java.net.MalformedURLException,
                                      java.io.FileNotFoundException,
                                      java.io.IOException
Given an expression and a context, return the results in a string.
Parameters:
expression - The string expression.
node - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

getExpr

public java.lang.Object getExpr(java.lang.String expression,
                                com.lotus.xsl.Node contextNode,
                                com.lotus.xsl.Element namespaceContext,
                                com.lotus.xsl.NodeList contextNodeList)
                         throws XSLProcessorException,
                                java.net.MalformedURLException,
                                java.io.FileNotFoundException,
                                java.io.IOException
Given an expression and a context, return the result, without casting to any specific type.
Parameters:
expression - The expression.
node - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

getExpr

public java.lang.Object getExpr(Expression expression,
                                com.lotus.xsl.Node contextNode,
                                com.lotus.xsl.Element namespaceContext,
                                com.lotus.xsl.NodeList contextNodeList)
                         throws XSLProcessorException,
                                java.net.MalformedURLException,
                                java.io.FileNotFoundException,
                                java.io.IOException
Given an expression and a context, return the result, without casting to any specific type.
Parameters:
expression - The expression.
node - The node that "." expresses.
namespaceContext - The context in which namespaces in the queries are supposed to be expanded.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

AbsoluteLocationPath

public com.lotus.xsl.NodeListImpl AbsoluteLocationPath(com.lotus.xsl.Node context,
                                                       com.lotus.xsl.NodeListImpl queryResults,
                                                       boolean isURI)
                                                throws XSLProcessorException,
                                                       java.net.MalformedURLException,
                                                       java.io.FileNotFoundException,
                                                       java.io.IOException
-------------------------------------------------------------------------------- AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath --------------------------------------------------------------------------------
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

isNodeAfter

public boolean isNodeAfter(com.lotus.xsl.Node node1,
                           com.lotus.xsl.Node node2)
Figure out if node2 should be placed after node1 when placing nodes in a list that is to be sorted in document order. Assumes that node1 and node2 are not equal. NOTE: Make sure this does the right thing with attribute nodes!!!
Returns:
true if node2 should be placed after node1, and false if node2 should be placed before node1.

getDocByURL

public com.lotus.xsl.Document getDocByURL(com.lotus.xsl.Node context,
                                          java.lang.String url)
                                   throws XSLProcessorException,
                                          java.net.MalformedURLException,
                                          java.io.FileNotFoundException,
                                          java.io.IOException
Get a document identified by a URL, parsing it if necessary.

getElementByID

public com.lotus.xsl.Element getElementByID(com.lotus.xsl.Node context,
                                            java.lang.String id)
                                     throws XSLProcessorException,
                                            java.net.MalformedURLException,
                                            java.io.FileNotFoundException,
                                            java.io.IOException
Get a document identified by a URL, parsing it if necessary.

getClassType

public int getClassType(java.lang.Object obj)
Given an expression object, return what type of class it is...

numberCast

public double numberCast(java.lang.Object obj)
Cast result object to a number.

booleanCast

public boolean booleanCast(java.lang.Object obj)
Cast result object to a boolean.

stringCast

public java.lang.String stringCast(java.lang.Object obj)
Cast result object to a string.

rtreefragCast

public com.lotus.xsl.DocumentFragment rtreefragCast(java.lang.Object obj)
Cast result object to a result tree fragment.

nodelistCast

public java.util.Vector nodelistCast(java.lang.Object obj)
Cast result object to a nodelist.

castToType

public java.lang.Object castToType(java.lang.Object obj,
                                   int t)
Cast object to type t.

warn

public void warn(java.lang.String msg)
          throws QueryEngineException
Warn the user of an problem.

warn

public void warn(com.lotus.xsl.Node sourceNode,
                 java.lang.String msg)
          throws QueryEngineException
Warn the user of an problem.

error

public void error(java.lang.String msg)
           throws QueryEngineException
Tell the user of an error, and probably throw an exception.

error

public void error(com.lotus.xsl.Node sourceNode,
                  java.lang.String msg)
           throws QueryEngineException
Tell the user of an error, and probably throw an exception.