KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > ast > tree > SelectExpressionList


1 // $Id: SelectExpressionList.java,v 1.1 2005/07/12 20:27:16 steveebersole Exp $
2
package org.hibernate.hql.ast.tree;
3
4 import java.util.ArrayList JavaDoc;
5
6 import org.hibernate.hql.antlr.SqlTokenTypes;
7 import org.hibernate.hql.ast.util.ASTPrinter;
8
9 import antlr.collections.AST;
10
11 /**
12  * Common behavior - a node that contains a list of select expressions.
13  *
14  * @author josh Nov 6, 2004 8:51:00 AM
15  */

16 public abstract class SelectExpressionList extends HqlSqlWalkerNode {
17     /**
18      * Returns an array of SelectExpressions gathered from the children of the given parent AST node.
19      *
20      * @return an array of SelectExpressions gathered from the children of the given parent AST node.
21      */

22     public SelectExpression[] collectSelectExpressions() {
23         // Get the first child to be considered. Sub-classes may do this differently in order to skip nodes that
24
// are not select expressions (e.g. DISTINCT).
25
AST firstChild = getFirstSelectExpression();
26         AST parent = this;
27         ArrayList JavaDoc list = new ArrayList JavaDoc( parent.getNumberOfChildren() );
28         for ( AST n = firstChild; n != null; n = n.getNextSibling() ) {
29             if ( n instanceof SelectExpression ) {
30                 list.add( n );
31             }
32             else {
33                 throw new IllegalStateException JavaDoc( "Unexpected AST: " + n.getClass().getName() + " " + new ASTPrinter( SqlTokenTypes.class ).showAsString( n, "" ) );
34             }
35         }
36         return ( SelectExpression[] ) list.toArray( new SelectExpression[list.size()] );
37     }
38
39     /**
40      * Returns the first select expression node that should be considered when building the array of select
41      * expressions.
42      *
43      * @return the first select expression node that should be considered when building the array of select
44      * expressions
45      */

46     protected abstract AST getFirstSelectExpression();
47
48 }
49
Popular Tags