FileDocCategorySizeDatePackage
EJBQLParser.javaAPI DocGlassfish v2 API13809Tue May 22 16:54:40 BST 2007oracle.toplink.essentials.internal.parsing.ejbql

EJBQLParser

public abstract class EJBQLParser extends LLkParser
EJBQLParser is the superclass of the ANTLR generated parser.

Fields Summary
private static final int
EOF_CHAR
The ANTLR end of file character.
private List
errors
List of errors.
private String
queryName
The name of the query being compiled. The variable is null for dynamic queries.
private String
queryText
The text of the query being compiled.
protected NodeFactory
factory
The factory to create parse tree nodes.
Constructors Summary
protected EJBQLParser(TokenBuffer tokenBuf, int k_)

    
         
        super(tokenBuf, k_);
    
protected EJBQLParser(ParserSharedInputState state, int k_)

        super(state, k_);
    
protected EJBQLParser(TokenStream lexer, int k)

        super(lexer, k);
    
Methods Summary
public static java.lang.StringANTLRVersion()
INTERNAL Returns the ANTLR version currently used.

        return "2.7.3";
    
public voidaddError(java.lang.Exception e)
INTERNAL Add the exception to the list of errors.

        if (e instanceof ANTLRException) {
            e = handleANTLRException((ANTLRException)e);
        } else if (!(e instanceof EJBQLException)) {
            e = EJBQLException.generalParsingException(getQueryInfo(), e);
        }
        errors.add(e);
    
public static oracle.toplink.essentials.internal.parsing.EJBQLParseTreebuildParseTree(java.lang.String queryText)
INTERNAL Builds a parser, parses the specified query string and returns the parse tree. Any error in the query text results in an EJBQLException. This method is used for dynamic queries.

        return buildParseTree(null, queryText);
    
public static oracle.toplink.essentials.internal.parsing.EJBQLParseTreebuildParseTree(java.lang.String queryName, java.lang.String queryText)
INTERNAL Builds a parser, parses the specified query string and returns the parse tree. Any error in the query text results in an EJBQLException.

        EJBQLParser parser = buildParserFor(queryName, queryText);
        return parser.parse();
    
public static oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParserbuildParserFor(java.lang.String queryText)
INTERNAL Creates a parser for the specified query string. The query string is not parsed (see method parse). This method is used for dynamic queries.

        return buildParserFor(null, queryText);
    
public static oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParserbuildParserFor(java.lang.String queryName, java.lang.String queryText)
INTERNAL Creates a parser for the specified query string. The query string is not parsed (see method parse).

        try {
            EJBQLParser parser = EJBQLParserBuilder.buildParser(queryText);
            parser.setQueryName(queryName);
            parser.setQueryText(queryText);
            parser.setNodeFactory(new NodeFactoryImpl(parser.getQueryInfo()));
            return parser;
        } catch (Exception ex) {
            throw EJBQLException.generalParsingException(queryText, ex);
        }
    
public abstract voiddocument()
This is the parser start method. It will be implemented by the ANTLR generated subclass.

protected oracle.toplink.essentials.exceptions.EJBQLExceptiongenerateException()
INTERNAL Generate an exception which encapsulates all the exceptions generated by this parser. Special case where the first exception is an EJBQLException.

        //Handle exceptions we expect (such as expressionSotSupported)
        Exception firstException = (Exception)getErrors().get(0);
        if (firstException instanceof EJBQLException) {
            return (EJBQLException)firstException;
        }

        //Handle general exceptions, such as NPE
        EJBQLException exception = 
            EJBQLException.generalParsingException(getQueryInfo());
        exception.setInternalExceptions(getErrors());
        return exception;
    
public java.util.ListgetErrors()
INTERNAL Returns the list of errors found during the parsing process.

        return errors;
    
public oracle.toplink.essentials.internal.parsing.NodeFactorygetNodeFactory()
INTERNAL Returns the factory used by the parser to create a parse tree and parse tree nodes.

        return factory;
    
public oracle.toplink.essentials.internal.parsing.EJBQLParseTreegetParseTree()
INTERNAL Returns the parse tree created by a successful run of the parse method.

        return (EJBQLParseTree)getRootNode();
    
public java.lang.StringgetQueryInfo()
INTERNAL Return the the query text prefixed by the query name in case of a named query. The method returns just the query text in case of a dynamic query.

        return (queryName == null) ? queryText :
            queryName + ": " + queryText;
    
