KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
29 import org.xquark.xquery.parser.QName;
30 import org.xquark.xquery.parser.XQueryException;
31 import org.xquark.xquery.parser.XQueryExpression;
32
33 public class QTypeAttribute extends QTypeNode implements QTypeVisitable {
34     private static final String JavaDoc RCSRevision = "$Revision: 1.7 $";
35     private static final String JavaDoc RCSName = "$Name: $";
36
37     QName name = null;
38     AttributeDeclaration attDecl = null;
39     
40     public QTypeAttribute(QName name, SimpleType simpleType) {
41         this.name = name;
42         setType(simpleType);
43         subclass = ATTRIBUTE;
44         occurence = OCC_1_1;
45     }
46     public QTypeAttribute(QName name, SimpleType simpleType, byte occurence) {
47         this.name = name;
48         setType(simpleType);
49         subclass = ATTRIBUTE;
50         this.occurence = occurence;
51     }
52     public QTypeAttribute(QName name, AttributeDeclaration attDecl, SimpleType simpleType) {
53         this.name = name;
54         setType(simpleType);
55         setAttributeDeclaration(attDecl);
56         subclass = ATTRIBUTE;
57         occurence = OCC_1_1;
58     }
59     public QTypeAttribute(QName name, AttributeDeclaration attDecl, SimpleType simpleType, byte occurence) {
60         this.name = name;
61         setType(simpleType);
62         setAttributeDeclaration(attDecl);
63         subclass = ATTRIBUTE;
64         this.occurence = occurence;
65     }
66
67     // #############################################################################
68
// VISITOR STUFF
69
// #############################################################################
70

71     public void accept(QTypeVisitor visitor) throws XQueryException {
72         visitor.visit(this);
73     }
74
75     // get/set
76

77     public XQueryExpression getName() {
78         return name;
79     }
80     
81     public AttributeDeclaration getAttributeDeclaration() {
82         return attDecl;
83     }
84
85     public void setAttributeDeclaration(AttributeDeclaration attDecl) {
86         this.attDecl = attDecl;
87     }
88
89     // equals
90
public boolean equals(Object JavaDoc qtype) {
91         if (!(qtype instanceof QTypeAttribute))
92             return false;
93 // if (((QTypeAttribute) qtype).getOccurence() != occurence)
94
// return false;
95
return compare(type, ((QTypeAttribute) qtype).getSimpleType()) && name.equals(((QTypeAttribute) qtype).getName());
96     }
97
98     // tells whether qtype is numeric
99
public boolean isNumeric() {
100         if (type == null)
101             return false;
102         else
103             return isNumeric(type);
104     }
105
106     // tells whether qtype is boolean
107
public boolean isBoolean() {
108         if (type == null)
109             return false;
110         else
111             return isBoolean(type);
112     }
113
114     // tells whether qtype is integer
115
public boolean isInteger() {
116         if (type == null)
117             return false;
118         else
119             return isInteger(type);
120     }
121
122     // tells whether qtype is string
123
public boolean isString() {
124         if (type == null)
125             return false;
126         else
127             return isString(type);
128     }
129
130     // // tells whether qtype is an atom
131
// public boolean isAtom() { return false; }
132

133     // tells whether qtype can react to text()
134
public boolean isText() {
135         return true;
136     }
137
138     // tells whether qtype is a date or collection of dates
139
public boolean isDate() {
140         if (type == null)
141             return false;
142         else
143             return isDate(type);
144     }
145
146     // tells whether qtype is a attribte or collection or sequence
147
public boolean isAttribute() {
148         return true;
149     }
150
151     // tells whether qtype is a ID, IDREF or IDREFS type
152
public boolean isIDAttribute() {
153         if (type == null)
154             return false;
155         if (type.getNamespace().equals(SchemaConstants.XMLSCHEMA_URI) && (type.getName().equals("ID") || type.getName().equals("IDREF") || type.getName().equals("IDREFS")))
156             return true;
157         return false;
158     }
159
160     // tells whether qtype is a node
161
public boolean isNode() {
162         return true;
163     }
164
165     // tells whether qtype is a node with simple type
166
public boolean isSimpleTypeNode() {
167         return true;
168     }
169
170     // tells whether qtype is atomic (atom or element with simple content
171
public boolean isAtomic() {
172         return !isMultiple();
173     }
174
175     public boolean canBeComparedTo(QType compType) {
176         if (compType == null)
177             return false;
178         if (!(compType instanceof QTypeAttribute))
179             return compType.canBeComparedTo(this);
180         if (type == null)
181             return true;
182         if (((QTypeAttribute) compType).getSimpleType() == null)
183             return true;
184         return canBeCompared(((SimpleType)type).getPrimitive().getType(), ((QTypeAttribute) compType).getSimpleType().getPrimitive().getType());
185     }
186
187     public QType applyTEXTFunction(boolean inDepth, ArrayList JavaDoc history, SchemaManager schemamanager) throws TypeException {
188         return new QTypeAtom((SimpleType) schemamanager.getType(SchemaConstants.XMLSCHEMA_URI, TypeVisitor.SC_STRING),occurence);
189     }
190
191     public QType applyDATAFunction() throws TypeException {
192         return new QTypeAtom((SimpleType)type,occurence);
193     }
194
195     public QType applyFILTERFunction() throws TypeException {
196         return this;
197     }
198
199     // clone
200
public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
201         QTypeAttribute newObj = new QTypeAttribute(name,attDecl,(SimpleType)type,occurence);
202         return newObj;
203     }
204     // print
205
public String JavaDoc toSimpleString() {
206         return "QTypeAttribute(" + name + " , " + type.getName() + ")";
207     }
208
209     public String JavaDoc toString() {
210         return "QTypeAttribute(" + name + " ,\n" + type + ")";
211     }
212
213 }
214
Popular Tags