KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > xfunctions > AfCast


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.xfunctions;
24
25 import java.util.List JavaDoc;
26
27 import org.xquark.extractor.algebra.Expression;
28 import org.xquark.extractor.sql.SqlExpression;
29 import org.xquark.jdbc.typing.DbType;
30
31 public final class AfCast extends Expression {
32
33     private static final String JavaDoc RCSRevision = "$Revision: 1.6 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36
37     Expression _expression = null;
38     DbType _targetType = null;
39
40     public AfCast()
41     {
42     }
43
44     public AfCast(Expression arg, DbType targetType)
45     {
46         setExpression(arg);
47         setTargetType(targetType);
48     }
49
50     public Expression getExpression()
51     {
52         return _expression;
53     }
54
55     public List JavaDoc getOperands()
56     {
57         return null;
58     }
59
60     public void setExpression(Expression expression)
61     {
62         _expression = expression;
63         _expression.setFather(this);
64     }
65
66     public DbType getTargetType()
67     {
68         return _targetType;
69     }
70
71     public void setTargetType(DbType targetType)
72     {
73         _targetType = targetType;
74     }
75
76     public String JavaDoc getName()
77     {
78         return getExpression().getName();
79     }
80
81     public boolean replaceChild(Expression oldChild, Expression newChild)
82     {
83         //Trace.enter(this, "replaceChild(Expression oldChild, Expression newChild)");
84
boolean retVal = false;
85
86         if (getExpression().equals(oldChild)) {
87             setExpression(newChild);
88             retVal = true;
89         }
90
91         //Trace.exit(this, "replaceChild(Expression oldChild, Expression newChild)");
92
return retVal;
93     }
94
95     public String JavaDoc pprint()
96     {
97         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
98         retVal.append("AfCast(");
99         retVal.append(getExpression().pprint());
100         retVal.append(", ");
101         retVal.append(getTargetType().pprint());
102         retVal.append(")");
103         return retVal.toString();
104     }
105
106     public SqlExpression accept(org.xquark.extractor.algebra.GenSqlVisitor visitor)
107     {
108         return visitor.visit(this);
109     }
110
111     public void accept(org.xquark.extractor.algebra.AlgebraVisitor visitor)
112     {
113         visitor.visit(this);
114     }
115     
116     /**
117      * The semantics chosen for equals of algebra nodes is "the same algebra operator
118      * hierarchy referring to the same database objects".
119      * @param o the expression to be compared with this.
120      */

121     public boolean deepEquals(Object JavaDoc o)
122     {
123         if (o instanceof AfCast)
124         {
125             AfCast cast = (AfCast)o;
126             return _expression.deepEquals(cast.getExpression())
127                         && _targetType.equals(cast.getTargetType()); // NOTE: assuming metadata object are not duplicated...
128
}
129         return false;
130     }
131 }
132
133
Popular Tags