FileDocCategorySizeDatePackage
JDOQLParameterDeclarationParser.javaAPI DocGlassfish v2 API8337Fri May 04 22:35:06 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc

JDOQLParameterDeclarationParser

public class JDOQLParameterDeclarationParser extends Object implements com.sun.enterprise.deployment.interfaces.QueryParser
Helper class to support parsing of JDOQL parameter declarations. Created on October 16, 2002
author
Michael Bouschen

Fields Summary
protected static final ResourceBundle
messages
I18N support
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Method main for testing purposes. Parameter args is expected to a an array of parameter declaration String. One parameter declaration may declare multiple parameters according to the JDOQL parameter declaration syntax. Calling java com...jqlc.ParameterDeclarationHelper "int a, String b" will print
Parameter types for >int a, String b<
int
String

        QueryParser helper = new JDOQLParameterDeclarationParser();
        for (int i = 0; i < args.length; i++) {
            String text = args[i];
            System.out.println("Parameter types for >" + text + "<");
            for (Iterator types = helper.parameterTypeIterator(text); 
                 types.hasNext();) {
                System.out.println("  " + types.next());
            }
        }
    
public java.util.IteratorparameterTypeIterator(java.lang.String text)
Returns an iterator over the parameter types of the specified JDOQL parameter declartion. The types are represented by their name, thus the Iterator's next method returns Strings.

param
text the JDOQL parameter declaration
return
an iterator over parameter types
exception
JDOQueryException indicates a parse error


                                                       
       
    
        return new ParameterTypeIterator(parse(text));
    
private persistence.antlr.collections.ASTparse(java.lang.String text)
Internal method parsing the JDOQL parameter declaration.

param
text the JDOQL parameter declaration
return
an AST representing the parameter declarations

        if (text == null) {
            return null;
        }

        // return value
        AST paramsAST = null;

        // error message helper
        ErrorMsg errorMsg = new ErrorMsg();

        // create parser
        JQLParser parser = JQLC.createStringParser(text, errorMsg);

        try {
            // start parsing
            parser.parseParameters();
            // get the AST representation
            paramsAST = parser.getAST();
        }
        catch (ANTLRException ex) {
            // handle any exceptions thrown by lexer or parser
            JQLParser.handleANTLRException(ex, errorMsg);
        }

        return paramsAST;