KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: FromReferenceNode.java,v 1.2 2005/07/15 16:20:04 steveebersole Exp $
2
package org.hibernate.hql.ast.tree;
3
4 import antlr.SemanticException;
5 import antlr.collections.AST;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 /**
11  * Represents a reference to a FROM element, for example a class alias in a WHERE clause.
12  *
13  * @author josh Jul 21, 2004 7:02:04 AM
14  */

15 public abstract class FromReferenceNode extends AbstractSelectExpression
16         implements ResolvableNode, DisplayableNode, InitializeableNode, PathNode {
17
18     private static final Log log = LogFactory.getLog( FromReferenceNode.class );
19
20     private FromElement fromElement;
21     private boolean resolved = false;
22     public static final int ROOT_LEVEL = 0;
23
24     public FromElement getFromElement() {
25         return fromElement;
26     }
27
28     public void setFromElement(FromElement fromElement) {
29         this.fromElement = fromElement;
30     }
31
32     /**
33      * Resolves the left hand side of the DOT.
34      *
35      * @throws SemanticException
36      */

37     public void resolveFirstChild() throws SemanticException {
38     }
39
40     public String JavaDoc getPath() {
41         return getOriginalText();
42     }
43
44     public boolean isResolved() {
45         return resolved;
46     }
47
48     public void setResolved() {
49         this.resolved = true;
50         if ( log.isDebugEnabled() ) {
51             log.debug( "Resolved : " + this.getPath() + " -> " + this.getText() );
52         }
53     }
54
55     public String JavaDoc getDisplayText() {
56         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
57         buf.append( "{" ).append( ( fromElement == null ) ? "no fromElement" : fromElement.getDisplayText() );
58         buf.append( "}" );
59         return buf.toString();
60     }
61
62     public void recursiveResolve(int level, boolean impliedAtRoot, String JavaDoc classAlias) throws SemanticException {
63         recursiveResolve( level, impliedAtRoot, classAlias, this );
64     }
65
66     public void recursiveResolve(int level, boolean impliedAtRoot, String JavaDoc classAlias, AST parent) throws SemanticException {
67         AST lhs = getFirstChild();
68         int nextLevel = level + 1;
69         if ( lhs != null ) {
70             FromReferenceNode n = ( FromReferenceNode ) lhs;
71             n.recursiveResolve( nextLevel, impliedAtRoot, null, this );
72         }
73         resolveFirstChild();
74         boolean impliedJoin = true;
75         if ( level == ROOT_LEVEL && !impliedAtRoot ) {
76             impliedJoin = false;
77         }
78         resolve( true, impliedJoin, classAlias, parent );
79     }
80
81     public boolean isReturnableEntity() throws SemanticException {
82         return !isScalar() && fromElement.isEntity();
83     }
84
85     public void resolveInFunctionCall(boolean generateJoin, boolean implicitJoin) throws SemanticException {
86         resolve( generateJoin, implicitJoin );
87     }
88
89     public void resolve(boolean generateJoin, boolean implicitJoin) throws SemanticException {
90         resolve( generateJoin, implicitJoin, null );
91     }
92
93     public void resolve(boolean generateJoin, boolean implicitJoin, String JavaDoc classAlias) throws SemanticException {
94         resolve( generateJoin, implicitJoin, classAlias, null );
95     }
96
97     public void prepareForDot(String JavaDoc propertyName) throws SemanticException {
98     }
99
100     /**
101      * Sub-classes can override this method if they produce implied joins (e.g. DotNode).
102      *
103      * @return an implied join created by this from reference.
104      */

105     public FromElement getImpliedJoin() {
106         return null;
107     }
108
109 }
110
Popular Tags