KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > typing > QTypeElement


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.xquery.typing;
25
26 import org.xquark.schema.*;
27 import org.xquark.xquery.parser.XQueryException;
28 import org.xquark.xquery.parser.XQueryExpression;
29
30 public class QTypeElement extends QTypeNode implements QTypeVisitable {
31     private static final String JavaDoc RCSRevision = "$Revision: 1.9 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34     XQueryExpression name = null;
35     ElementDeclaration eltDecl = null;
36
37     public QTypeElement(XQueryExpression name, Type type) {
38         this.name = name;
39         setType(type);
40         subclass = ELEMENT;
41         occurence = OCC_1_1;
42         if (type == null) {
43             int i= 0;
44         }
45     }
46     public QTypeElement(XQueryExpression name, Type type, byte occurence) {
47         this.name = name;
48         setType(type);
49         subclass = ELEMENT;
50         this.occurence = occurence;
51         if (type == null) {
52             int i= 0;
53         }
54     }
55
56     public QTypeElement(XQueryExpression name, ElementDeclaration eltDecl, Type type) {
57         this.name = name;
58         setType(type);
59         setElementDeclaration(eltDecl);
60         subclass = ELEMENT;
61         occurence = OCC_1_1;
62         if (type == null) {
63             int i= 0;
64         }
65     }
66     public QTypeElement(XQueryExpression name, ElementDeclaration eltDecl, Type type, byte occurence) {
67         this.name = name;
68         setType(type);
69         setElementDeclaration(eltDecl);
70         subclass = ELEMENT;
71         this.occurence = occurence;
72         if (type == null) {
73             int i= 0;
74         }
75     }
76
77     // #############################################################################
78
// VISITOR STUFF
79
// #############################################################################
80

81     public void accept(QTypeVisitor visitor) throws XQueryException {
82         visitor.visit(this);
83     }
84
85     // get/set
86

87     public XQueryExpression getName() {
88         return name;
89     }
90
91     public ElementDeclaration getElementDeclaration() {
92         return eltDecl;
93     }
94
95     public void setElementDeclaration(ElementDeclaration eltDecl) {
96         this.eltDecl = eltDecl;
97     }
98
99     // equals
100
public boolean equals(Object JavaDoc qtype) {
101         if (!(qtype instanceof QTypeElement))
102             return false;
103         // TODO verify equality of name
104
// if (((QTypeElement) qtype).getOccurence() != occurence)
105
// return false;
106
return compare(type, ((QTypeElement) qtype).getType()) && name.equals(((QTypeElement) qtype).getName());
107     }
108
109     // tells whether qtype is numeric
110
public boolean isNumeric() {
111         return isNumeric(type);
112         /*
113          if (type.isSimpleType()) return isNumeric(type);
114         if (((ComplexType) type).getContentType() == SchemaConstants.MIXED) return true;
115         if (((ComplexType) type).isExtension()) return true;
116         else return false;
117          */

118     }
119
120     // tells whether qtype is boolean
121
public boolean isBoolean() {
122         return isBoolean(type);
123     }
124
125     // tells whether qtype is integer
126
public boolean isInteger() {
127         return isInteger(type);
128     }
129
130     // tells whether qtype is string
131
public boolean isString() {
132         if (this.isMixed())
133             return true; // this is temporary
134
return isString(type);
135     }
136
137     // tells whether qtype is an atom
138
public boolean isAtom() {
139         return false;
140     }
141     // if (type.isSimpleType()) return true;
142
// // else if (((ComplexType) type).getContentType() == SchemaConstants.MIXED) return true;
143
// else if (((ComplexType) type).isExtension()) return true;
144
// else return false;
145
// }
146

147     // tells whether qtype can react to text()
148
public boolean isText() {
149         return true;
150     }
151
152     // tells whether qtype is a date or collection of dates
153
public boolean isDate() {
154         return isDate(type);
155     }
156
157     // tells whether qtype is a node
158
public boolean isNode() {
159         return true;
160     }
161
162     // tells whether qtype is a node with simple type
163
public boolean isSimpleTypeNode() {
164         if (type.getValueType() != null)
165             return true;
166         if (type.getName() != null && type.getName().equals(Type.ANY_TYPE))
167             return true;
168         return false;
169     }
170
171     // tells whether qtype is multiple
172
// public boolean isMultiple() {
173
// if (type.getName() != null && type.getName().equals("anyType"))
174
// return true;
175
// return false;
176
// }
177

178     // tells whether qtype is atomic (atom or element with simple content
179
public boolean isAtomic() {
180         if (type.getName() != null && type.getName().equals(TypeVisitor.SC_ANYTYPE))
181             return true;
182         if (this.isMixed())
183             return !isMultiple(); // this is temporary -- add 2002/09/02
184
if (type.getValueType() != null)
185             return !isMultiple();
186         return false;
187     }
188
189     // tells whether qtype is mixed
190
public boolean isMixed() {
191         if (type instanceof ComplexType && ((ComplexType) type).getContentType() == SchemaConstants.MIXED)
192             return true;
193         return false;
194     }
195
196     // tells whether qtype is element
197
public boolean isElement() {
198         return true;
199     }
200
201
202     public QType applyDATAFunction() throws TypeException {
203         if (type.getValueType() != null)
204             return new QTypeAtom(type.getValueType(), occurence);
205         if (type.getContentType() == Type.MIXED) {
206             //SchemaManager sm = new SchemaManager();
207
return new QTypeAtom(null, occurence);
208         }
209         return null;
210     }
211
212     // clone
213
public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
214         QTypeElement newObj = new QTypeElement(name, type, occurence);
215         return newObj;
216     }
217     public String JavaDoc toSimpleString() {
218         return "QTypeElement(" + name + " ," + type.getName() + ")";
219     }
220
221     public String JavaDoc toString() {
222         return "QTypeElement(" + name + " ,\n" + type + ")";
223     }
224
225 }
226
Popular Tags