Class Path
- java.lang.Object
-
- org.apache.commons.jxpath.ri.compiler.Expression
-
- org.apache.commons.jxpath.ri.compiler.Path
-
- Direct Known Subclasses:
ExpressionPath,LocationPath
public abstract class Path extends Expression
- Version:
- $Revision: 681111 $ $Date: 2008-07-30 11:30:29 -0500 (Wed, 30 Jul 2008) $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.jxpath.ri.compiler.Expression
Expression.PointerIterator, Expression.ValueIterator
-
-
Field Summary
Fields Modifier and Type Field Description private booleanbasicprivate booleanbasicKnownprivate Step[]steps-
Fields inherited from class org.apache.commons.jxpath.ri.compiler.Expression
NOT_A_NUMBER, ONE, ZERO
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanareBasicPredicates(Expression[] predicates)Learn whether the elements of the specified array are "basic" predicates.protected EvalContextbuildContextChain(EvalContext context, int stepCount, boolean createInitialContext)Build a context from a chain of contexts.booleancomputeContextDependent()Implemented by subclasses and result is cached by isContextDependent()protected EvalContextcreateContextForStep(EvalContext context, int axis, NodeTest nodeTest)Different axes are serviced by different contexts.protected EvalContextevalSteps(EvalContext context)Given a root context, walks a path therefrom and builds a context that contains all nodes matching the path.protected PointergetSingleNodePointerForSteps(EvalContext context)Given a root context, walks a path therefrom and finds the pointer to the first element matching the path.Step[]getSteps()Get the steps.booleanisSimplePath()Recognizes paths formatted asfoo/bar[3]/baz[@name = 'biz'].protected booleanisSimpleStep(Step step)A Step is "simple" if it takes one of these forms: ".", "/foo", "@bar", "/foo[3]".protected PointersearchForPath(EvalContext context)The idea here is to return a NullPointer rather than null if that's at all possible.-
Methods inherited from class org.apache.commons.jxpath.ri.compiler.Expression
compute, computeValue, isContextDependent, iterate, iteratePointers
-
-
-
-
Field Detail
-
steps
private Step[] steps
-
basicKnown
private boolean basicKnown
-
basic
private boolean basic
-
-
Constructor Detail
-
Path
public Path(Step[] steps)
Create a new Path.- Parameters:
steps- that compose the Path
-
-
Method Detail
-
getSteps
public Step[] getSteps()
Get the steps.- Returns:
- Step[]
-
computeContextDependent
public boolean computeContextDependent()
Description copied from class:ExpressionImplemented by subclasses and result is cached by isContextDependent()- Specified by:
computeContextDependentin classExpression- Returns:
- calculated context-dependentness as boolean
-
isSimplePath
public boolean isSimplePath()
Recognizes paths formatted asfoo/bar[3]/baz[@name = 'biz']. The evaluation of such "simple" paths is optimized and streamlined.- Returns:
trueif this path is simple
-
isSimpleStep
protected boolean isSimpleStep(Step step)
A Step is "simple" if it takes one of these forms: ".", "/foo", "@bar", "/foo[3]". If there are predicates, they should be context independent for the step to still be considered simple.- Parameters:
step- the step to check- Returns:
- boolean
-
areBasicPredicates
protected boolean areBasicPredicates(Expression[] predicates)
Learn whether the elements of the specified array are "basic" predicates.- Parameters:
predicates- the Expression[] to check- Returns:
- boolean
-
getSingleNodePointerForSteps
protected Pointer getSingleNodePointerForSteps(EvalContext context)
Given a root context, walks a path therefrom and finds the pointer to the first element matching the path.- Parameters:
context- evaluation context- Returns:
- Pointer
-
searchForPath
protected Pointer searchForPath(EvalContext context)
The idea here is to return a NullPointer rather than null if that's at all possible. Take for example this path: "//map/key". Let's say, "map" is an existing node, but "key" is not there. We will create a NullPointer that can be used to set/create the "key" property.However, a path like "//key" would still produce null, because we have no way of knowing where "key" would be if it existed.
To accomplish this, we first try the path itself. If it does not find anything, we chop off last step of the path, as long as it is a simple one like child:: or attribute:: and try to evaluate the truncated path. If it finds exactly one node - create a NullPointer and return. If it fails, chop off another step and repeat. If it finds more than one location - return null.
- Parameters:
context- evaluation context- Returns:
- Pointer
-
evalSteps
protected EvalContext evalSteps(EvalContext context)
Given a root context, walks a path therefrom and builds a context that contains all nodes matching the path.- Parameters:
context- evaluation context- Returns:
- EvaluationContext
-
buildContextChain
protected EvalContext buildContextChain(EvalContext context, int stepCount, boolean createInitialContext)
Build a context from a chain of contexts.- Parameters:
context- evaluation contextstepCount- number of steps to descendcreateInitialContext- whether to create the initial context- Returns:
- created context
-
createContextForStep
protected EvalContext createContextForStep(EvalContext context, int axis, NodeTest nodeTest)
Different axes are serviced by different contexts. This method allocates the right context for the supplied step.- Parameters:
context- evaluation contextaxis- codenodeTest- node test- Returns:
- EvalContext
-
-