KickJava   Java API By Example, From Geeks To Geeks.

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


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.xquery.parser.XQueryException;
27
28 public class QTypeDocument extends QTypeNode implements QTypeVisitable {
29     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
30     private static final String JavaDoc RCSName = "$Name: $";
31
32     public static final byte ANY_ORIGIN = 0;
33     public static final byte COLLECTION_ORIGIN = 1;
34     public static final byte DOCUMENT_ORIGIN = 2;
35
36     private QType qtype = null;
37     private byte origin = ANY_ORIGIN;
38
39     public QTypeDocument(QType qtype, byte origin) {
40         this.qtype = qtype;
41         subclass = DOCUMENT;
42         occurence = OCC_1_1;
43         this.origin = origin;
44     }
45     public QTypeDocument(QType qtype, byte occurence, byte origin) {
46         this.qtype = qtype;
47         subclass = DOCUMENT;
48         this.occurence = occurence;
49         this.origin = origin;
50     }
51
52     // #############################################################################
53
// VISITOR STUFF
54
// #############################################################################
55

56     public void accept(QTypeVisitor visitor) throws XQueryException {
57         visitor.visit(this);
58     }
59
60     // get/set
61
public QType getQType() {
62         return qtype;
63     }
64
65     public void setQType(QType qtype) throws TypeException {
66         this.qtype = qtype;
67     }
68
69     // public Type getType() {
70
// return qtype.getType();
71
// }
72

73     // equals
74

75     public boolean equals(Object JavaDoc type) {
76         if (!(type instanceof QTypeDocument))
77             return false;
78 // if (((QTypeDocument) qtype).getOccurence() != occurence)
79
// return false;
80
return qtype.equals(((QTypeDocument) type).getQType());
81     }
82
83     // tells whether qtype is a node
84
public boolean isNode() {
85         if (qtype == null)
86             return false;
87         return qtype.isNode();
88     }
89
90     // tells whether qtype is a node with simple type
91
public boolean isSimpleTypeNode() {
92         if (qtype == null)
93             return false;
94         return qtype.isSimpleTypeNode();
95     }
96
97     // tells whether qtype is a collection
98
public boolean isCollection() {
99         return false;
100     }
101
102     // tells whether qtype is a document
103
public boolean isDocument() {
104         return true;
105     }
106
107     // tells whether qtype is multiple
108
// public boolean isMultiple() {
109
// return false;
110
// }
111

112     // tells whether qtype is mixed
113
public boolean isMixed() {
114         if (qtype == null)
115             return false;
116         return qtype.isMixed();
117     }
118
119     // tells whether qtype is element
120
public boolean isElement() {
121         if (qtype == null)
122             return false;
123         return qtype.isElement();
124     }
125
126     public boolean canBeComparedTo(QType compType) {
127         if (compType == null)
128             return false;
129         if (!(compType instanceof QTypeDocument))
130             return qtype.canBeComparedTo(compType);
131         return qtype.canBeComparedTo(((QTypeDocument) compType).getQType());
132     }
133
134     //public Object getSubType(String namespace, String localname, boolean isAttribute, boolean inDepth, ArrayList history) throws TypeException {
135
// Olivier: 2002/11/19
136
// public Object getSubType(QName qname, int axis, boolean inDepth, ArrayList history, ArrayList reslist, SchemaManager schemamanager) throws TypeException {
137
// if (qtype == null)
138
// return null;
139
// Object obj = qtype.getSubType(qname, axis, inDepth, history, reslist, schemamanager);
140
// return obj;
141
// }
142
//
143
// public QType applyTEXTFunction(boolean inDepth, ArrayList history, SchemaManager schemamanager) throws TypeException {
144
// if (qtype == null)
145
// return null;
146
// QType type = qtype.applyTEXTFunction(inDepth, history, schemamanager);
147
// if (type != null)
148
// return new QTypeDocument(type);
149
// return null;
150
// }
151
//
152

153     public QType applyDATAFunction() throws TypeException {
154         if (qtype == null)
155             return null;
156         return qtype.applyDATAFunction();
157     }
158         
159     //
160
// public QType applyNODEFunction(int axis, ArrayList history, ArrayList reslist, SchemaManager schemamanager) throws TypeException {
161
// if (qtype == null)
162
// return null;
163
// QType type = qtype.applyNODEFunction(axis, history, reslist, schemamanager);
164
// if (type != null)
165
// return new QTypeDocument(type);
166
// return null;
167
// }
168

169     // get origin
170
public boolean isFromDocument() {
171         return (origin == DOCUMENT_ORIGIN);
172     }
173     // clone
174
public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
175         QTypeDocument newObj = new QTypeDocument(qtype, occurence, origin);
176         return newObj;
177     }
178     // print
179
public String JavaDoc toSimpleString() {
180         return "QTypeDocument(" + qtype + ")";
181     }
182
183     public String JavaDoc toString() {
184         return "QTypeDocument(" + qtype + ")";
185     }
186
187 }
188
Popular Tags