KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > type > AnyType


1 package net.sf.saxon.type;
2
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.expr.StaticContext;
5 import net.sf.saxon.expr.StaticProperty;
6 import net.sf.saxon.om.NodeInfo;
7 import net.sf.saxon.om.SequenceIterator;
8 import net.sf.saxon.om.SingletonIterator;
9 import net.sf.saxon.style.StandardNames;
10 import net.sf.saxon.value.UntypedAtomicValue;
11 import net.sf.saxon.value.Value;
12
13 import java.io.Serializable JavaDoc;
14
15 /**
16  * This class has a singleton instance which represents the XML Schema built-in type xs:anyType,
17  * also known as the urtype.
18  */

19
20 public final class AnyType implements ComplexType, Serializable JavaDoc {
21
22     private static AnyType theInstance = new AnyType();
23
24     /**
25      * Private constructor
26      */

27     private AnyType() {
28         super();
29     }
30
31     /**
32      * Get the singular instance of this class
33      * @return the singular object representing xs:anyType
34      */

35
36     public static AnyType getInstance() {
37         return theInstance;
38     }
39
40     /**
41      * Get the validation status - always valid
42      */

43     public int getValidationStatus() {
44         return VALIDATED;
45     }
46
47     /**
48      * Get the base type
49      * @return null (this is the root of the type hierarchy)
50      */

51
52     public SchemaType getBaseType() {
53         return null;
54     }
55
56     /**
57      * Returns the base type that this type inherits from. This method can be used to get the
58      * base type of a type that is known to be valid.
59      * If this type is a Simpletype that is a built in primitive type then null is returned.
60      *
61      * @return the base type.
62      * @throws IllegalStateException if this type is not valid.
63      */

64
65     public SchemaType getKnownBaseType() throws IllegalStateException JavaDoc {
66         return null;
67     }
68
69     /**
70      * Gets the integer code of the derivation method used to derive this type from its
71      * parent. Returns zero for primitive types.
72      *
73      * @return a numeric code representing the derivation method, for example
74      * {@link SchemaType#DERIVATION_RESTRICTION}
75      */

76
77     public int getDerivationMethod() {
78         return 0;
79     }
80
81     /**
82      * Determines whether derivation (of a particular kind)
83      * from this type is allowed, based on the "final" property
84      *
85      * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
86      * @return true if this kind of derivation is allowed
87      */

88
89     public boolean allowsDerivation(int derivation) {
90         return true;
91     }
92
93     /**
94      * Test whether this ComplexType has been marked as abstract.
95      * @return false: this class is not abstract.
96      */

97
98     public boolean isAbstract() {
99         return false;
100     }
101
102     /**
103      * Test whether this SchemaType is a complex type
104      *
105      * @return true if this SchemaType is a complex type
106      */

107
108     public boolean isComplexType() {
109         return true;
110     }
111
112     /**
113      * Test whether this SchemaType is a simple type
114      * @return true if this SchemaType is a simple type
115      */

116
117     public boolean isSimpleType() {
118         return false;
119     }
120
121     /**
122      * Returns the value of the 'block' attribute for this type, as a bit-signnificant
123      * integer with fields such as {@link SchemaType#DERIVATION_LIST} and {@link SchemaType#DERIVATION_EXTENSION}
124      *
125      * @return the value of the 'block' attribute for this type
126      */

127
128     public int getBlock() {
129         return 0;
130     }
131
132     /**
133      * Test whether this complex type has complex content
134      * @return true: this complex type has complex content
135      */

136     public boolean isComplexContent() {
137         return true;
138     }
139
140     /**
141      * Test whether this complex type has simple content
142      * @return false: this complex type has complex content
143      */

144
145     public boolean isSimpleContent() {
146         return false;
147     }
148
149     /**
150      * Test whether this complex type has "all" content, that is, a content model
151      * using an xs:all compositor
152      * @return false: this complex type does not use an "all" compositor
153      */

154
155     public boolean isAllContent() {
156         return false;
157     }
158
159     /**
160      * For a complex type with simple content, return the simple type of the content.
161      * Otherwise, return null.
162      * @return null: this complex type does not have simple content
163      */

164
165     public SimpleType getSimpleContentType() {
166         return null;
167     }
168
169     /**
170      * Test whether this complex type is derived by restriction
171      * @return false: this type is not a restriction
172      */

173     public boolean isRestricted() {
174         return false;
175     }
176
177     /**
178      * Test whether the content type of this complex type is empty
179      * @return false: the content model is not empty
180      */

181
182     public boolean isEmptyContent() {
183         return false;
184     }
185
186     /**
187      * Test whether the content model of this complexType allows empty content
188      * @return true: the content is allowed to be empty
189      */

190
191     public boolean isEmptiable() {
192         return true;
193     }
194
195     /**
196      * Test whether this complex type allows mixed content
197      * @return true: mixed content is allowed
198      */

199
200     public boolean isMixedContent() {
201         return true;
202     }
203
204     /**
205      * Get the fingerprint of the name of this type
206      * @return the fingerprint.
207      */

208
209     public int getFingerprint() {
210         return StandardNames.XS_ANY_TYPE;
211     }
212
213     /**
214      * Get the namecode of the name of this type. This includes the prefix from the original
215      * type declaration: in the case of built-in types, there may be a conventional prefix
216      * or there may be no prefix.
217      */

218
219     public int getNameCode() {
220         return StandardNames.XS_ANY_TYPE;
221     }
222
223     /**
224      * Get a description of this type for use in diagnostics
225      * @return the string "xs:anyType"
226      */

227
228     public String JavaDoc getDescription() {
229         return "xs:anyType";
230     }
231
232     /**
233      * Get the display name of the type: that is, a lexical QName with an arbitrary prefix
234      *
235      * @return a lexical QName identifying the type
236      */

237
238     public String JavaDoc getDisplayName() {
239         return "xs:anyType";
240     }
241
242     /**
243      * Test whether this is the same type as another type. They are considered to be the same type
244      * if they are derived from the same type definition in the original XML representation (which
245      * can happen when there are multiple includes of the same file)
246      */

247
248     public boolean isSameType(SchemaType other) {
249         return (other instanceof AnyType);
250     }
251
252     /**
253      * Analyze an expression to see whether the expression is capable of delivering a value of this
254      * type.
255      *
256      @param expression the expression that delivers the content
257      * @param kind the node kind whose content is being delivered: {@link net.sf.saxon.type.Type#ELEMENT},
258           * {@link net.sf.saxon.type.Type#ATTRIBUTE}, or {@link net.sf.saxon.type.Type#DOCUMENT}
259      * @param env
260
261      */

262
263     public void analyzeContentExpression(Expression expression, int kind, StaticContext env) {
264         return;
265     }
266
267     /**
268      * Get the typed value of a node that is annotated with this schema type
269      * @param node the node whose typed value is required
270      * @return an iterator returning a single untyped atomic value, equivalent to the string value of the node. This
271      * follows the standard rules for elements with mixed content.
272      */

273
274     public SequenceIterator getTypedValue(NodeInfo node) {
275         return SingletonIterator.makeIterator(new UntypedAtomicValue(node.getStringValue()));
276     }
277
278     /**
279      * Get the typed value of a node that is annotated with this schema type. The result of this method will always be consistent with the method
280      * {@link #getTypedValue}. However, this method is often more convenient and may be
281      * more efficient, especially in the common case where the value is expected to be a singleton.
282      *
283      * @param node the node whose typed value is required
284      * @return the typed value.
285      * @since 8.5
286      */

287
288     public Value atomize(NodeInfo node) {
289         return new UntypedAtomicValue(node.getStringValue());
290     }
291
292     /**
293      * Test whether this complex type subsumes another complex type. The algorithm
294      * used is as published by Thompson and Tobin, XML Europe 2003.
295      * @param sub the other type (the type that is derived by restriction, validly or otherwise)
296      * @return null indicating that this type does indeed subsume the other; or a string indicating
297      * why it doesn't.
298      */

299
300     public String JavaDoc subsumes(ComplexType sub) {
301         return null;
302     }
303
304     /**
305      * Check that this type is validly derived from a given type
306      *
307      * @param type the type from which this type is derived
308      * @param block the derivations that are blocked by the relevant element declaration
309      * @throws SchemaException
310      * if the derivation is not allowed
311      */

312
313     public void isTypeDerivationOK(SchemaType type, int block) throws SchemaException {
314         throw new SchemaException("Cannot derive xs:anyType from another type");
315     }
316
317     /**
318      * Find an element particle within this complex type definition having a given element name
319      * (identified by fingerprint), and return the schema type associated with that element particle.
320      * If there is no such particle, return null. If the fingerprint matches an element wildcard,
321      * return the type of the global element declaration with the given name if one exists, or AnyType
322      * if none exists and lax validation is permitted by the wildcard.
323      *
324      * @param fingerprint Identifies the name of the child element within this content model
325      */

326
327     public SchemaType getElementParticleType(int fingerprint) {
328         return this;
329     }
330
331     /**
332      * Find an element particle within this complex type definition having a given element name
333      * (identified by fingerprint), and return the cardinality associated with that element particle,
334      * that is, the number of times the element can occur within this complex type. The value is one of
335      * {@link net.sf.saxon.expr.StaticProperty#EXACTLY_ONE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_ONE},
336      * {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_MORE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ONE_OR_MORE},
337      * If there is no such particle, return zero.
338      *
339      * @param fingerprint Identifies the name of the child element within this content model
340      */

341
342     public int getElementParticleCardinality(int fingerprint) {
343         return StaticProperty.ALLOWS_ZERO_OR_MORE;
344     }
345
346     /**
347      * Find an attribute use within this complex type definition having a given attribute name
348      * (identified by fingerprint), and return the schema type associated with that attribute.
349      * If there is no such attribute use, return null. If the fingerprint matches an attribute wildcard,
350      * return the type of the global attribute declaration with the given name if one exists, or AnySimpleType
351      * if none exists and lax validation is permitted by the wildcard.
352      *
353      * @param fingerprint Identifies the name of the child element within this content model
354      */

355
356     public SchemaType getAttributeUseType(int fingerprint) {
357         return AnySimpleType.getInstance();
358     }
359 }
360
361
362 //
363
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
364
// you may not use this file except in compliance with the License. You may obtain a copy of the
365
// License at http://www.mozilla.org/MPL/
366
//
367
// Software distributed under the License is distributed on an "AS IS" basis,
368
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
369
// See the License for the specific language governing rights and limitations under the License.
370
//
371
// The Original Code is: all this file.
372
//
373
// The Initial Developer of the Original Code is Saxonica Limited
374
//
375
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
376
//
377
// Contributor(s): none
378
//
Popular Tags