com.novell.xml.xpath
Class Parser

java.lang.Object
  extended bycom.novell.xml.xpath.Parser
Direct Known Subclasses:
ExpressionParser

public class Parser
extends Object

Class that parses XPath expressions and returns an object that implements com.novell.xml.xpath.Expression


Constructor Summary
Parser(NamespaceContext namespaces)
          Build a Parser object for parsing one or more expressions given the passed namespace context.
Parser(VariableBindings variables, FunctionLibrary library, NamespaceContext namespaces)
          Build a Parser object for parsing one or more expressions given the passed variable bindings, function library and namespace context.
 
Method Summary
protected static FunctionLibrary getDefaultFunctionLibrary()
          Return the default XPath function library.
protected  FunctionLibrary getLibrary()
          Return the function library in use
protected  int getOperator(Token token)
          Return the operator value of the passed token, if it is an operator token.
 Token[] getTokens()
          Return the token array that tokenize() created
protected  VariableBindings getVariables()
          Return the variable bindings in use
protected  void nextToken()
          Advance the current token in the token stream by one.
protected  Expression parse()
          Parse the token string.
 Expression parse(String source)
          Parse a single expression.
 Expression parse(Token[] tokens)
          Parse an already tokenized expression.
protected  Expression parseAdditiveExpr()
           
protected  Expression parseAndExpr()
           
protected  ArgumentList parseArgumentList()
           
protected  Basis parseBasis()
           
protected  Expression parseEqualityExpr()
           
protected  Expression parseExpr()
           
protected  Expression parseFilterExpr()
           
protected  Expression parseFunctionCall()
          Parse a function call.
protected  Expression parseLocationPath()
           
protected  Expression parseMultiplicativeExpr()
           
protected  NodeTest parseNodeTest()
           
protected  Expression parseOrExpr()
           
protected  Expression parsePathExpr()
           
protected  Predicate parsePredicate()
           
protected  Expression parsePrimaryExpr()
           
protected  Expression parseRelationalExpr()
           
protected  RelativeLocationPath parseRelativeLocationPath()
           
protected  Step parseStep()
           
protected  Expression parseUnaryExpr()
           
protected  Expression parseUnionExpr()
           
protected  Token peekToken()
          Look at the next token without advancing in the token stream.
 boolean setBrokenMode(boolean doBroken)
          Set this Parser object to behave in a backwards-compatible broken mode.
 void tokenize(String source)
          Tokenize the passed string and place the tokens into the parser mechanism for examining tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser(NamespaceContext namespaces)
Build a Parser object for parsing one or more expressions given the passed namespace context. The function library used is the XPath built-in library (no extensions) and no variables are available.

Parameters:
namespaces - The namespace context in effect for the expression.

Parser

public Parser(VariableBindings variables,
              FunctionLibrary library,
              NamespaceContext namespaces)
Build a Parser object for parsing one or more expressions given the passed variable bindings, function library and namespace context.

Parameters:
variables - The variable bindings in effect for the expression.
library - The function library in effect for the expression.
namespaces - The namespace context in effect for the expression.
Method Detail

setBrokenMode

public boolean setBrokenMode(boolean doBroken)
Set this Parser object to behave in a backwards-compatible broken mode.

This is used for DirXML to default to a broken behavior for "!=" where only one of the operands is a node-set.

Parameters:
doBroken - if true do anything originally broken but later fixed XPath operations in the original, broken fashion.
Returns:
setting of broken mode before this call

parse

public Expression parse(String source)
                 throws XPathParserException
Parse a single expression. Throws a parser exception if there is a syntax error in the expression.

Parameters:
source - A string containing the XPath expression to parse.
Returns:
An object implementing the Expression interface.
Throws:
XPathParserException

parse

public Expression parse(Token[] tokens)
                 throws XPathParserException
Parse an already tokenized expression.

Parameters:
tokens - The token stream.
Returns:
An object implementing the Expression interface.
Throws:
XPathParserException

parse

