Package org.apache.xpath.compiler
Class Compiler
java.lang.Object
org.apache.xpath.compiler.OpMap
org.apache.xpath.compiler.Compiler
public class Compiler extends OpMap
An instance of this class compiles an XPath string expression into
a Expression object. This class compiles the string into a sequence
of operation codes (op map) and then builds from that into an Expression
tree.
-
Field Summary
Fields inherited from class org.apache.xpath.compiler.OpMap
m_currentPattern, MAPINDEX_LENGTH -
Constructor Summary
Constructors Constructor Description Compiler()Construct a Compiler instance that has a null error listener and a null source locator.Compiler(ErrorListener errorHandler, SourceLocator locator, FunctionTable fTable)Construct a Compiler object with a specific ErrorListener and SourceLocator where the expression is located. -
Method Summary
Modifier and Type Method Description protected Expressionand(int opPos)Compile an 'and' operation.protected Expressionarg(int opPos)Compile a function argument.voidassertion(boolean b, String msg)Tell the user of an assertion error, and probably throw an exception.protected Expressionbool(int opPos)Compile a 'boolean(...)' operation.Expressioncompile(int opPos)Execute the XPath object from a given opcode position.intcountPredicates(int opPos)Count the number of predicates in the step.protected Expressiondiv(int opPos)Compile a 'div' operation.protected Expressionequals(int opPos)Compile a '=' operation.voiderror(String msg, Object[] args)Tell the user of an error, and probably throw an exception.Expression[]getCompiledPredicates(int opPos)Compile a zero or more predicates for a given match pattern.intgetLocationPathDepth()Get the level of the location path or union being constructed.PrefixResolvergetNamespaceContext()Get the current namespace context for the xpath.intgetWhatToShow(int opPos)Get aNodeFilterbit set that tells what to show for a given node test.protected Expressiongroup(int opPos)Compile an expression group.protected Expressiongt(int opPos)Compile a '>' operation.protected Expressiongte(int opPos)Compile a '>=' operation.protected Expressionliteral(int opPos)Compile a literal string value.ExpressionlocationPath(int opPos)Compile a location path.ExpressionlocationPathPattern(int opPos)Compile a location match pattern unit expression.protected Expressionlt(int opPos)Compile a '<' operation.protected Expressionlte(int opPos)Compile a '<=' operation.protected ExpressionmatchPattern(int opPos)Compile an entire match pattern expression.protected Expressionminus(int opPos)Compile a '-' operation.protected Expressionmod(int opPos)Compile a 'mod' operation.protected Expressionmult(int opPos)Compile a '*' operation.protected Expressionneg(int opPos)Compile a unary '-' operation.protected Expressionnotequals(int opPos)Compile a '!=' operation.protected Expressionnumber(int opPos)Compile a 'number(...)' operation.protected Expressionnumberlit(int opPos)Compile a literal number value.protected Expressionor(int opPos)Compile an 'or' operation.protected Expressionplus(int opPos)Compile a '+' operation.Expressionpredicate(int opPos)Compile a location step predicate expression.voidsetNamespaceContext(PrefixResolver pr)Set the current namespace context for the xpath.protected StepPatternstepPattern(int opPos, int stepCount, StepPattern ancestorPattern)Compile a step pattern unit expression, used for both location paths and match patterns.protected Expressionstring(int opPos)Compile a 'string(...)' operation.protected Expressionunion(int opPos)Compile a location path union.protected Expressionvariable(int opPos)Compile a variable reference.voidwarn(String msg, Object[] args)Warn the user of an problem.Methods inherited from class org.apache.xpath.compiler.OpMap
getArgLength, getArgLengthOfStep, getFirstChildPos, getFirstChildPosOfStep, getFirstPredicateOpPos, getNextOpPos, getNextOpPos, getNextStepPos, getOp, getOpMap, getPatternString, getStepLocalName, getStepNS, getStepTestType, getToken, getTokenQueue, getTokenQueueSize, setOp, toString
-
Constructor Details
-
Compiler
Construct a Compiler object with a specific ErrorListener and SourceLocator where the expression is located.- Parameters:
errorHandler- Error listener where messages will be sent, or null if messages should be sent to System err.locator- The location object where the expression lives, which may be null, but which, if not null, must be valid over the long haul, in other words, it will not be cloned.fTable- The FunctionTable object where the xpath build-in functions are stored.
-
Compiler
public Compiler()Construct a Compiler instance that has a null error listener and a null source locator.
-
-
Method Details
-
compile
Execute the XPath object from a given opcode position.- Parameters:
opPos- The current position in the xpath.m_opMap array.- Returns:
- The result of the XPath.
- Throws:
TransformerException- if there is a syntax or other error.
-
or
Compile an 'or' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Orinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
and
Compile an 'and' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Andinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
notequals
Compile a '!=' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
NotEqualsinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
equals
Compile a '=' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Equalsinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
lte
Compile a '<=' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Lteinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
lt
Compile a '<' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Ltinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
gte
Compile a '>=' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Gteinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
gt
Compile a '>' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Gtinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
plus
Compile a '+' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Plusinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
minus
Compile a '-' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Minusinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
mult
Compile a '*' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Multinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
div
Compile a 'div' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Divinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
mod
Compile a 'mod' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Modinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
neg
Compile a unary '-' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Neginstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
string
Compile a 'string(...)' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Stringinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
bool
Compile a 'boolean(...)' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Boolinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
number
Compile a 'number(...)' operation.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Numberinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
literal
Compile a literal string value.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
XStringinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
numberlit
Compile a literal number value.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
XNumberinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
variable
Compile a variable reference.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
Variableinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
group
Compile an expression group.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to the contained expression.
- Throws:
TransformerException- if a error occurs creating the Expression.
-
arg
Compile a function argument.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to the argument expression.
- Throws:
TransformerException- if a error occurs creating the Expression.
-
union
Compile a location path union. The UnionPathIterator itself may createLocPathIteratorchildren.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
LocPathIteratorinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
getLocationPathDepth
public int getLocationPathDepth()Get the level of the location path or union being constructed.- Returns:
- 0 if it is a top-level path.
-
locationPath
Compile a location path. The LocPathIterator itself may createAxesWalkerchildren.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
LocPathIteratorinstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
predicate
Compile a location step predicate expression.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- the contained predicate expression.
- Throws:
TransformerException- if a error occurs creating the Expression.
-
matchPattern
Compile an entire match pattern expression.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
UnionPatterninstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
locationPathPattern
Compile a location match pattern unit expression.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
StepPatterninstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
getWhatToShow
public int getWhatToShow(int opPos)Get aNodeFilterbit set that tells what to show for a given node test.- Parameters:
opPos- the op map position for the location step.- Returns:
NodeFilterbit set that tells what to show for a given node test.
-
stepPattern
protected StepPattern stepPattern(int opPos, int stepCount, StepPattern ancestorPattern) throws TransformerExceptionCompile a step pattern unit expression, used for both location paths and match patterns.- Parameters:
opPos- The current position in the m_opMap array.stepCount- The number of steps to expect.ancestorPattern- The owning StepPattern, which may be null.- Returns:
- reference to
StepPatterninstance. - Throws:
TransformerException- if a error occurs creating the Expression.
-
getCompiledPredicates
Compile a zero or more predicates for a given match pattern.- Parameters:
opPos- The position of the first predicate the m_opMap array.- Returns:
- reference to array of
Expressioninstances. - Throws:
TransformerException- if a error occurs creating the Expression.
-
countPredicates
Count the number of predicates in the step.- Parameters:
opPos- The position of the first predicate the m_opMap array.- Returns:
- The number of predicates for this step.
- Throws:
TransformerException- if a error occurs creating the Expression.
-
warn
Warn the user of an problem.- Parameters:
msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException- if the current ErrorListoner determines to throw an exception.
-
assertion
Tell the user of an assertion error, and probably throw an exception.- Parameters:
b- If false, a runtime exception will be thrown.msg- The assertion message, which should be informative.- Throws:
RuntimeException- if the b argument is false.
-
error
Tell the user of an error, and probably throw an exception.- Overrides:
errorin classOpMap- Parameters:
msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException- if the current ErrorListoner determines to throw an exception.
-
getNamespaceContext
Get the current namespace context for the xpath.- Returns:
- The current prefix resolver, *may* be null, though hopefully not.
-
setNamespaceContext
Set the current namespace context for the xpath.- Parameters:
pr- The resolver for prefixes in the XPath expression.
-