KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
27
28 import org.xquark.schema.SchemaConstants;
29 import org.xquark.schema.SchemaManager;
30 import org.xquark.schema.SimpleType;
31 import org.xquark.xquery.parser.XQueryException;
32
33 public class QTypeText extends QTypeNode implements QTypeVisitable {
34     private static final String JavaDoc RCSRevision = "$Revision: 1.7 $";
35     private static final String JavaDoc RCSName = "$Name: $";
36
37     public QTypeText(SimpleType simpleType) {
38         setType(simpleType);
39         subclass = TEXT;
40         occurence = OCC_1_1;
41     }
42     public QTypeText(SimpleType simpleType, byte occurence) {
43         setType(simpleType);
44         subclass = TEXT;
45         this.occurence = occurence;
46     }
47
48     // #############################################################################
49
// VISITOR STUFF
50
// #############################################################################
51

52     public void accept(QTypeVisitor visitor) throws XQueryException {
53         visitor.visit(this);
54     }
55
56     // get/set
57
// public SimpleType getSimpleType() {
58
// return simpleType;
59
// }
60

61     // equals
62
public boolean equals(Object JavaDoc qtype) {
63         if (!(qtype instanceof QTypeText))
64             return false;
65 // if (((QTypeText) qtype).getOccurence() != occurence)
66
// return false;
67
return compare(type, ((QTypeText) qtype).getSimpleType());
68     }
69
70     // tells whether qtype is numeric
71
public boolean isNumeric() {
72         if (type == null)
73             return false;
74         else
75             return isNumeric(type);
76     }
77
78     // tells whether qtype is boolean
79
public boolean isBoolean() {
80         if (type == null)
81             return false;
82         else
83             return isBoolean(type);
84     }
85
86     // tells whether qtype is integer
87
public boolean isInteger() {
88         if (type == null)
89             return false;
90         else
91             return isInteger(type);
92     }
93
94     // tells whether qtype is string
95
public boolean isString() {
96         if (type == null || isMultiple())
97             return false;
98         else
99             return isString(type);
100     }
101
102     // // tells whether qtype is an atom
103
// public boolean isAtom() { return false; }
104

105 // // tells whether qtype can react to text()
106
// public boolean isText() {
107
// return true;
108
// }
109

110     // tells whether qtype is a date or collection of dates
111
public boolean isDate() {
112         if (type == null)
113             return false;
114         else
115             return isDate(type);
116     }
117
118     // tells whether qtype is a attribte or collection or sequence
119
public boolean isAttribute() {
120         return false;
121     }
122
123 // // tells whether qtype is a ID, IDREF or IDREFS type
124
// public boolean isIDAttribute() {
125
// if (type == null)
126
// return false;
127
// if (type.getNamespace().equals(SchemaConstants.XMLSCHEMA_URI) && (type.getName().equals("ID") || type.getName().equals("IDREF") || type.getName().equals("IDREFS")))
128
// return true;
129
// return false;
130
// }
131

132     // tells whether qtype is a node
133
public boolean isNode() {
134         return true;
135     }
136
137     // tells whether qtype is a node with simple type
138
public boolean isSimpleTypeNode() {
139         return true;
140     }
141
142     // tells whether qtype is atomic (atom or element with simple content
143
public boolean isAtomic() {
144         return !isMultiple();
145     }
146
147     public boolean canBeComparedTo(QType compType) {
148         if (compType == null)
149             return false;
150         if (!(compType instanceof QTypeText))
151             return compType.canBeComparedTo(this);
152         if (type == null)
153             return true;
154         if (((QTypeText) compType).getSimpleType() == null)
155             return true;
156         return canBeCompared(((SimpleType)type).getPrimitive().getType(), ((QTypeText) compType).getSimpleType().getPrimitive().getType());
157     }
158
159     public QType applyTEXTFunction(boolean inDepth, ArrayList JavaDoc history, SchemaManager schemamanager) throws TypeException {
160         return new QTypeAtom((SimpleType) schemamanager.getType(SchemaConstants.XMLSCHEMA_URI, TypeVisitor.SC_STRING),occurence);
161     }
162
163     public QType applyDATAFunction() throws TypeException {
164         return new QTypeAtom((SimpleType)type,occurence);
165     }
166
167     public QType applyFILTERFunction() throws TypeException {
168         return this;
169     }
170
171     // clone
172
public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
173         QTypeText newObj = new QTypeText((SimpleType)type,occurence);
174         return newObj;
175     }
176     // print
177
public String JavaDoc toSimpleString() {
178         return "QTypeText(" + type.getName() + ")";
179     }
180
181     public String JavaDoc toString() {
182         return "QTypeText(" + type + ")";
183     }
184
185 }
186
Popular Tags