protected Expression parse()
                    throws XPathParserException
Parse the token string. The tokens must have already been setup.

Returns:
The Expression that was parsed.
Throws:
XPathParserException

parseExpr

protected Expression parseExpr()
                        throws XPathParserException
Throws:
XPathParserException

parseOrExpr

protected Expression parseOrExpr()
                          throws XPathParserException
Throws:
XPathParserException

parseAndExpr

protected Expression parseAndExpr()
                           throws XPathParserException
Throws:
XPathParserException

parseEqualityExpr

protected Expression parseEqualityExpr()
                                throws XPathParserException
Throws:
XPathParserException

parseRelationalExpr

protected Expression parseRelationalExpr()
                                  throws XPathParserException
Throws:
XPathParserException

parseAdditiveExpr

protected Expression parseAdditiveExpr()
                                throws XPathParserException
Throws:
XPathParserException

parseMultiplicativeExpr

protected Expression parseMultiplicativeExpr()
                                      throws XPathParserException
Throws:
XPathParserException

parseUnaryExpr

protected Expression parseUnaryExpr()
                             throws XPathParserException
Throws:
XPathParserException

parseUnionExpr

protected Expression parseUnionExpr()
                             throws XPathParserException
Throws:
XPathParserException

parsePathExpr

protected Expression parsePathExpr()
                            throws XPathParserException
Throws:
XPathParserException

parseFilterExpr

protected Expression parseFilterExpr()
                              throws XPathParserException
Throws:
XPathParserException

parsePrimaryExpr

protected Expression parsePrimaryExpr()
                               throws XPathParserException
Throws:
XPathParserException

parseFunctionCall

protected Expression parseFunctionCall()
                                throws XPathParserException
Parse a function call. The current token must be the FunctionNameToken.

Returns:
an Expression representing the function call
Throws:
XPathParserException - Thrown if the expression has incorrect syntax

parseArgumentList

protected ArgumentList parseArgumentList()
                                  throws XPathParserException
Throws:
XPathParserException

parseLocationPath

protected Expression parseLocationPath()
                                throws XPathParserException
Throws:
XPathParserException

parseRelativeLocationPath

protected RelativeLocationPath parseRelativeLocationPath()
                                                  throws XPathParserException
Throws:
XPathParserException

parseStep

protected Step parseStep()
                  throws XPathParserException
Throws:
XPathParserException

parseBasis

protected Basis parseBasis()
                    throws XPathParserException
Throws:
XPathParserException

parseNodeTest

protected NodeTest parseNodeTest()
                          throws XPathParserException
Throws:
XPathParserException

parsePredicate

protected Predicate parsePredicate()
                            throws XPathParserException
Throws:
XPathParserException

tokenize

public void tokenize(String source)
              throws XPathParserException
Tokenize the passed string and place the tokens into the parser mechanism for examining tokens.

Parameters:
source - The string to tokenize.
Throws:
XPathParserException

getTokens

public Token[] getTokens()
Return the token array that tokenize() created

Returns:
The token array that tokenize() created

peekToken

protected Token peekToken()
Look at the next token without advancing in the token stream.

Returns:
The current token in the stream. This may be a special token with the value Token.NOT_A_TOKEN if there are no more tokens in the stream.

nextToken

protected void nextToken()
Advance the current token in the token stream by one.


getOperator

protected int getOperator(Token token)
Return the operator value of the passed token, if it is an operator token.

Parameters:
token - The token to examine.
Returns:
A value from OperatorToken including OperatorToken.NOT_AN_OPERATOR.

getLibrary

protected FunctionLibrary getLibrary()
Return the function library in use

Returns:
The function library in use

getDefaultFunctionLibrary

protected static FunctionLibrary getDefaultFunctionLibrary()
Return the default XPath function library.

Returns:
An object implementing FunctionLibrary that contains all XPath built-in functions

getVariables

protected VariableBindings getVariables()
Return the variable bindings in use

Returns:
The VariableBindings object in use