public java.lang.StringgetQueryName()
INTERNAL Return the name of the current query being compiled. This method returns null if the current query is a dynamic query and not a named query.

        return queryText;
    
public java.lang.StringgetQueryText()
INTERNAL Return the text of the current query being compiled.

        return queryText;
    
public abstract java.lang.ObjectgetRootNode()
Returns the root node after representing the parse tree for the current query string. It will be implemented by the ANTLR generated subclass.

protected oracle.toplink.essentials.exceptions.EJBQLExceptionhandleANTLRException(persistence.antlr.ANTLRException ex)
INTERNAL Map an exception thrown by the ANTLR generated code to an EJBQLException.

        EJBQLException result = null;
        if (ex instanceof MismatchedCharException) {
            MismatchedCharException mismatched = (MismatchedCharException)ex;
            if (mismatched.foundChar == EOF_CHAR) {
                result = EJBQLException.unexpectedEOF(getQueryInfo(), 
                    mismatched.getLine(), mismatched.getColumn(), ex);
            } else if (mismatched.mismatchType == MismatchedCharException.CHAR) {
                result = EJBQLException.expectedCharFound(getQueryInfo(), 
                    mismatched.getLine(), mismatched.getColumn(), 
                    String.valueOf((char)mismatched.expecting), 
                    String.valueOf((char)mismatched.foundChar), 
                    ex);
            }
        }
        else if (ex instanceof MismatchedTokenException) {
            MismatchedTokenException mismatched = (MismatchedTokenException)ex;
            Token token = mismatched.token;
            if (token != null) {
                if (token.getType() == Token.EOF_TYPE) {
                    result = EJBQLException.unexpectedEOF(getQueryInfo(), 
                        mismatched.getLine(), mismatched.getColumn(), ex);
                }
                else {
                    result = EJBQLException.syntaxErrorAt(getQueryInfo(),
                        mismatched.getLine(), mismatched.getColumn(),
                        token.getText(), ex);
                }
            }
        }
        else if (ex instanceof NoViableAltException) {
            NoViableAltException noviable = (NoViableAltException)ex;
            Token token = noviable.token;
            if (token != null) {
                if (token.getType() == Token.EOF_TYPE) {
                    result = EJBQLException.unexpectedEOF(getQueryInfo(),
                        noviable.getLine(), noviable.getColumn(), ex);
                }
                else {
                    result = EJBQLException.unexpectedToken(getQueryInfo(), 
                        noviable.getLine(), noviable.getColumn(), 
                        token.getText(), ex);
                }
            }
        }
        else if (ex instanceof NoViableAltForCharException) {
            NoViableAltForCharException noViableAlt = (NoViableAltForCharException)ex;
            result = EJBQLException.unexpectedChar(getQueryInfo(),
                noViableAlt.getLine(), noViableAlt.getColumn(),
                String.valueOf((char)noViableAlt.foundChar), ex);
        }
        else if (ex instanceof TokenStreamRecognitionException) {
            result = handleANTLRException(((TokenStreamRecognitionException)ex).recog);
        }
        
        if (result == null) {
            // no special handling from aboves matches the exception if this
            // line is reached => make it a syntax error
            result = EJBQLException.syntaxError(getQueryInfo(), ex);
        }
        return result;
    
public booleanhasErrors()
INTERNAL Returns true if there were errors during the parsing process.

        return !getErrors().isEmpty();
    
public oracle.toplink.essentials.internal.parsing.EJBQLParseTreeparse()
INTERNAL Parse the query string that was specified on parser creation.

        try {
            document();
        } catch (Exception e) {
            addError(e);
        }
        
        // Handle any errors generated by the Parser
        if (hasErrors()) {
            throw generateException();
        }

        // return the parser tree
        return getParseTree();
    
public voidreportError(persistence.antlr.RecognitionException ex)
Method called by the ANTLR generated code in case of an error.

        addError(ex);
    
public voidsetNodeFactory(oracle.toplink.essentials.internal.parsing.NodeFactory factory)
INTERNAL Set the factory used by the parser to create a parse tree and parse tree nodes.

        this.factory = factory;
    
public voidsetQueryName(java.lang.String queryName)
INTERNAL Set the name of the current query being compiled. Please note, setting the query name using this method is for error handling and debugging purposes.

        this.queryName = queryName;
    
public voidsetQueryText(java.lang.String queryText)
INTERNAL Set the text of the current query being compiled. Please note, setting the query text using this method is for error handling and debugging purposes.

        this.queryText = queryText;