1 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 18 public final class PathHelper { 19 20 private static final Log log = LogFactory.getLog( PathHelper.class ); 21 22 private PathHelper() { 23 } 24 25 32 public static AST parsePath(String path, ASTFactory factory) { 33 String [] identifiers = StringHelper.split( ".", path ); 34 AST lhs = null; 35 for ( int i = 0; i < identifiers.length; i++ ) { 36 String 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 getAlias(String path) { 52 return StringHelper.root( path ); 53 } 54 } 55 | Popular Tags |