KickJava   Java API By Example, From Geeks To Geeks.

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


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.om.NodeInfo;
6 import net.sf.saxon.om.SequenceIterator;
7 import net.sf.saxon.trans.XPathException;
8 import net.sf.saxon.value.Value;
9
10 /**
11  * SchemaType is an interface implemented by all schema types: simple and complex types, built-in and
12  * user-defined types.
13  *
14  * <p>There is a hierarchy of interfaces that extend SchemaType, representing the top levels of the schema
15  * type system: SimpleType and ComplexType, with SimpleType further subdivided into List, Union, and Atomic
16  * types.</p>
17  *
18  * <p>The implementations of these interfaces are organized into a different hierarchy: on the one side,
19  * built-in types such as AnyType, AnySimpleType, and the built-in atomic types and list types; on the other
20  * side, user-defined types defined in a schema.</p>
21  */

22
23 public interface SchemaType extends SchemaComponent {
24
25     // DerivationMethods. These constants are copied from org.w3.dom.TypeInfo. They are redefined here to avoid
26
// creating a dependency on the TypeInfo class, which is only available when JAXP 1.3 is available.
27

28     /**
29      * If the document's schema is an XML Schema [<a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
30      * , this constant represents the derivation by <a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#key-typeRestriction'>
31      * restriction</a> if complex types are involved, or a <a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-restriction'>
32      * restriction</a> if simple types are involved.
33      * <br> The reference type definition is derived by restriction from the
34      * other type definition if the other type definition is the same as the
35      * reference type definition, or if the other type definition can be
36      * reached recursively following the {base type definition} property
37      * from the reference type definition, and all the <em>derivation methods</em> involved are restriction.
38      */

39     public static final int DERIVATION_RESTRICTION = 0x00000001;
40     /**
41      * If the document's schema is an XML Schema [<a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
42      * , this constant represents the derivation by <a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#key-typeExtension'>
43      * extension</a>.
44      * <br> The reference type definition is derived by extension from the
45      * other type definition if the other type definition can be reached
46      * recursively following the {base type definition} property from the
47      * reference type definition, and at least one of the <em>derivation methods</em> involved is an extension.
48      */

49     public static final int DERIVATION_EXTENSION = 0x00000002;
50     /**
51      * If the document's schema is an XML Schema [<a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
52      * , this constant represents the <a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-union'>
53      * union</a> if simple types are involved.
54      * <br> The reference type definition is derived by union from the other
55      * type definition if there exists two type definitions T1 and T2 such
56      * as the reference type definition is derived from T1 by
57      * <code>DERIVATION_RESTRICTION</code> or
58      * <code>DERIVATION_EXTENSION</code>, T2 is derived from the other type
59      * definition by <code>DERIVATION_RESTRICTION</code>, T1 has {variety} <em>union</em>, and one of the {member type definitions} is T2. Note that T1 could be
60      * the same as the reference type definition, and T2 could be the same
61      * as the other type definition.
62      */

63     public static final int DERIVATION_UNION = 0x00000004;
64     /**
65      * If the document's schema is an XML Schema [<a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
66      * , this constant represents the <a HREF='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-list'>list</a>.
67      * <br> The reference type definition is derived by list from the other
68      * type definition if there exists two type definitions T1 and T2 such
69      * as the reference type definition is derived from T1 by
70      * <code>DERIVATION_RESTRICTION</code> or
71      * <code>DERIVATION_EXTENSION</code>, T2 is derived from the other type
72      * definition by <code>DERIVATION_RESTRICTION</code>, T1 has {variety} <em>list</em>, and T2 is the {item type definition}. Note that T1 could be the same as
73      * the reference type definition, and T2 could be the same as the other
74      * type definition.
75      */

76     public static final int DERIVATION_LIST = 0x00000008;
77
78     /**
79      * Derivation by substitution.
80      * This constant, unlike the others, is NOT defined in the DOM level 3 TypeInfo interface.
81      */

82
83     public static final int DERIVE_BY_SUBSTITUTION = 16;
84
85     /**
86      * Get the namecode of the name of this type. This includes the prefix from the original
87      * type declaration: in the case of built-in types, there may be a conventional prefix
88      * or there may be no prefix.
89      */

90
91     int getNameCode();
92
93     /**
94      * Get the fingerprint of the name of this type
95      * @return the fingerprint. Returns an invented fingerprint for an anonymous type.
96      */

97
98     int getFingerprint();
99
100     /**
101      * Get the display name of the type: that is, a lexical QName with an arbitrary prefix
102      * @return a lexical QName identifying the type
103      */

104
105     String JavaDoc getDisplayName();
106
107     /**
108      * Test whether this SchemaType is a complex type
109      * @return true if this SchemaType is a complex type
110      */

111
112     boolean isComplexType();
113
114     /**
115      * Test whether this SchemaType is a simple type
116      * @return true if this SchemaType is a simple type
117      */

118
119     boolean isSimpleType();
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      * @return the value of the 'block' attribute for this type
125      */

126
127     int getBlock();
128
129     /**
130      * Returns the base type that this type inherits from. This method can be used to get the
131      * base type of a type that is known to be valid.
132      * If this type is a Simpletype that is a built in primitive type then null is returned.
133      * @return the base type.
134      * @throws IllegalStateException if this type is not valid.
135     */

136
137     SchemaType getBaseType() throws UnresolvedReferenceException;
138
139     /**
140      * Gets the integer code of the derivation method used to derive this type from its
141      * parent. Returns zero for primitive types.
142      * @return a numeric code representing the derivation method, for example {@link SchemaType#DERIVATION_RESTRICTION}
143      */

144
145     int getDerivationMethod();
146
147     /**
148      * Determines whether derivation (of a particular kind)
149      * from this type is allowed, based on the "final" property
150      * @param derivation the kind of derivation, for example {@link SchemaType#DERIVATION_LIST}
151      * @return true if this kind of derivation is allowed
152      */

153
154     boolean allowsDerivation(int derivation);
155
156     /**
157      * Analyze an expression to see whether the expression is capable of delivering a value of this
158      * type.
159      * @param expression the expression that delivers the content
160      * @param kind the node kind whose content is being delivered: {@link Type#ELEMENT},
161      * {@link Type#ATTRIBUTE}, or {@link Type#DOCUMENT}
162      * @param env The static evaluation context for the query or stylesheet
163      * @throws XPathException if the expression will never deliver a value of the correct type
164      */

165
166     void analyzeContentExpression(Expression expression, int kind, StaticContext env) throws XPathException;
167
168     /**
169      * Get the typed value of a node that is annotated with this schema type. The results of this method
170      * are consistent with the {@link #atomize} method, but this version returns a SequenceIterator which may
171      * be more efficient when handling long lists.
172      * @param node the node whose typed value is required
173      * @return a SequenceIterator over the atomic values making up the typed value of the specified
174      * node. The objects returned by this iterator are of type {@link net.sf.saxon.value.AtomicValue}
175      */

176
177     SequenceIterator getTypedValue(NodeInfo node) throws XPathException;
178
179     /**
180      * 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
181      * {@link #getTypedValue}. However, this method is often more convenient and may be
182      * more efficient, especially in the common case where the value is expected to be a singleton.
183      * @param node the node whose typed value is required
184      * @return the typed value.
185      * @since 8.5
186      */

187
188     Value atomize(NodeInfo node) throws XPathException;
189
190     /**
191      * Test whether this is the same type as another type. They are considered to be the same type
192      * if they are derived from the same type definition in the original XML representation (which
193      * can happen when there are multiple includes of the same file)
194      */

195
196     boolean isSameType(SchemaType other);
197
198     /**
199      * Get a description of this type for use in error messages. This is the same as the display name
200      * in the case of named types; for anonymous types it identifies the type by its position in a source
201      * schema document.
202      * @return text identifing the type, for use in a phrase such as "the type XXXX".
203      */

204
205     String JavaDoc getDescription();
206
207     /**
208      * Check that this type is validly derived from a given type, following the rules for the Schema Component
209      * Constraint "Is Type Derivation OK (Simple)" (3.14.6) or "Is Type Derivation OK (Complex)" (3.4.6) as
210      * appropriate.
211      * @param base the base type; the algorithm tests whether derivation from this type is permitted
212      * @param block the derivations that are blocked by the relevant element declaration
213      * @throws SchemaException if the derivation is not allowed
214      */

215
216     public void isTypeDerivationOK(SchemaType base, int block) throws SchemaException, ValidationException;
217
218 }
219
220 //
221
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
222
// you may not use this file except in compliance with the License. You may obtain a copy of the
223
// License at http://www.mozilla.org/MPL/
224
//
225
// Software distributed under the License is distributed on an "AS IS" basis,
226
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
227
// See the License for the specific language governing rights and limitations under the License.
228
//
229
// The Original Code is: all this file.
230
//
231
// The Initial Developer of the Original Code is Michael H. Kay
232
//
233
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
234
//
235
// Contributor(s): none.
236
//
237
Popular Tags