KickJava   Java API By Example, From Geeks To Geeks.

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


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.SqlWrapperException;
28 import org.xquark.extractor.sql.SqlExpression;
29 import org.xquark.xquery.parser.XQueryExpression;
30
31
32 /**
33  * NOTE: This 'Expression' does not seem to appear in the generated relational
34  * algebra. It correspond to XQuery variables bound to complex elements that are
35  * locally stored in the variable stack by the @link org.xquark.extractor.algebra.GenAlgebraVisitor
36  * but does not appear in the return clause and thus in the relational algebra tree.
37  */

38 public final class TupleExpression extends Expression {
39
40     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
41     private static final String JavaDoc RCSName = "$Name: $";
42
43
44     protected List _itemList;
45     protected RenameRelation _tableInstance;
46
47     public TupleExpression() {
48     }
49
50     public TupleExpression(RenameRelation tableInstance , List itemList, XQueryExpression aOrginalXExpr)
51     {
52         setTableInstance(tableInstance);
53         setItemList(itemList);
54         setOrginalXExpr(aOrginalXExpr);
55     }
56
57
58     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc
59     {
60         //Trace.enter(this, "clone(Map clonedExprs)");
61
TupleExpression retVal = (TupleExpression)super.clone(clonedExprs);
62         retVal.setItemList(AlgebraTools.clone(_itemList, clonedExprs));
63         clonedExprs.put(this, retVal);
64         //Trace.exit(this, "clone(Map clonedExprs)");
65
return retVal;
66     }
67
68
69     public RenameRelation getTableInstance()
70     {
71         return _tableInstance ;
72     }
73
74     public void setTableInstance(RenameRelation tableInstance)
75     {
76         _tableInstance = tableInstance;
77     }
78
79     /**
80     Access method for the _itemList property.
81
82     @return the current value of the _itemList property
83      */

84     public List getItemList()
85     {
86         return _itemList ;
87     }
88
89     public List getOperands() {
90         return null;
91     }
92
93     /**
94     Sets the value of the _itemList property.
95
96     @param aItemList the new value of the _itemList property
97      */

98     public void setItemList(List itemList)
99     {
100         //Trace.enter(this,"setItemList");
101

102         _itemList = itemList;
103
104         if (null==_itemList) {
105             return ;
106         }
107
108         Iterator iter = _itemList.iterator();
109         while (iter.hasNext()) {
110             Expression item = (Expression)iter.next();
111             item.setFather(this);
112         }
113
114         //Trace.exit(this,"setItemList");
115
}
116
117
118     /**
119     @param itemExpr
120     @roseuid 3B2787F00323
121      */

122     public void addItem(AttributeExpression itemExpr)
123     {
124         //Trace.enter(this,"addItem");
125

126         if ( null == _itemList )
127         {
128             _itemList = new ArrayList ();
129         }
130
131         _itemList.add ( itemExpr ) ;
132         itemExpr.setFather(this);
133
134         //Trace.exit(this,"addItem");
135
}
136
137
138     public void arithmeticOperation(int operater,Expression leftOperand,Expression rightOperand)
139     {
140         //Trace.enter(this,"ArithmeticOperation");
141

142 // Iterator iter = _itemList.iterator();
143
// Expression item ;
144
// List newItemList = new ArrayList();
145
// Expression arOp ;
146
// while (iter.hasNext()) {
147
// item = getRealExpression((Expression)iter.next());
148
// if (null != leftOperand) {
149
// arOp = new BinOpArithmetic (operater, leftOperand, item);
150
// }
151
// else {
152
// arOp = new BinOpArithmetic (operater, item, rightOperand);
153
// }
154
// newItemList.add (arOp);
155
// }
156
// setItemList(newItemList);
157
//Trace.exit (this,"ArithmeticOperation");
158
}
159
160
161
162
163     public void addNameTest (String JavaDoc name)
164     {
165         //Trace.enter( this , "addNameTest");
166
// /** @todo!!! */
167
// List items = ((Relation)_operand).nameTest(name);
168
// Iterator iter = items.iterator();
169
// while (iter.hasNext()) {
170
// Object item = iter.next();
171
// addItem((Expression)item);
172
// }
173
//Trace.exit( this , "addNameTest");
174
}
175
176     public List nameTest (String JavaDoc name)
177     {
178         //Trace.enter(this,"nameTest",name);
179

180         List retVal = null;
181
182 // if (name.equalsIgnoreCase("*") || null == name) {
183
// retVal = _itemList;
184
// // in this case , there will be a problem when there are duplicated name
185
// Trace.warn(this,"nameTest","wild card used in nameTest");
186
// }
187
// else {
188
// // Name is not a wild card
189
// retVal = new ArrayList ();
190
// for (int i = 0; i < _itemNames.size(); i++) {
191
// if (name.equalsIgnoreCase((String)_itemNames.get(i))) {
192
// retVal.add (_itemList.get(i));
193
// }
194
// }
195
// if (0==retVal.size()) {
196
// retVal = null;
197
// }
198
// }
199

200         //Trace.exit (this,"nameTest",name);
201
return retVal;
202     }
203
204     public boolean replaceChild(Expression oldChild, Expression newChild)
205     {
206         //Trace.enter(this, "replaceChild(Expression oldChild, Expression newChild)");
207
boolean retVal = false;
208
209         List list = getItemList();
210
211         Expression expr = null ;
212         for (int i = 0; i < list.size(); i++) {
213             expr = (Expression)list.get(i);
214             if (expr.equals(oldChild)) {
215                 list.set(i, newChild);
216                 newChild.setFather(this);
217                 retVal = true;
218                 break;
219             }
220         }
221
222         //Trace.exit(this, "replaceChild(Expression oldChild, Expression newChild)");
223
return retVal;
224     }
225
226     public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException
227     {
228         return visitor.visit(this);
229     }
230
231     public void accept (AlgebraVisitor visitor) throws SqlWrapperException
232     {
233         visitor.visit(this);
234     }
235
236     /**
237      * @see Expression#deepEquals(Object)
238      */

239     public boolean deepEquals(Object JavaDoc o)
240     {
241         if (o instanceof TupleExpression)
242         {
243             TupleExpression cast = (TupleExpression)o;
244             return _tableInstance.deepEquals(cast.getTableInstance()) // NOTE: assuming metadata object are not duplicated...
245
&& AlgebraTools.areExprListEquivalent(_itemList, cast.getItemList());
246         }
247         return false;
248     }
249 }
250
Popular Tags