KickJava   Java API By Example, From Geeks To Geeks.

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


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 complex type xdt:untyped,
17  * used for elements that have not been validated.
18  */

19
20 public final class Untyped implements ComplexType, Serializable JavaDoc {
21
22     /**
23      * Get the validation status - always valid
24      */

25     public int getValidationStatus() {
26         return VALIDATED;
27     }
28
29     /**
30      * Returns the value of the 'block' attribute for this type, as a bit-signnificant
31      * integer with fields such as {@link SchemaType#DERIVATION_LIST} and {@link SchemaType#DERIVATION_EXTENSION}
32      *
33      * @return the value of the 'block' attribute for this type
34      */

35
36     public int getBlock() {
37         return 0;
38     }
39
40     /**
41      * Gets the integer code of the derivation method used to derive this type from its
42      * parent. Returns zero for primitive types.
43      *
44      * @return a numeric code representing the derivation method, for example {@link SchemaType#DERIVATION_RESTRICTION}
45      */

46
47     public int getDerivationMethod() {
48         return 0;
49     }
50
51     /**
52      * Determines whether derivation (of a particular kind)
53      * from this type is allowed, based on the "final" property
54      *
55      * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
56      * @return true if this kind of derivation is allowed
57      */

58
59     public boolean allowsDerivation(int derivation) {
60         return false;
61     }
62
63     /**
64      * Check that this type is validly derived from a given type
65      *
66      * @param type the type from which this type is derived
67      * @param block the derivations that are blocked by the relevant element declaration
68      */

69
70     public void isTypeDerivationOK(SchemaType type, int block) {
71
72     }
73
74     private static Untyped theInstance = new Untyped();
75
76     /**
77      * Private constructor
78      */

79     private Untyped() {}
80
81     /**
82      * Get the fingerprint of the name of this type
83      *
84      * @return the fingerprint. Returns an invented fingerprint for an anonymous type.
85      */

86
87     public int getFingerprint() {
88         return StandardNames.XDT_UNTYPED;
89     }
90
91     /**
92      * Get the namecode of the name of this type. This includes the prefix from the original
93      * type declaration: in the case of built-in types, there may be a conventional prefix
94      * or there may be no prefix.
95      */

96
97     public int getNameCode() {
98         return StandardNames.XDT_UNTYPED;
99     }
100
101     /**
102      * Get the display name of the type: that is, a lexical QName with an arbitrary prefix
103      *
104      * @return a lexical QName identifying the type
105      */

106
107     public String JavaDoc getDisplayName() {
108         return "xdt:untyped";
109     }
110
111     /**
112      * Test whether this SchemaType is a complex type
113      *
114      * @return true if this SchemaType is a complex type
115      */

116
117     public boolean isComplexType() {
118         return true;
119     }
120
121     /**
122      * Returns the base type that this type inherits from. This method can be used to get the
123      * base type of a type that is known to be valid.
124      * If this type is a Simpletype that is a built in primitive type then null is returned.
125      *
126      * @return the base type.
127      * @throws IllegalStateException if this type is not valid.
128      */

129
130     public SchemaType getKnownBaseType() throws IllegalStateException JavaDoc {
131         return AnyType.getInstance();
132     }
133
134     /**
135      * Test whether this is the same type as another type. They are considered to be the same type
136      * if they are derived from the same type definition in the original XML representation (which
137      * can happen when there are multiple includes of the same file)
138      */

139
140     public boolean isSameType(SchemaType other) {
141         return (other instanceof Untyped);
142     }
143
144     /**
145      * Returns the base type that this type inherits from.
146      * If this type is a Simpletype that is a built in primitive type then null is returned.
147      *
148      * @return the base type.
149      */

150
151     public SchemaType getBaseType() {
152         return AnyType.getInstance();
153     }
154
155
156     /**
157      * Get the singular instance of this class
158      * @return the singular object representing xs:anyType
159      */

160
161     public static Untyped getInstance() {
162         return theInstance;
163     }
164
165     /**
166      * Test whether this ComplexType has been marked as abstract.
167      * @return false: this class is not abstract.
168      */

169
170     public boolean isAbstract() {
171         return false;
172     }
173
174     /**
175      * Test whether this SchemaType is a simple type
176      * @return true if this SchemaType is a simple type
177      */

178
179     public boolean isSimpleType() {
180         return false;
181     }
182
183     /**
184      * Test whether this complex type has complex content
185      * @return true: this complex type has complex content
186      */

187     public boolean isComplexContent() {
188         return true;
189     }
190
191     /**
192      * Test whether this complex type has simple content
193      * @return false: this complex type has complex content
194      */

195
196     public boolean isSimpleContent() {
197         return false;
198     }
199
200     /**
201      * Test whether this complex type has "all" content, that is, a content model
202      * using an xs:all compositor
203      * @return false: this complex type does not use an "all" compositor
204      */

205
206     public boolean isAllContent() {
207         return false;
208     }
209
210     /**
211      * For a complex type with simple content, return the simple type of the content.
212      * Otherwise, return null.
213      * @return null: this complex type does not have simple content
214      */

215
216     public SimpleType getSimpleContentType() {
217         return null;
218     }
219
220     /**
221      * Test whether this complex type is derived by restriction
222      * @return true: this type is treated as a restriction of xs:anyType
223      */

224     public boolean isRestricted() {
225         return true;
226     }
227
228     /**
229      * Test whether the content type of this complex type is empty
230      * @return false: the content model is not empty
231      */

232
233     public boolean isEmptyContent() {
234         return false;
235     }
236
237     /**
238      * Test whether the content model of this complexType allows empty content
239      * @return true: the content is allowed to be empty
240      */

241
242     public boolean isEmptiable() {
243         return true;
244     }
245
246     /**
247      * Test whether this complex type allows mixed content
248      * @return true: mixed content is allowed
249      */

250
251     public boolean isMixedContent() {
252         return true;
253     }
254
255     /**
256      * Get a description of this type for use in diagnostics
257      * @return the string "xs:anyType"
258      */

259
260     public String JavaDoc getDescription() {
261         return "xdt:untyped";
262     }
263
264     /**
265      * Analyze an expression to see whether the expression is capable of delivering a value of this
266      * type.
267      *
268      @param expression the expression that delivers the content
269      * @param kind the node kind whose content is being delivered: {@link Type#ELEMENT},
270           * {@link Type#ATTRIBUTE}, or {@link Type#DOCUMENT}
271      * @param env
272
273      */

274
275     public void analyzeContentExpression(Expression expression, int kind, StaticContext env) {
276         return;
277     }
278
279     /**
280      * Get the typed value of a node that is annotated with this schema type
281      * @param node the node whose typed value is required
282      * @return an iterator returning a single untyped atomic value, equivalent to the string value of the node. This
283      * follows the standard rules for elements with mixed content.
284      */

285
286     public SequenceIterator getTypedValue(NodeInfo node) {
287         return SingletonIterator.makeIterator(new UntypedAtomicValue(node.getStringValueCS()));
288     }
289
290     /**
291      * 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
292      * {@link #getTypedValue}. However, this method is often more convenient and may be
293      * more efficient, especially in the common case where the value is expected to be a singleton.
294      *
295      * @param node the node whose typed value is required
296      * @return the typed value.
297      * @since 8.5
298      */

299
300     public Value atomize(NodeInfo node) {
301         return new UntypedAtomicValue(node.getStringValue());
302     }
303
304     /**
305      * Test whether this complex type subsumes another complex type. The algorithm
306      * used is as published by Thompson and Tobin, XML Europe 2003.
307      * @param sub the other type (the type that is derived by restriction, validly or otherwise)
308      * @return null indicating that this type does indeed subsume the other; or a string indicating
309      * why it doesn't.
310      */

311
312     public String JavaDoc subsumes(ComplexType sub) {
313         return null;
314     }
315
316     /**
317      * Find an element particle within this complex type definition having a given element name
318      * (identified by fingerprint), and return the schema type associated with that element particle.
319      * If there is no such particle, return null. If the fingerprint matches an element wildcard,
320      * return the type of the global element declaration with the given name if one exists, or AnyType
321      * if none exists and lax validation is permitted by the wildcard.
322      *
323      * @param fingerprint Identifies the name of the child element within this content model
324      */

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

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

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