001: package net.sf.saxon.type;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.expr.StaticContext;
005: import net.sf.saxon.expr.StaticProperty;
006: import net.sf.saxon.om.NodeInfo;
007: import net.sf.saxon.om.SequenceIterator;
008: import net.sf.saxon.om.SingletonIterator;
009: import net.sf.saxon.style.StandardNames;
010: import net.sf.saxon.value.UntypedAtomicValue;
011: import net.sf.saxon.value.Value;
012:
013: import java.io.Serializable;
014:
015: /**
016: * This class has a singleton instance which represents the XML Schema built-in type xs:anyType,
017: * also known as the urtype.
018: */
019:
020: public final class AnyType implements ComplexType, Serializable {
021:
022: private static AnyType theInstance = new AnyType();
023:
024: /**
025: * Private constructor
026: */
027: private AnyType() {
028: super ();
029: }
030:
031: /**
032: * Get the singular instance of this class
033: * @return the singular object representing xs:anyType
034: */
035:
036: public static AnyType getInstance() {
037: return theInstance;
038: }
039:
040: /**
041: * Get the validation status - always valid
042: */
043: public int getValidationStatus() {
044: return VALIDATED;
045: }
046:
047: /**
048: * Get the base type
049: * @return null (this is the root of the type hierarchy)
050: */
051:
052: public SchemaType getBaseType() {
053: return null;
054: }
055:
056: /**
057: * Returns the base type that this type inherits from. This method can be used to get the
058: * base type of a type that is known to be valid.
059: * If this type is a Simpletype that is a built in primitive type then null is returned.
060: *
061: * @return the base type.
062: * @throws IllegalStateException if this type is not valid.
063: */
064:
065: public SchemaType getKnownBaseType() throws IllegalStateException {
066: return null;
067: }
068:
069: /**
070: * Gets the integer code of the derivation method used to derive this type from its
071: * parent. Returns zero for primitive types.
072: *
073: * @return a numeric code representing the derivation method, for example
074: * {@link SchemaType#DERIVATION_RESTRICTION}
075: */
076:
077: public int getDerivationMethod() {
078: return 0;
079: }
080:
081: /**
082: * Determines whether derivation (of a particular kind)
083: * from this type is allowed, based on the "final" property
084: *
085: * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
086: * @return true if this kind of derivation is allowed
087: */
088:
089: public boolean allowsDerivation(int derivation) {
090: return true;
091: }
092:
093: /**
094: * Test whether this ComplexType has been marked as abstract.
095: * @return false: this class is not abstract.
096: */
097:
098: public boolean isAbstract() {
099: 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 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 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,
264: int kind, StaticContext env) {
265: return;
266: }
267:
268: /**
269: * Get the typed value of a node that is annotated with this schema type
270: * @param node the node whose typed value is required
271: * @return an iterator returning a single untyped atomic value, equivalent to the string value of the node. This
272: * follows the standard rules for elements with mixed content.
273: */
274:
275: public SequenceIterator getTypedValue(NodeInfo node) {
276: return SingletonIterator.makeIterator(new UntypedAtomicValue(
277: node.getStringValue()));
278: }
279:
280: /**
281: * 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
282: * {@link #getTypedValue}. However, this method is often more convenient and may be
283: * more efficient, especially in the common case where the value is expected to be a singleton.
284: *
285: * @param node the node whose typed value is required
286: * @return the typed value.
287: * @since 8.5
288: */
289:
290: public Value atomize(NodeInfo node) {
291: return new UntypedAtomicValue(node.getStringValue());
292: }
293:
294: /**
295: * Test whether this complex type subsumes another complex type. The algorithm
296: * used is as published by Thompson and Tobin, XML Europe 2003.
297: * @param sub the other type (the type that is derived by restriction, validly or otherwise)
298: * @return null indicating that this type does indeed subsume the other; or a string indicating
299: * why it doesn't.
300: */
301:
302: public String subsumes(ComplexType sub) {
303: return null;
304: }
305:
306: /**
307: * Check that this type is validly derived from a given type
308: *
309: * @param type the type from which this type is derived
310: * @param block the derivations that are blocked by the relevant element declaration
311: * @throws SchemaException
312: * if the derivation is not allowed
313: */
314:
315: public void isTypeDerivationOK(SchemaType type, int block)
316: throws SchemaException {
317: throw new SchemaException(
318: "Cannot derive xs:anyType from another type");
319: }
320:
321: /**
322: * Find an element particle within this complex type definition having a given element name
323: * (identified by fingerprint), and return the schema type associated with that element particle.
324: * If there is no such particle, return null. If the fingerprint matches an element wildcard,
325: * return the type of the global element declaration with the given name if one exists, or AnyType
326: * if none exists and lax validation is permitted by the wildcard.
327: *
328: * @param fingerprint Identifies the name of the child element within this content model
329: */
330:
331: public SchemaType getElementParticleType(int fingerprint) {
332: return this ;
333: }
334:
335: /**
336: * Find an element particle within this complex type definition having a given element name
337: * (identified by fingerprint), and return the cardinality associated with that element particle,
338: * that is, the number of times the element can occur within this complex type. The value is one of
339: * {@link net.sf.saxon.expr.StaticProperty#EXACTLY_ONE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_ONE},
340: * {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_MORE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ONE_OR_MORE},
341: * If there is no such particle, return zero.
342: *
343: * @param fingerprint Identifies the name of the child element within this content model
344: */
345:
346: public int getElementParticleCardinality(int fingerprint) {
347: return StaticProperty.ALLOWS_ZERO_OR_MORE;
348: }
349:
350: /**
351: * Find an attribute use within this complex type definition having a given attribute name
352: * (identified by fingerprint), and return the schema type associated with that attribute.
353: * If there is no such attribute use, return null. If the fingerprint matches an attribute wildcard,
354: * return the type of the global attribute declaration with the given name if one exists, or AnySimpleType
355: * if none exists and lax validation is permitted by the wildcard.
356: *
357: * @param fingerprint Identifies the name of the child element within this content model
358: */
359:
360: public SchemaType getAttributeUseType(int fingerprint) {
361: return AnySimpleType.getInstance();
362: }
363: }
364:
365: //
366: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
367: // you may not use this file except in compliance with the License. You may obtain a copy of the
368: // License at http://www.mozilla.org/MPL/
369: //
370: // Software distributed under the License is distributed on an "AS IS" basis,
371: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
372: // See the License for the specific language governing rights and limitations under the License.
373: //
374: // The Original Code is: all this file.
375: //
376: // The Initial Developer of the Original Code is Saxonica Limited
377: //
378: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
379: //
380: // Contributor(s): none
381: //
|