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 complex type xdt:untyped,
017: * used for elements that have not been validated.
018: */
019:
020: public final class Untyped implements ComplexType, Serializable {
021:
022: /**
023: * Get the validation status - always valid
024: */
025: public int getValidationStatus() {
026: return VALIDATED;
027: }
028:
029: /**
030: * Returns the value of the 'block' attribute for this type, as a bit-signnificant
031: * integer with fields such as {@link SchemaType#DERIVATION_LIST} and {@link SchemaType#DERIVATION_EXTENSION}
032: *
033: * @return the value of the 'block' attribute for this type
034: */
035:
036: public int getBlock() {
037: return 0;
038: }
039:
040: /**
041: * Gets the integer code of the derivation method used to derive this type from its
042: * parent. Returns zero for primitive types.
043: *
044: * @return a numeric code representing the derivation method, for example {@link SchemaType#DERIVATION_RESTRICTION}
045: */
046:
047: public int getDerivationMethod() {
048: return 0;
049: }
050:
051: /**
052: * Determines whether derivation (of a particular kind)
053: * from this type is allowed, based on the "final" property
054: *
055: * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
056: * @return true if this kind of derivation is allowed
057: */
058:
059: public boolean allowsDerivation(int derivation) {
060: return false;
061: }
062:
063: /**
064: * Check that this type is validly derived from a given type
065: *
066: * @param type the type from which this type is derived
067: * @param block the derivations that are blocked by the relevant element declaration
068: */
069:
070: public void isTypeDerivationOK(SchemaType type, int block) {
071:
072: }
073:
074: private static Untyped theInstance = new Untyped();
075:
076: /**
077: * Private constructor
078: */
079: private Untyped() {
080: }
081:
082: /**
083: * Get the fingerprint of the name of this type
084: *
085: * @return the fingerprint. Returns an invented fingerprint for an anonymous type.
086: */
087:
088: public int getFingerprint() {
089: return StandardNames.XDT_UNTYPED;
090: }
091:
092: /**
093: * Get the namecode of the name of this type. This includes the prefix from the original
094: * type declaration: in the case of built-in types, there may be a conventional prefix
095: * or there may be no prefix.
096: */
097:
098: public int getNameCode() {
099: return StandardNames.XDT_UNTYPED;
100: }
101:
102: /**
103: * Get the display name of the type: that is, a lexical QName with an arbitrary prefix
104: *
105: * @return a lexical QName identifying the type
106: */
107:
108: public String getDisplayName() {
109: return "xdt:untyped";
110: }
111:
112: /**
113: * Test whether this SchemaType is a complex type
114: *
115: * @return true if this SchemaType is a complex type
116: */
117:
118: public boolean isComplexType() {
119: return true;
120: }
121:
122: /**
123: * Returns the base type that this type inherits from. This method can be used to get the
124: * base type of a type that is known to be valid.
125: * If this type is a Simpletype that is a built in primitive type then null is returned.
126: *
127: * @return the base type.
128: * @throws IllegalStateException if this type is not valid.
129: */
130:
131: public SchemaType getKnownBaseType() throws IllegalStateException {
132: return AnyType.getInstance();
133: }
134:
135: /**
136: * Test whether this is the same type as another type. They are considered to be the same type
137: * if they are derived from the same type definition in the original XML representation (which
138: * can happen when there are multiple includes of the same file)
139: */
140:
141: public boolean isSameType(SchemaType other) {
142: return (other instanceof Untyped);
143: }
144:
145: /**
146: * Returns the base type that this type inherits from.
147: * If this type is a Simpletype that is a built in primitive type then null is returned.
148: *
149: * @return the base type.
150: */
151:
152: public SchemaType getBaseType() {
153: return AnyType.getInstance();
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 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,
276: int kind, StaticContext env) {
277: return;
278: }
279:
280: /**
281: * Get the typed value of a node that is annotated with this schema type
282: * @param node the node whose typed value is required
283: * @return an iterator returning a single untyped atomic value, equivalent to the string value of the node. This
284: * follows the standard rules for elements with mixed content.
285: */
286:
287: public SequenceIterator getTypedValue(NodeInfo node) {
288: return SingletonIterator.makeIterator(new UntypedAtomicValue(
289: node.getStringValueCS()));
290: }
291:
292: /**
293: * 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
294: * {@link #getTypedValue}. However, this method is often more convenient and may be
295: * more efficient, especially in the common case where the value is expected to be a singleton.
296: *
297: * @param node the node whose typed value is required
298: * @return the typed value.
299: * @since 8.5
300: */
301:
302: public Value atomize(NodeInfo node) {
303: return new UntypedAtomicValue(node.getStringValue());
304: }
305:
306: /**
307: * Test whether this complex type subsumes another complex type. The algorithm
308: * used is as published by Thompson and Tobin, XML Europe 2003.
309: * @param sub the other type (the type that is derived by restriction, validly or otherwise)
310: * @return null indicating that this type does indeed subsume the other; or a string indicating
311: * why it doesn't.
312: */
313:
314: public String subsumes(ComplexType sub) {
315: return null;
316: }
317:
318: /**
319: * Find an element particle within this complex type definition having a given element name
320: * (identified by fingerprint), and return the schema type associated with that element particle.
321: * If there is no such particle, return null. If the fingerprint matches an element wildcard,
322: * return the type of the global element declaration with the given name if one exists, or AnyType
323: * if none exists and lax validation is permitted by the wildcard.
324: *
325: * @param fingerprint Identifies the name of the child element within this content model
326: */
327:
328: public SchemaType getElementParticleType(int fingerprint) {
329: return this ;
330: }
331:
332: /**
333: * Find an element particle within this complex type definition having a given element name
334: * (identified by fingerprint), and return the cardinality associated with that element particle,
335: * that is, the number of times the element can occur within this complex type. The value is one of
336: * {@link net.sf.saxon.expr.StaticProperty#EXACTLY_ONE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_ONE},
337: * {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_MORE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ONE_OR_MORE},
338: * If there is no such particle, return zero.
339: *
340: * @param fingerprint Identifies the name of the child element within this content model
341: */
342:
343: public int getElementParticleCardinality(int fingerprint) {
344: return StaticProperty.ALLOWS_ZERO_OR_MORE;
345: }
346:
347: /**
348: * Find an attribute use within this complex type definition having a given attribute name
349: * (identified by fingerprint), and return the schema type associated with that attribute.
350: * If there is no such attribute use, return null. If the fingerprint matches an attribute wildcard,
351: * return the type of the global attribute declaration with the given name if one exists, or AnySimpleType
352: * if none exists and lax validation is permitted by the wildcard.
353: *
354: * @param fingerprint Identifies the name of the child element within this content model
355: */
356:
357: public SchemaType getAttributeUseType(int fingerprint) {
358: return BuiltInSchemaFactory
359: .getSchemaType(StandardNames.XDT_UNTYPED_ATOMIC);
360: }
361: }
362:
363: //
364: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
365: // you may not use this file except in compliance with the License. You may obtain a copy of the
366: // License at http://www.mozilla.org/MPL/
367: //
368: // Software distributed under the License is distributed on an "AS IS" basis,
369: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
370: // See the License for the specific language governing rights and limitations under the License.
371: //
372: // The Original Code is: all this file.
373: //
374: // The Initial Developer of the Original Code is Saxonica Limited
375: //
376: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
377: //
378: // Contributor(s): none
379: //
|