KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 XQuark Group.
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 org.xquark.extractor.common.SqlWrapperException;
26 import org.xquark.extractor.sql.SqlExpression;
27 import org.xquark.jdbc.typing.MappingInfo;
28 import org.xquark.schema.SimpleType;
29
30 /**
31  * Features an external variable.
32  * NOTE: Not really correct to extend Literal, but in fact it is processed like
33  * a literal
34  */

35 public class ExternalVariable extends Literal {
36     private String JavaDoc _expandedName = null;
37     public MappingInfo _mappingInfo = null;
38     
39     public ExternalVariable(String JavaDoc ns, String JavaDoc localName, SimpleType sType) {
40         _expandedName = getExpandedName(ns, localName);
41         if (sType != null)
42             _mappingInfo = new MappingInfo(sType);
43     }
44
45     public static String JavaDoc getExpandedName(String JavaDoc ns, String JavaDoc varName) {
46         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
47         if (ns != null) {
48             sb.append('{');
49             sb.append(ns);
50             sb.append('}');
51         }
52         sb.append(varName);
53         return sb.toString();
54     }
55     
56     public SqlExpression accept(GenSqlVisitor visitor) throws SqlWrapperException {
57         return visitor.visit(this);
58     }
59
60     /**
61      * @return Returns the _expandedName.
62      */

63     public String JavaDoc getExpandedName() {
64         return _expandedName;
65     }
66     
67     public MappingInfo getMappingInfo() {
68         return _mappingInfo;
69     }
70
71     public SimpleType getSimpleType() {
72         return _mappingInfo.getXMLType();
73     }
74
75     public void accept(AlgebraVisitor visitor) throws SqlWrapperException {
76         visitor.visit(this);
77     }
78
79     public boolean deepEquals(Object JavaDoc o) {
80         if (o instanceof ExternalVariable)
81         {
82             ExternalVariable cast = (ExternalVariable)o;
83             return _expandedName.equals(cast.getExpandedName());
84         }
85         return false;
86     }
87 }
88
Popular Tags