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
MAPINDEX_LENGTH
-
-
Constructor Summary
Constructors Constructor Description Compiler()Construct a Compiler instance that has a null error listener and a null source locator.Compiler(javax.xml.transform.ErrorListener errorHandler, javax.xml.transform.SourceLocator locator, FunctionTable fTable)Construct a Compiler object with a specific ErrorListener and SourceLocator where the expression is located.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertion(boolean b, java.lang.String msg)Tell the user of an assertion error, and probably throw an exception.Expressioncompile(int opPos)Execute the XPath object from a given opcode position.intcountPredicates(int opPos)Count the number of predicates in the step.voiderror(java.lang.String msg, java.lang.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.ExpressionlocationPath(int opPos)Compile a location path.ExpressionlocationPathPattern(int opPos)Compile a location match pattern unit expression.Expressionpredicate(int opPos)Compile a location step predicate expression.voidsetNamespaceContext(PrefixResolver pr)Set the current namespace context for the xpath.voidwarn(java.lang.String msg, java.lang.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 Detail
-
Compiler
public Compiler(javax.xml.transform.ErrorListener errorHandler, javax.xml.transform.SourceLocator locator, FunctionTable fTable)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 Detail
-
compile
public Expression compile(int opPos) throws javax.xml.transform.TransformerException
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:
javax.xml.transform.TransformerException- if there is a syntax or other error.
-
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
public Expression locationPath(int opPos) throws javax.xml.transform.TransformerException
Compile a location path. The LocPathIterator itself may createAxesWalkerchildren.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
LocPathIteratorinstance. - Throws:
javax.xml.transform.TransformerException- if a error occurs creating the Expression.
-
predicate
public Expression predicate(int opPos) throws javax.xml.transform.TransformerException
Compile a location step predicate expression.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- the contained predicate expression.
- Throws:
javax.xml.transform.TransformerException- if a error occurs creating the Expression.
-
locationPathPattern
public Expression locationPathPattern(int opPos) throws javax.xml.transform.TransformerException
Compile a location match pattern unit expression.- Parameters:
opPos- The current position in the m_opMap array.- Returns:
- reference to
StepPatterninstance. - Throws:
javax.xml.transform.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.
-
getCompiledPredicates
public Expression[] getCompiledPredicates(int opPos) throws javax.xml.transform.TransformerException
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:
javax.xml.transform.TransformerException- if a error occurs creating the Expression.
-
countPredicates
public int countPredicates(int opPos) throws javax.xml.transform.TransformerExceptionCount 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:
javax.xml.transform.TransformerException- if a error occurs creating the Expression.
-
warn
public void warn(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerExceptionWarn 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:
javax.xml.transform.TransformerException- if the current ErrorListoner determines to throw an exception.
-
assertion
public void assertion(boolean b, java.lang.String msg)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:
java.lang.RuntimeException- if the b argument is false.
-
error
public void error(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerExceptionTell 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:
javax.xml.transform.TransformerException- if the current ErrorListoner determines to throw an exception.
-
getNamespaceContext
public PrefixResolver getNamespaceContext()
Get the current namespace context for the xpath.- Returns:
- The current prefix resolver, *may* be null, though hopefully not.
-
setNamespaceContext
public void setNamespaceContext(PrefixResolver pr)
Set the current namespace context for the xpath.- Parameters:
pr- The resolver for prefixes in the XPath expression.
-
-