001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb.plugins.cmp.ejbql;
023:
024: import java.util.List;
025:
026: import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
027: import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
028: import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
029: import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
030:
031: /**
032: * This abstract syntax node represents a path declaration.
033: *
034: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
035: * @version $Revision: 57209 $
036: */
037: public final class ASTPath extends SimpleNode {
038: public List pathList;
039: public List fieldList;
040: public int type;
041:
042: public boolean innerJoin;
043:
044: public ASTPath(int id) {
045: super (id);
046: }
047:
048: public String getPath() {
049: return (String) pathList.get(pathList.size() - 1);
050: }
051:
052: public String getPath(int i) {
053: return (String) pathList.get(i);
054: }
055:
056: public FieldBridge getField() {
057: return (FieldBridge) fieldList.get(fieldList.size() - 1);
058: }
059:
060: public boolean isCMPField() {
061: return fieldList.get(fieldList.size() - 1) instanceof CMPFieldBridge;
062: }
063:
064: public CMPFieldBridge getCMPField() {
065: return (CMPFieldBridge) fieldList.get(fieldList.size() - 1);
066: }
067:
068: public boolean isCMRField() {
069: return fieldList.get(fieldList.size() - 1) instanceof CMRFieldBridge;
070: }
071:
072: public boolean isCMRField(int i) {
073: return fieldList.get(i) instanceof CMRFieldBridge;
074: }
075:
076: public CMRFieldBridge getCMRField() {
077: return (CMRFieldBridge) fieldList.get(fieldList.size() - 1);
078: }
079:
080: public CMRFieldBridge getCMRField(int i) {
081: return (CMRFieldBridge) fieldList.get(i);
082: }
083:
084: public EntityBridge getEntity() {
085: Object field = fieldList.get(fieldList.size() - 1);
086: if (field instanceof CMRFieldBridge) {
087: return ((CMRFieldBridge) field).getRelatedEntity();
088: } else if (field instanceof EntityBridge) {
089: return (EntityBridge) field;
090: } else {
091: return null;
092: }
093: }
094:
095: public EntityBridge getEntity(int i) {
096: Object field = fieldList.get(i);
097: if (field instanceof CMRFieldBridge) {
098: return ((CMRFieldBridge) field).getRelatedEntity();
099: } else if (field instanceof EntityBridge) {
100: return (EntityBridge) field;
101: } else {
102: return null;
103: }
104: }
105:
106: public int size() {
107: return fieldList.size();
108: }
109:
110: public String toString() {
111: return pathList.get(pathList.size() - 1) + " <" + type + ">";
112: }
113:
114: public boolean equals(Object o) {
115: if (o instanceof ASTPath) {
116: ASTPath path = (ASTPath) o;
117: return path.getPath().equals(getPath());
118: }
119: return false;
120: }
121:
122: public int hashCode() {
123: return getPath().hashCode();
124: }
125:
126: /**
127: * Accept the visitor. *
128: */
129: public Object jjtAccept(JBossQLParserVisitor visitor, Object data) {
130: return visitor.visit(this, data);
131: }
132: }
|