KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > ejbql > ASTPath


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.ejbql;
23
24 import java.util.List JavaDoc;
25
26 import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
27 import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
28 import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
29 import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
30
31 /**
32  * This abstract syntax node represents a path declaration.
33  *
34  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
35  * @version $Revision: 37459 $
36  */

37 public final class ASTPath extends SimpleNode
38 {
39    public List JavaDoc pathList;
40    public List JavaDoc fieldList;
41    public int type;
42
43    public boolean innerJoin;
44
45    public ASTPath(int id)
46    {
47       super(id);
48    }
49
50    public String JavaDoc getPath()
51    {
52       return (String JavaDoc) pathList.get(pathList.size() - 1);
53    }
54
55    public String JavaDoc getPath(int i)
56    {
57       return (String JavaDoc) pathList.get(i);
58    }
59
60    public FieldBridge getField()
61    {
62       return (FieldBridge) fieldList.get(fieldList.size() - 1);
63    }
64
65    public boolean isCMPField()
66    {
67       return fieldList.get(fieldList.size() - 1) instanceof CMPFieldBridge;
68    }
69
70    public CMPFieldBridge getCMPField()
71    {
72       return (CMPFieldBridge) fieldList.get(fieldList.size() - 1);
73    }
74
75    public boolean isCMRField()
76    {
77       return fieldList.get(fieldList.size() - 1) instanceof CMRFieldBridge;
78    }
79
80    public boolean isCMRField(int i)
81    {
82       return fieldList.get(i) instanceof CMRFieldBridge;
83    }
84
85    public CMRFieldBridge getCMRField()
86    {
87       return (CMRFieldBridge) fieldList.get(fieldList.size() - 1);
88    }
89
90    public CMRFieldBridge getCMRField(int i)
91    {
92       return (CMRFieldBridge) fieldList.get(i);
93    }
94
95    public EntityBridge getEntity()
96    {
97       Object JavaDoc field = fieldList.get(fieldList.size() - 1);
98       if(field instanceof CMRFieldBridge)
99       {
100          return ((CMRFieldBridge) field).getRelatedEntity();
101       }
102       else if(field instanceof EntityBridge)
103       {
104          return (EntityBridge) field;
105       }
106       else
107       {
108          return null;
109       }
110    }
111
112    public EntityBridge getEntity(int i)
113    {
114       Object JavaDoc field = fieldList.get(i);
115       if(field instanceof CMRFieldBridge)
116       {
117          return ((CMRFieldBridge) field).getRelatedEntity();
118       }
119       else if(field instanceof EntityBridge)
120       {
121          return (EntityBridge) field;
122       }
123       else
124       {
125          return null;
126       }
127    }
128
129    public int size()
130    {
131       return fieldList.size();
132    }
133
134    public String JavaDoc toString()
135    {
136       return pathList.get(pathList.size() - 1) + " <" + type + ">";
137    }
138
139    public boolean equals(Object JavaDoc o)
140    {
141       if(o instanceof ASTPath)
142       {
143          ASTPath path = (ASTPath) o;
144          return path.getPath().equals(getPath());
145       }
146       return false;
147    }
148
149    public int hashCode()
150    {
151       return getPath().hashCode();
152    }
153
154    /**
155     * Accept the visitor. *
156     */

157    public Object JavaDoc jjtAccept(JBossQLParserVisitor visitor, Object JavaDoc data)
158    {
159       return visitor.visit(this, data);
160    }
161 }
162
Popular Tags