org.apache.commons.jxpath.ri.axes
Class SimplePathInterpreter

java.lang.Object
  extended byorg.apache.commons.jxpath.ri.axes.SimplePathInterpreter

public class SimplePathInterpreter
extends java.lang.Object

An evaluation mechanism for simple XPaths, which is much faster than the usual process. It is only used for xpaths which have no context-dependent parts, consist entirely of child::name and self::node() steps with predicates that either integer or have the form [@name = ...].

Version:
$Revision: 1.10 $ $Date: 2002/04/24 04:05:40 $
Author:
Dmitri Plotnikov

Field Summary
private static int PERFECT_MATCH
           
private static QName QNAME_NAME
           
 
Constructor Summary
SimplePathInterpreter()
           
 
Method Summary
private static int computeQuality(NodePointer pointer)
          For a pointer that matches an actual node, returns 0.
private static NodePointer createChildPointerForStep(PropertyOwnerPointer parentPointer, Step step)
           
static NodePointer createNullPointer(EvalContext context, NodePointer parent, Step[] steps, int currentStep)
          Creates a "null pointer" that a) represents the requested path and b) can be used for creation of missing nodes in the path.
private static NodePointer createNullPointerForPredicates(EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate)
          Creates a "null pointer" that starts with predicates.
private static NodePointer doPredicate(EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate)
          Evaluates predicates and proceeds with the subsequent steps of the path.
private static NodePointer doPredicateIndex(EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate)
          Evaluate a subscript predicate: see if the node is a collection and if the index is inside the collection
private static NodePointer doPredicateName(EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate)
           
private static NodePointer doPredicatesStandard(EvalContext context, java.util.List parents, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate)
          Called exclusively for standard InfoSet nodes, e.g.
private static NodePointer doStep(EvalContext context, NodePointer parent, Step[] steps, int currentStep)
          Recursive evaluation of a path.
private static NodePointer doStepNoPredicatesPropertyOwner(EvalContext context, PropertyOwnerPointer parentPointer, Step[] steps, int currentStep)
          We have a step that starts with a property owner (bean, map, etc) and has no predicates.
