KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > ast > util > PathHelper


1 // $Id: PathHelper.java,v 1.1 2005/07/12 20:27:22 steveebersole Exp $
2
package org.hibernate.hql.ast.util;
3
4 import org.hibernate.hql.antlr.HqlSqlTokenTypes;
5 import org.hibernate.util.StringHelper;
6
7 import antlr.ASTFactory;
8 import antlr.collections.AST;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 /**
14  * Provides utility methods for paths.
15  *
16  * @author josh Sep 14, 2004 8:16:29 AM
17  */

18 public final class PathHelper {
19
20     private static final Log log = LogFactory.getLog( PathHelper.class );
21
22     private PathHelper() {
23     }
24
25     /**
26      * Turns a path into an AST.
27      *
28      * @param path The path.
29      * @param factory The AST factory to use.
30      * @return An HQL AST representing the path.
31      */

32     public static AST parsePath(String JavaDoc path, ASTFactory factory) {
33         String JavaDoc[] identifiers = StringHelper.split( ".", path );
34         AST lhs = null;
35         for ( int i = 0; i < identifiers.length; i++ ) {
36             String JavaDoc identifier = identifiers[i];
37             AST child = ASTUtil.create( factory, HqlSqlTokenTypes.IDENT, identifier );
38             if ( i == 0 ) {
39                 lhs = child;
40             }
41             else {
42                 lhs = ASTUtil.createBinarySubtree( factory, HqlSqlTokenTypes.DOT, ".", lhs, child );
43             }
44         }
45         if ( log.isDebugEnabled() ) {
46             log.debug( "parsePath() : " + path + " -> " + ASTUtil.getDebugString( lhs ) );
47         }
48         return lhs;
49     }
50
51     public static String JavaDoc getAlias(String JavaDoc path) {
52         return StringHelper.root( path );
53     }
54 }
55
Popular Tags