KickJava   Java API By Example, From Geeks To Geeks.

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


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 XfCast 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 XfCast()
41     {
42     }
43
44     public XfCast(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 void setExpression(Expression expression)
56     {
57         _expression = expression;
58         _expression.setFather(this);
59     }
60
61     public DbType getTargetType()
62     {
63         return _targetType;
64     }
65
66     public void setTargetType(DbType targetType)
67     {
68         _targetType = targetType;
69     }
70
71     public String JavaDoc getName()
72     {
73         return null;
74     }
75
76     public List JavaDoc getOperands()
77     {
78         return null;
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("XfCast(");
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      * @see Expression#deepEquals(Object)
118      */

119     public boolean deepEquals(Object JavaDoc o)
120     {
121         if (o instanceof XfCast)
122         {
123             XfCast cast = (XfCast)o;
124             return _expression.deepEquals(cast.getExpression())
125                     && _targetType.equals(cast.getTargetType());
126         }
127         return false;
128     }
129 }
130
131
Popular Tags