private static NodePointer doStepNoPredicatesStandard(EvalContext context, NodePointer parentPointer, Step[] steps, int currentStep)
          A path that starts with a standard InfoSet node (e.g.
private static NodePointer doStepPredicatesPropertyOwner(EvalContext context, PropertyOwnerPointer parentPointer, Step[] steps, int currentStep)
          A path that starts with a property owner.
private static NodePointer doStepPredicatesStandard(EvalContext context, NodePointer parent, Step[] steps, int currentStep)
          A path that starts with a standard InfoSet node, e.g.
private static NodeIterator getNodeIterator(EvalContext context, NodePointer pointer, Step step)
           
private static int indexFromPredicate(EvalContext context, Expression predicate)
          Extract an integer from a subscript predicate.
static NodePointer interpretSimpleExpressionPath(EvalContext context, NodePointer root, Expression[] predicates, Step[] steps)
          Interpret the steps of a simple expression path that starts with the given root, which is the result of evaluation of the root expression of the expression path, applies the given predicates to it and then follows the given steps.
static NodePointer interpretSimpleLocationPath(EvalContext context, NodePointer root, Step[] steps)
          Interpret a simple path that starts with the given root and follows the given steps.
private static boolean isCollectionElement(NodePointer pointer, int index)
          Returns true if the pointer is a collection and the index is withing the bounds of the collection.
private static boolean isLangAttribute(QName name)
           
private static boolean isNameAttributeEqual(NodePointer pointer, java.lang.String name)
          Returns true if the pointer has an attribute called "name" and its value is equal to the supplied string.
private static java.lang.String keyFromPredicate(EvalContext context, Expression predicate)
          Extracts the string value of the expression from a predicate like [@name=expression].
private static NodePointer valuePointer(NodePointer pointer)
          For an intermediate pointer (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QNAME_NAME

private static final QName QNAME_NAME

PERFECT_MATCH

private static final int PERFECT_MATCH
See Also:
Constant Field Values
Constructor Detail

SimplePathInterpreter

public SimplePathInterpreter()
Method Detail

interpretSimpleLocationPath

public static NodePointer interpretSimpleLocationPath(EvalContext context,
                                                      NodePointer root,
                                                      Step[] steps)
Interpret a simple path that starts with the given root and follows the given steps. All steps must have the axis "child::" and a name test. They can also optionally have predicates of type [@name=expression] or simply [expression] interpreted as an index.


interpretSimpleExpressionPath

public static NodePointer interpretSimpleExpressionPath(EvalContext context,
                                                        NodePointer root,
                                                        Expression[] predicates,
                                                        Step[] steps)
Interpret the steps of a simple expression path that starts with the given root, which is the result of evaluation of the root expression of the expression path, applies the given predicates to it and then follows the given steps. All steps must have the axis "child::" or "attribute::" and a name test. They can also optionally have predicates of type [@name=...] or simply [...] interpreted as an index.


doStep

private static NodePointer doStep(EvalContext context,
                                  NodePointer parent,
                                  Step[] steps,
                                  int currentStep)
Recursive evaluation of a path. The general plan is: Look at the current step, find nodes that match it, iterate over those nodes and for each of them call doStep again for subsequent steps.


doStepNoPredicatesPropertyOwner

private static NodePointer doStepNoPredicatesPropertyOwner(EvalContext context,
                                                           PropertyOwnerPointer parentPointer,
                                                           Step[] steps,
                                                           int currentStep)
We have a step that starts with a property owner (bean, map, etc) and has no predicates. The name test of the step may map to a scalar property or to a collection. If it is a collection, we should apply the tail of the path to each element until we find a match. If we don't find a perfect match, we should return the "best quality" pointer, which has the longest chain of steps mapping to existing nodes and the shortes tail of Null* pointers.


doStepNoPredicatesStandard

private static NodePointer doStepNoPredicatesStandard(EvalContext context,
                                                      NodePointer parentPointer,
                                                      Step[] steps,
                                                      int currentStep)
A path that starts with a standard InfoSet node (e.g. DOM Node) and has no predicates. Get a child iterator and apply the tail of the path to each element until we find a match. If we don't find a perfect match, we should return the "best quality" pointer, which has the longest chain of steps mapping to existing nodes and the shortes tail of Null* pointers.


doStepPredicatesPropertyOwner

private static NodePointer doStepPredicatesPropertyOwner(EvalContext context,
                                                         PropertyOwnerPointer parentPointer,
                                                         Step[] steps,
                                                         int currentStep)
A path that starts with a property owner. The method evaluates the first predicate in a special way and then forwards to a general predicate processing method.


createChildPointerForStep

private static NodePointer createChildPointerForStep(PropertyOwnerPointer parentPointer,
                                                     Step step)

doStepPredicatesStandard

private static NodePointer doStepPredicatesStandard(EvalContext context,
                                                    NodePointer parent,
                                                    Step[] steps,
                                                    int currentStep)
A path that starts with a standard InfoSet node, e.g. a DOM Node. The method evaluates the first predicate in a special way and then forwards to a general predicate processing method.


doPredicate

private static NodePointer doPredicate(EvalContext context,
                                       NodePointer parent,
                                       Step[] steps,
                                       int currentStep,
                                       Expression[] predicates,
                                       int currentPredicate)
Evaluates predicates and proceeds with the subsequent steps of the path.


doPredicateName

private static NodePointer doPredicateName(EvalContext context,
                                           NodePointer parent,
                                           Step[] steps,
                                           int currentStep,
                                           Expression[] predicates,
                                           int currentPredicate)

doPredicatesStandard

private static NodePointer doPredicatesStandard(EvalContext context,
                                                java.util.List parents,
                                                Step[] steps,
                                                int currentStep,
                                                Expression[] predicates,
                                                int currentPredicate)
Called exclusively for standard InfoSet nodes, e.g. DOM nodes to evaluate predicate sequences like [@name=...][@name=...][index].


doPredicateIndex

private static NodePointer doPredicateIndex(EvalContext context,
                                            NodePointer parent,
                                            Step[] steps,
                                            int currentStep,
                                            Expression[] predicates,
                                            int currentPredicate)
Evaluate a subscript predicate: see if the node is a collection and if the index is inside the collection


indexFromPredicate

private static int indexFromPredicate(EvalContext context,
                                      Expression predicate)
Extract an integer from a subscript predicate. The returned index starts with 0, even though the subscript starts with 1.


keyFromPredicate

private static java.lang.String keyFromPredicate(EvalContext context,
                                                 Expression predicate)
Extracts the string value of the expression from a predicate like [@name=expression].


computeQuality

private static int computeQuality(NodePointer pointer)
For a pointer that matches an actual node, returns 0. For a pointer that does not match an actual node, but whose parent pointer does returns -1, etc.


isNameAttributeEqual

private static boolean isNameAttributeEqual(NodePointer pointer,
                                            java.lang.String name)
Returns true if the pointer has an attribute called "name" and its value is equal to the supplied string.


isCollectionElement

private static boolean isCollectionElement(NodePointer pointer,
                                           int index)
Returns true if the pointer is a collection and the index is withing the bounds of the collection.


valuePointer

private static NodePointer valuePointer(NodePointer pointer)
For an intermediate pointer (e.g. PropertyPointer, ContainerPointer) returns a pointer for the contained value.


createNullPointer

public static NodePointer createNullPointer(EvalContext context,
                                            NodePointer parent,
                                            Step[] steps,
                                            int currentStep)
Creates a "null pointer" that a) represents the requested path and b) can be used for creation of missing nodes in the path.


createNullPointerForPredicates

private static NodePointer createNullPointerForPredicates(EvalContext context,
                                                          NodePointer parent,
                                                          Step[] steps,
                                                          int currentStep,
                                                          Expression[] predicates,
                                                          int currentPredicate)
Creates a "null pointer" that starts with predicates.


getNodeIterator

private static NodeIterator getNodeIterator(EvalContext context,
                                            NodePointer pointer,
                                            Step step)

isLangAttribute

private static boolean isLangAttribute(QName name)