KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > Expression


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.algebra;
24
25 import java.util.*;
26
27 import org.xquark.extractor.common.Debug;
28 import org.xquark.extractor.common.SqlWrapperException;
29 import org.xquark.extractor.sql.SqlExpression;
30 import org.xquark.xquery.parser.XQueryExpression;
31
32 public abstract class Expression implements Cloneable JavaDoc, Constants
33 {
34     private static final String JavaDoc RCSRevision = "$Revision: 1.6 $";
35     private static final String JavaDoc RCSName = "$Name: $";
36
37     protected SqlType _type;
38     protected Expression _father;
39     protected XQueryExpression _OrginalXExpr;
40     protected Set _referredAttributes;
41     protected Mapper _mapper;
42
43     /**
44      * Access method for the _father property.
45      *
46      * @return the current value of the _father property
47      */

48     public org.xquark.extractor.algebra.Expression getFather()
49     {
50         return _father;
51     }
52
53     /**
54      * Sets the value of the _father property.
55      *
56      * @param aFather
57      * the new value of the _father property
58      */

59     public void setFather(org.xquark.extractor.algebra.Expression aFather)
60     {
61         _father = aFather;
62     }
63
64     /**
65      * Access method for the _OrginalXExpr property.
66      *
67      * @return the current value of the _OrginalXExpr property
68      */

69     public XQueryExpression getOrginalXExpr()
70     {
71         return _OrginalXExpr;
72     }
73
74     /**
75      * Sets the value of the _OrginalXExpr property.
76      *
77      * @param aOrginalXExpr
78      * the new value of the _OrginalXExpr property
79      */

80     public void setOrginalXExpr(XQueryExpression aOrginalXExpr)
81     {
82         _OrginalXExpr = aOrginalXExpr;
83     }
84
85
86     public void setType(SqlType type)
87     {
88         _type = type;
89     }
90
91     /**
92      * Access method for the _referredAttributes property.
93      *
94      * @return the current value of the _referredAttributes property
95      */

96     public Set getReferredAttributes()
97     {
98         return _referredAttributes;
99     }
100
101     /**
102      * Sets the value of the _referredAttributes property.
103      *
104      * @param aReferredAttributes
105      * the new value of the _referredAttributes property
106      */

107     public void setReferredAttributes(Set aReferredAttributes)
108     {
109         _referredAttributes = aReferredAttributes;
110     }
111
112     /**
113      * Access method for the _mapper property.
114      *
115      * @return the current value of the _mapper property
116      */

117     public Mapper getMapper()
118     {
119         /* default implementation*/
120         return _mapper;
121     }
122
123     /**
124      * Sets the value of the _mapper property.
125      *
126      * @param aMapper
127      * the new value of the _mapper property
128      */

129     public void setMapper(Mapper aMapper)
130     {
131         //_mapper = mapper;
132
_mapper = aMapper;
133     }
134
135     public abstract List getOperands();
136
137     public SqlType getType()
138     {
139         return _type;
140     }
141
142     public List getChildren()
143     {
144         Debug.nyi("List getChildren()");
145         return null;
146     }
147
148     public String JavaDoc pprint()
149     {
150         return this.getClass().getName();
151     }
152
153     public String JavaDoc toString() {
154         return pprint();
155     }
156
157     // TODO: implement a deep clone without map
158
public synchronized Object JavaDoc clone() throws CloneNotSupportedException JavaDoc
159     {
160         Object JavaDoc retVal = null;
161         Map clonedExprs = new HashMap(500);
162         retVal = clone(clonedExprs);
163         clonedExprs.clear();
164         clonedExprs = null;
165
166         return retVal;
167     }
168
169     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc
170     {
171         return super.clone();
172     }
173
174     public String JavaDoc getName()
175     {
176         return null;
177     }
178
179     public boolean replaceChild(Expression oldChild, Expression newChild)
180     {
181         Debug.assertTrue(false,"NYI!! for " + this.pprint());
182         return false;
183     }
184
185     public abstract SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException;
186
187     public abstract void accept (AlgebraVisitor visitor) throws SqlWrapperException;
188
189     public Set getReferredTableInstances()
190     {
191         Set retVal = new HashSet();
192         if (null != _referredAttributes) {
193             Iterator iter = _referredAttributes.iterator();
194             AttributeExpression item;
195             while (iter.hasNext()) {
196                 item = (AttributeExpression)iter.next();
197                 retVal.add(item.getTableInstance());
198             }
199         }
200         return retVal;
201     }
202     
203     /**
204      * The semantics chosen for equals of algebra nodes is "the same algebra operator
205      * hierarchy (aliases ignored) referring to the same database objects".
206      * @param o the expression to be compared with this.
207      */

208     public abstract boolean deepEquals(Object JavaDoc o);
209 }
210
211
Popular Tags