KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.type;
2
3 import net.sf.saxon.ConversionContext;
4 import net.sf.saxon.expr.Expression;
5 import net.sf.saxon.expr.StaticContext;
6 import net.sf.saxon.om.NamespaceResolver;
7 import net.sf.saxon.om.NodeInfo;
8 import net.sf.saxon.om.SequenceIterator;
9 import net.sf.saxon.om.SingletonIterator;
10 import net.sf.saxon.style.StandardNames;
11 import net.sf.saxon.value.UntypedAtomicValue;
12 import net.sf.saxon.value.Value;
13 import net.sf.saxon.value.Whitespace;
14
15 /**
16  * This class has a singleton instance which represents the XML Schema built-in type xs:anySimpleType
17  */

18
19 public final class AnySimpleType implements SimpleType {
20
21     private static AnySimpleType theInstance = new AnySimpleType();
22
23     /**
24      * Private constructor
25      */

26     private AnySimpleType() {
27     }
28
29     /**
30      * Get the most specific possible atomic type that all items in this SimpleType belong to
31      * @return the lowest common supertype of all member types
32      */

33
34     public AtomicType getCommonAtomicType() {
35         return Type.ANY_ATOMIC_TYPE;
36     }
37
38     /**
39      * Get the singular instance of this class
40      * @return the singular object representing xs:anyType
41      */

42
43     public static AnySimpleType getInstance() {
44         return theInstance;
45     }
46
47     /**
48      * Get the validation status - always valid
49      */

50     public int getValidationStatus() {
51         return VALIDATED;
52     }
53
54     /**
55      * Get the base type
56      * @return AnyType
57      */

58
59     public SchemaType getBaseType() {
60         return AnyType.getInstance();
61     }
62
63     /**
64      * Returns the base type that this type inherits from. This method can be used to get the
65      * base type of a type that is known to be valid.
66      * @return the base type.
67      */

68
69     public SchemaType getKnownBaseType() throws IllegalStateException JavaDoc {
70         return getBaseType();
71     }
72
73     /**
74      * Test whether this SchemaType is a complex type
75      *
76      * @return true if this SchemaType is a complex type
77      */

78
79     public boolean isComplexType() {
80         return false;
81     }
82
83     /**
84      * Test whether this SchemaType is a simple type
85      * @return true if this SchemaType is a simple type
86      */

87
88     public boolean isSimpleType() {
89         return true;
90     }
91
92     /**
93      * Get the fingerprint of the name of this type
94      * @return the fingerprint.
95      */

96
97     public int getFingerprint() {
98         return StandardNames.XS_ANY_SIMPLE_TYPE;
99     }
100
101     /**
102      * Get the namecode of the name of this type. This includes the prefix from the original
103      * type declaration: in the case of built-in types, there may be a conventional prefix
104      * or there may be no prefix.
105      */

106
107     public int getNameCode() {
108         return StandardNames.XS_ANY_SIMPLE_TYPE;
109     }
110
111     /**
112      * Get a description of this type for use in diagnostics
113      * @return the string "xs:anyType"
114      */

115
116     public String JavaDoc getDescription() {
117         return "xs:anySimpleType";
118     }
119
120     /**
121      * Get the display name of the type: that is, a lexical QName with an arbitrary prefix
122      *
123      * @return a lexical QName identifying the type
124      */

125
126     public String JavaDoc getDisplayName() {
127         return "xs:anySimpleType";
128     }
129
130     /**
131      * Test whether this is the same type as another type. They are considered to be the same type
132      * if they are derived from the same type definition in the original XML representation (which
133      * can happen when there are multiple includes of the same file)
134      */

135
136     public boolean isSameType(SchemaType other) {
137         return (other instanceof AnySimpleType);
138     }
139
140     /**
141      * Get the typed value of a node that is annotated with this schema type. This shouldn't happen: nodes
142      * are never annotated as xs:anySimpleType; but if it does happen, we treat it as if it were
143      * untypedAtomic.
144      * @param node the node whose typed value is required
145      * @return an iterator returning a single untyped atomic value, equivalent to the string value of the node.
146      */

147
148     public SequenceIterator getTypedValue(NodeInfo node) {
149         return SingletonIterator.makeIterator(new UntypedAtomicValue(node.getStringValueCS()));
150     }
151
152     /**
153      * 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
154      * {@link #getTypedValue}. However, this method is often more convenient and may be
155      * more efficient, especially in the common case where the value is expected to be a singleton.
156      *
157      * @param node the node whose typed value is required
158      * @return the typed value.
159      * @since 8.5
160      */

161
162     public Value atomize(NodeInfo node) {
163         return new UntypedAtomicValue(node.getStringValueCS());
164     }
165
166      /**
167      * Check that this type is validly derived from a given type
168      *
169      * @param type the type from which this type is derived
170      * @param block the derivations that are blocked by the relevant element declaration
171      * @throws SchemaException
172      * if the derivation is not allowed
173      */

174
175     public void isTypeDerivationOK(SchemaType type, int block) throws SchemaException {
176         throw new SchemaException("Cannot derive xs:anySimpleType from another type");
177     }
178
179     /**
180      * Test whether this Simple Type is an atomic type
181      * @return false, this is not (necessarily) an atomic type
182      */

183
184     public boolean isAtomicType() {
185         return false;
186     }
187
188
189     /**
190      * Determine whether this is a list type
191      * @return false (it isn't a list type)
192      */

193     public boolean isListType() {
194         return false;
195     }
196
197     /**
198      * Determin whether this is a union type
199      * @return false (it isn't a union type)
200      */

201     public boolean isUnionType() {
202         return false;
203     }
204
205     /**
206      * Get the built-in ancestor of this type in the type hierarchy
207      * @return this type itself
208      */

209     public SchemaType getBuiltInBaseType() {
210         return this;
211     }
212
213     /**
214      * Get the typed value corresponding to a given string value, assuming it is
215      * valid against this type
216      *
217      * @param value the string value
218      * @param resolver a namespace resolver used to resolve any namespace prefixes appearing
219      * in the content of values. Can supply null, in which case any namespace-sensitive content
220      * will be rejected.
221      * @param conversion
222      * @return an iterator over the atomic sequence comprising the typed value. The objects
223      * returned by this SequenceIterator will all be of type {@link net.sf.saxon.value.AtomicValue}
224      */

225
226     public SequenceIterator getTypedValue(CharSequence JavaDoc value, NamespaceResolver resolver, ConversionContext conversion) {
227         return new UntypedAtomicValue(value).iterate(null);
228     }
229
230     /**
231      * Check whether a given input string is valid according to this SimpleType
232      * @param value the input string to be checked
233      * @param nsResolver a namespace resolver used to resolve namespace prefixes if the type
234      * is namespace sensitive. The value supplied may be null; in this case any namespace-sensitive
235      * content will throw an UnsupportedOperationException.
236      * @param conversion
237      * @return null if validation succeeds (which it always does for this implementation)
238      * @throws UnsupportedOperationException if the type is namespace-sensitive and no namespace
239      * resolver is supplied
240      */

241     public ValidationException validateContent(CharSequence JavaDoc value, NamespaceResolver nsResolver, ConversionContext conversion) {
242         return null;
243     }
244
245     /**
246      * Test whether this type represents namespace-sensitive content
247      * @return false
248      */

249     public boolean isNamespaceSensitive() {
250         return false;
251     }
252
253     /**
254      * Returns the value of the 'block' attribute for this type, as a bit-signnificant
255      * integer with fields such as {@link SchemaType#DERIVATION_LIST} and {@link SchemaType#DERIVATION_EXTENSION}
256      *
257      * @return the value of the 'block' attribute for this type
258      */

259
260     public int getBlock() {
261         return 0;
262     }
263
264     /**
265      * Gets the integer code of the derivation method used to derive this type from its
266      * parent. Returns zero for primitive types.
267      *
268      * @return a numeric code representing the derivation method, for example {@link SchemaType#DERIVATION_RESTRICTION}
269      */

270
271     public int getDerivationMethod() {
272         return SchemaType.DERIVATION_RESTRICTION;
273     }
274
275     /**
276      * Determines whether derivation (of a particular kind)
277      * from this type is allowed, based on the "final" property
278      *
279      * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
280      * @return true if this kind of derivation is allowed
281      */

282
283     public boolean allowsDerivation(int derivation) {
284         return true;
285     }
286
287     /**
288      * Determine how values of this simple type are whitespace-normalized.
289      *
290      * @return one of {@link net.sf.saxon.value.Whitespace#PRESERVE}, {@link net.sf.saxon.value.Whitespace#COLLAPSE},
291      * {@link net.sf.saxon.value.Whitespace#REPLACE}.
292      */

293
294     public int getWhitespaceAction() {
295         return Whitespace.COLLAPSE;
296     }
297
298     /**
299      * Analyze an expression to see whether the expression is capable of delivering a value of this
300      * type.
301      *
302      * @param expression the expression that delivers the content
303      * @param kind the node kind whose content is being delivered: {@link net.sf.saxon.type.Type#ELEMENT},
304      * {@link net.sf.saxon.type.Type#ATTRIBUTE}, or {@link net.sf.saxon.type.Type#DOCUMENT}
305      * @param env
306      */

307
308     public void analyzeContentExpression(Expression expression, int kind, StaticContext env) {
309         return;
310     }
311 }
312
313
314 //
315
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
316
// you may not use this file except in compliance with the License. You may obtain a copy of the
317
// License at http://www.mozilla.org/MPL/
318
//
319
// Software distributed under the License is distributed on an "AS IS" basis,
320
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
321
// See the License for the specific language governing rights and limitations under the License.
322
//
323
// The Original Code is: all this file.
324
//
325
// The Initial Developer of the Original Code is Saxonica Limited
326
//
327
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
328
//
329
// Contributor(s): none
330
//
Popular Tags