KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.xquark.extractor.common.SqlWrapperException;
29 import org.xquark.extractor.sql.SqlExpression;
30
31 /**
32  * Used in the the following kind of queries:
33  *
34  * for $i in collection("TABLE")/TABLE[count(COL2)=1]
35  * return
36  * <a>
37  * {$i/COL1}
38  * </a>
39  *
40  */

41 public final class IfThenElse extends Expression {
42
43     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
44     private static final String JavaDoc RCSName = "$Name: $";
45
46     protected Expression _if;
47     protected Expression _then;
48     protected Expression _else;
49
50     public IfThenElse() {}
51
52     public IfThenElse(Expression iif, Expression tthen, Expression eelse) {
53         setIf(iif);
54         setThen(tthen);
55         setElse(eelse);
56     }
57
58     synchronized Object JavaDoc clone(Map JavaDoc clonedExprs)
59         throws CloneNotSupportedException JavaDoc {
60         //Trace.enter(this, "clone(Map clonedExprs)");
61
IfThenElse retVal = (IfThenElse) super.clone(clonedExprs);
62         retVal.setIf(
63             (getIf() == null) ? null : (Expression) getIf().clone(clonedExprs));
64         retVal.setThen(
65             (getThen() == null)
66                 ? null
67                 : (Expression) getThen().clone(clonedExprs));
68         retVal.setElse(
69             (getElse() == null)
70                 ? null
71                 : (Expression) getElse().clone(clonedExprs));
72         clonedExprs.put(this, retVal);
73         //Trace.exit(this, "clone(Map clonedExprs)");
74
return retVal;
75     }
76
77     public Expression getIf() {
78         return _if;
79     }
80
81     public void setIf(Expression iif) {
82         _if = iif;
83     }
84
85     public Expression getThen() {
86         return _then;
87     }
88
89     public void setThen(Expression tthen) {
90         _then = tthen;
91     }
92
93     public Expression getElse() {
94         return _else;
95     }
96
97     public void setElse(Expression eelse) {
98         _else = eelse;
99     }
100
101     public List JavaDoc getOperands() {
102         return null;
103     }
104
105     public boolean replaceChild(Expression oldChild, Expression newChild) {
106         //Trace.enter(this,"replaceChild(Expression oldChild, Expression newChild)");
107
boolean retVal = false;
108
109         if (getIf().equals(oldChild)) {
110             setIf(newChild);
111             retVal = true;
112         }
113         else if (getThen().equals(oldChild)) {
114             setThen(newChild);
115             retVal = true;
116         }
117         else if (getElse().equals(oldChild)) {
118             setElse(newChild);
119             retVal = true;
120         }
121
122         //Trace.exit(this,"replaceChild(Expression oldChild, Expression newChild)");
123
return retVal;
124     }
125
126     public SqlExpression accept(GenSqlVisitor visitor)
127         throws SqlWrapperException {
128         return visitor.visit(this);
129     }
130
131     public void accept(AlgebraVisitor visitor) throws SqlWrapperException {
132         visitor.visit(this);
133     }
134
135     /**
136      * The semantics chosen for equals of algebra nodes is "the same algebra operator
137      * hierarchy referring to the same database objects".
138      * @param o the expression to be compared with this.
139      */

140     public boolean deepEquals(Object JavaDoc o) {
141         if (o instanceof IfThenElse) {
142             IfThenElse cast = (IfThenElse) o;
143             return _if.deepEquals(cast.getIf())
144                 && _then.deepEquals(cast.getThen())
145                 && _else.deepEquals(cast.getElse());
146         }
147         return false;
148     }
149 }
150
Popular Tags