Debian Codegraph @

net/sf/saxon/type/ComplexType.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8
9 package net.sf.saxon.type;
10
11 import net.sf.saxon.om.StructuredQName;
12 import net.sf.saxon.z.IntHashSet;
13
14
15 /**
16 * A complex type as defined in XML Schema: either a user-defined complex type, or xs:anyType, or xs:untyped.
17 * In the non-schema-aware version of the Saxon product, the only complex type encountered is xs:untyped.
18 */
19
20 public interface ComplexType extends SchemaType {
21
22 int VARIETY_EMPTY = 0;
23 int VARIETY_SIMPLE = 1;
24 int VARIETY_ELEMENT_ONLY = 2;
25 int VARIETY_MIXED = 3;
26
27 int OPEN_CONTENT_ABSENT = 0;
28 int OPEN_CONTENT_NONE = 1;
29 int OPEN_CONTENT_INTERLEAVE = 2;
30 int OPEN_CONTENT_SUFFIX = 3;
31
32 /**
33 * Get the variety of this complex type. This will be one of the values
34 * {@link #VARIETY_EMPTY}, {@link #VARIETY_MIXED}, {@link #VARIETY_SIMPLE}, or
35 * {@link #VARIETY_ELEMENT_ONLY}
36 */
37
38 int getVariety();
39
40 /**
41 * Test whether this complex type has been marked as abstract. This corresponds to
42 * the {abstract} property in the schema component model.
43 *
44 * @return true if this complex type is abstract.
45 */
46
47 boolean isAbstract();
48
49 /**
50 * Test whether this complex type has complex content. This represents one aspect of the
51 * {content type} property in the schema component model.
52 *
53 * @return true if and only if this complex type has a complex content model, that is, if its variety is one
54 * of empty, mixed, or element-only.
55 */
56
57 boolean isComplexContent();
58
59 /**
60 * Test whether this complexType has simple content. This represents one aspect of the
61 * {content type} property in the schema component model.
62 *
63 * @return true if and only if this complex type has a simple content model, that is, if its variety is simple.
64 */
65
66 boolean isSimpleContent();
67
68 /**
69 * Test whether this complex type has "all" content, that is, a content model
70 * using an xs:all compositor
71 *
72 * @return true if the type has an "all" content model
73 */
74
75 boolean isAllContent();
76
77 /**
78 * Get the simple content type. This represents one aspect of the
79 * {content type} property in the schema component model.
80 *
81 * @return For a complex type with simple content, returns the simple type of the content.
82 * Otherwise, returns null.
83 */
84
85 /*@Nullable*/
86 SimpleType getSimpleContentType() throws MissingComponentException;
87
88 /**
89 * Test whether this complex type is derived by restriction. This corresponds to one
90 * aspect of the {derivation method} property in the schema component model.
91 *
92 * @return true if this complex type is derived by restriction
93 */
94
95 boolean isRestricted();
96
97 /**
98 * Test whether the content model of this complex type is empty. This represents one aspect of the
99 * {content type} property in the schema component model.
100 *
101 * @return true if the content model is defined as empty
102 */
103
104 boolean isEmptyContent();
105
106 /**
107 * Test whether the content model of this complex type allows empty content. This property applies only if
108 * this is a complex type with complex content.
109 *
110 * @return true if empty content is valid
111 */
112
113 boolean isEmptiable() throws SchemaException;
114
115 /**
116 * Test whether this complex type allows mixed content. This represents one aspect of the
117 * {content type} property in the schema component model. This property applies only if
118 * this is a complex type with complex content.
119 *
120 * @return true if mixed content is allowed
121 */
122
123 boolean isMixedContent();
124
125 /**
126 * Find an element particle within this complex type definition having a given element name
127 * (identified by elementName), and return the schema type associated with that element particle.
128 * If there is no such particle, return null. If the elementName matches an element wildcard,
129 * return the type of the global element declaration with the given name if one exists, or AnyType
130 * if none exists and lax validation is permitted by the wildcard.
131 *
132 * @param elementName Identifies the name of the child element within this content model
133 * @param considerExtensions True if types derived from this type by extension are to be included in the search
134 * @return the schema type associated with the child element particle with the given name.
135 * If there is no such particle, return null.
136 * @throws MissingComponentException if the schema is incomplete
137 */
138
139 /*@Nullable*/
140 SchemaType getElementParticleType(int elementName, boolean considerExtensions) throws MissingComponentException;
141
142 /**
143 * Find an element particle within this complex type definition having a given element name
144 * (identified by elementName), and return the cardinality associated with that element particle,
145 * that is, the number of times the element can occur within this complex type. The value is one of
146 * {@link net.sf.saxon.expr.StaticProperty#EXACTLY_ONE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_ONE},
147 * {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_MORE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ONE_OR_MORE},
148 * If there is no such particle, return {@link net.sf.saxon.expr.StaticProperty#EMPTY}.
149 *
150 * @param elementName Identifies the name of the child element within this content model
151 * @param considerExtensions True if types derived from this type by extension are to be included in the search
152 * @return the cardinality associated with the child element particle with the given name.
153 * If there is no such particle, return {@link net.sf.saxon.expr.StaticProperty#EMPTY}.
154 * @throws MissingComponentException if the schema is incomplete
155 */
156
157 int getElementParticleCardinality(int elementName, boolean considerExtensions) throws MissingComponentException;
158
159 /**
160 * Find an element particle within this complex type definition having a given element name
161 * (identified by elementName), and return the cardinality associated with that element particle,
162 * that is, the number of times the element can occur within this complex type. The value is one of
163 * {@link net.sf.saxon.expr.StaticProperty#EXACTLY_ONE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_ONE},
164 * {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ZERO_OR_MORE}, {@link net.sf.saxon.expr.StaticProperty#ALLOWS_ONE_OR_MORE},
165 * If there is no such particle, return {@link net.sf.saxon.expr.StaticProperty#EMPTY}.
166 *
167 * @param elementName Identifies the name of the child element within this content model
168 * @param considerExtensions True if types derived from this type by extension are to be included in the search
169 * @return the cardinality associated with the child element particle with the given name.
170 * If there is no such particle, return {@link net.sf.saxon.expr.StaticProperty#EMPTY}.
171 * @deprecated - retained for backwards compatibility
172 */
173
174 int getElementParticleCardinality(StructuredQName elementName, boolean considerExtensions)
175 throws SchemaException, ValidationException;
176
177 /**
178 * Find an attribute use within this complex type definition having a given attribute name
179 * (identified by fingerprint), and return the schema type associated with that attribute.
180 * If there is no such attribute use, return null. If the fingerprint matches an attribute wildcard,
181 * return the type of the global attribute declaration with the given name if one exists, or AnySimpleType
182 * if none exists and lax validation is permitted by the wildcard.
183 * <p>If there are types derived from this type by extension, search those too.</p>
184 *
185 * @param attributeName Identifies the name of the required attribute within this content model
186 * @return the schema type associated with the attribute use identified by the fingerprint.
187 * If there is no such attribute use, return null.
188 */
189
190 /*@Nullable*/
191 SimpleType getAttributeUseType(StructuredQName attributeName) throws SchemaException;
192
193 /**
194 * Find an attribute use within this complex type definition having a given attribute name
195 * (identified by fingerprint), and return the cardinality associated with that attribute,
196 * which will always be 0, 1, or 0-or-1.
197 * If there is no such attribute use, return 0. If the fingerprint matches an attribute wildcard,
198 * return 0-or-1.
199 * <p>If there are types derived from this type by extension, search those too.</p>
200 *
201 * @param attributeName Identifies the name of the required attribute within this content model
202 * @return the cardinality associated with the attribute use identified by the fingerprint.
203 */
204
205 int getAttributeUseCardinality(StructuredQName attributeName) throws SchemaException;
206
207 /**
208 * Return true if this type (or any known type derived from it by extension) allows the element
209 * to have one or more attributes.
210 *
211 * @return true if attributes (other than the standard xsi: attributes) are allowed. The value
212 * false indicates that only the standard attributes in the xsi namespace are permitted.
213 */
214
215 boolean allowsAttributes() throws MissingComponentException;
216
217 /**
218 * Get a list of all the names of elements that can appear as children of an element having this
219 * complex type, as integer fingerprints. If the list is unbounded (because of wildcards or the use
220 * of xs:anyType), return null.
221 * @param children a set, initially empty, which on return will hold the names of all permitted
222 * child elements; if the result contains the value -1, this indicates that it
223 * is not possible to enumerate all the children, typically because of wildcards.
224 * In this case the other contents of the set should be ignored
225 * @param ignoreWildcards true if wildcards should be ignored
226 */
227
228 void gatherAllPermittedChildren(IntHashSet children, boolean ignoreWildcards) throws SchemaException;
229
230 /**
231 * Get a list of all the names of elements that can appear as descendants of an element having this
232 * complex type, as integer fingerprints. If the list is unbounded (because of wildcards or the use
233 * of xs:anyType), include a -1 in the result.
234 *
235 * @param descendants a set, initially empty, which on return will hold the names of all permitted
236 * descendant elements; if the result contains the value -1, this indicates that
237 * it is not possible to enumerate all the descendants, typically because of
238 * wildcards. In this case the other contents of the set should
239 * be ignored.
240 */
241
242 void gatherAllPermittedDescendants(IntHashSet descendants) throws SchemaException;
243
244 /**
245 * Assuming an element is a permitted descendant in the content model of this type, determine
246 * the type of the element when it appears as a descendant. If it appears with more than one type,
247 * return xs:anyType.
248 *
249 * @param fingerprint the name of the required descendant element
250 * @return the type of the descendant element; null if the element cannot appear as a descendant;
251 * anyType if it can appear with several different types
252 */
253
254 /*@Nullable*/
255 SchemaType getDescendantElementType(int fingerprint) throws SchemaException;
256
257 /**
258 * Assuming an element is a permitted descendant in the content model of this type, determine
259 * the cardinality of the element when it appears as a descendant.
260 *
261 * @param elementFingerprint the name of the required descendant element
262 * @return the cardinality of the descendant element within this complex type
263 */
264
265 int getDescendantElementCardinality(int elementFingerprint) throws SchemaException;
266
267 /**
268 * Ask whether this type (or any known type derived from it by extension) allows the element
269 * to have children that match a wildcard
270 *
271 * @return true if the content model of this type, or its extensions, contains an element wildcard
272 */
273
274 boolean containsElementWildcard() throws MissingComponentException;
275
276 /**
277 * Ask whether there are any assertions defined on this complex type
278 *
279 * @return true if there are any assertions
280 */
281
282 boolean hasAssertions();
283 }
284