~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/hql/ast/util/PathHelper.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Id: PathHelper.java 7460 2005-07-12 20:27:29Z steveebersole $
 
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 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
}