1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: XSSimpleTypeDefinition.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XSSIMPLETYPEDEFINITION_HPP) |
---|
23 | #define XSSIMPLETYPEDEFINITION_HPP |
---|
24 | |
---|
25 | #include <xercesc/framework/psvi/XSTypeDefinition.hpp> |
---|
26 | |
---|
27 | XERCES_CPP_NAMESPACE_BEGIN |
---|
28 | |
---|
29 | /** |
---|
30 | * This class represents a simpleType definition |
---|
31 | * schema component. |
---|
32 | * This is *always* owned by the validator /parser object from which |
---|
33 | * it is obtained. |
---|
34 | * |
---|
35 | */ |
---|
36 | |
---|
37 | // forward declarations |
---|
38 | class XSAnnotation; |
---|
39 | class XSFacet; |
---|
40 | class XSMultiValueFacet; |
---|
41 | class DatatypeValidator; |
---|
42 | |
---|
43 | class XMLPARSER_EXPORT XSSimpleTypeDefinition : public XSTypeDefinition |
---|
44 | { |
---|
45 | public: |
---|
46 | |
---|
47 | // Variety definitions |
---|
48 | enum VARIETY { |
---|
49 | /** |
---|
50 | * The variety is absent for the anySimpleType definition. |
---|
51 | */ |
---|
52 | VARIETY_ABSENT = 0, |
---|
53 | /** |
---|
54 | * <code>Atomic</code> type. |
---|
55 | */ |
---|
56 | VARIETY_ATOMIC = 1, |
---|
57 | /** |
---|
58 | * <code>List</code> type. |
---|
59 | */ |
---|
60 | VARIETY_LIST = 2, |
---|
61 | /** |
---|
62 | * <code>Union</code> type. |
---|
63 | */ |
---|
64 | VARIETY_UNION = 3 |
---|
65 | }; |
---|
66 | |
---|
67 | // Facets |
---|
68 | enum FACET { |
---|
69 | /** |
---|
70 | * No facets defined. |
---|
71 | */ |
---|
72 | FACET_NONE = 0, |
---|
73 | /** |
---|
74 | * 4.3.1 Length |
---|
75 | */ |
---|
76 | FACET_LENGTH = 1, |
---|
77 | /** |
---|
78 | * 4.3.2 minLength. |
---|
79 | */ |
---|
80 | FACET_MINLENGTH = 2, |
---|
81 | /** |
---|
82 | * 4.3.3 maxLength. |
---|
83 | */ |
---|
84 | FACET_MAXLENGTH = 4, |
---|
85 | /** |
---|
86 | * 4.3.4 pattern. |
---|
87 | */ |
---|
88 | FACET_PATTERN = 8, |
---|
89 | /** |
---|
90 | * 4.3.5 whitespace. |
---|
91 | */ |
---|
92 | FACET_WHITESPACE = 16, |
---|
93 | /** |
---|
94 | * 4.3.7 maxInclusive. |
---|
95 | */ |
---|
96 | FACET_MAXINCLUSIVE = 32, |
---|
97 | /** |
---|
98 | * 4.3.9 maxExclusive. |
---|
99 | */ |
---|
100 | FACET_MAXEXCLUSIVE = 64, |
---|
101 | /** |
---|
102 | * 4.3.9 minExclusive. |
---|
103 | */ |
---|
104 | FACET_MINEXCLUSIVE = 128, |
---|
105 | /** |
---|
106 | * 4.3.10 minInclusive. |
---|
107 | */ |
---|
108 | FACET_MININCLUSIVE = 256, |
---|
109 | /** |
---|
110 | * 4.3.11 totalDigits . |
---|
111 | */ |
---|
112 | FACET_TOTALDIGITS = 512, |
---|
113 | /** |
---|
114 | * 4.3.12 fractionDigits. |
---|
115 | */ |
---|
116 | FACET_FRACTIONDIGITS = 1024, |
---|
117 | /** |
---|
118 | * 4.3.5 enumeration. |
---|
119 | */ |
---|
120 | FACET_ENUMERATION = 2048 |
---|
121 | }; |
---|
122 | |
---|
123 | // possible order relations |
---|
124 | enum ORDERING { |
---|
125 | /** |
---|
126 | * A constant defined for the 'ordered' fundamental facet: Not ordered. |
---|
127 | */ |
---|
128 | ORDERED_FALSE = 0, |
---|
129 | /** |
---|
130 | * A constant defined for the 'ordered' fundamental facet: partially |
---|
131 | * ordered. |
---|
132 | */ |
---|
133 | ORDERED_PARTIAL = 1, |
---|
134 | /** |
---|
135 | * A constant defined for the 'ordered' fundamental facet: total ordered. |
---|
136 | */ |
---|
137 | ORDERED_TOTAL = 2 |
---|
138 | }; |
---|
139 | |
---|
140 | // Constructors and Destructor |
---|
141 | // ----------------------------------------------------------------------- |
---|
142 | /** @name Constructors */ |
---|
143 | //@{ |
---|
144 | |
---|
145 | /** |
---|
146 | * The default constructor |
---|
147 | * |
---|
148 | * @param datatypeValidator |
---|
149 | * @param stVariety |
---|
150 | * @param xsBaseType |
---|
151 | * @param primitiveOrItemType |
---|
152 | * @param memberTypes |
---|
153 | * @param headAnnot |
---|
154 | * @param xsModel |
---|
155 | * @param manager The configurable memory manager |
---|
156 | */ |
---|
157 | XSSimpleTypeDefinition |
---|
158 | ( |
---|
159 | DatatypeValidator* const datatypeValidator |
---|
160 | , VARIETY stVariety |
---|
161 | , XSTypeDefinition* const xsBaseType |
---|
162 | , XSSimpleTypeDefinition* const primitiveOrItemType |
---|
163 | , XSSimpleTypeDefinitionList* const memberTypes |
---|
164 | , XSAnnotation* headAnnot |
---|
165 | , XSModel* const xsModel |
---|
166 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
167 | ); |
---|
168 | |
---|
169 | //@}; |
---|
170 | |
---|
171 | /** @name Destructor */ |
---|
172 | //@{ |
---|
173 | ~XSSimpleTypeDefinition(); |
---|
174 | //@} |
---|
175 | |
---|
176 | //--------------------- |
---|
177 | /** @name XSSimpleTypeDefinition methods */ |
---|
178 | |
---|
179 | //@{ |
---|
180 | |
---|
181 | /** |
---|
182 | * [variety]: one of {atomic, list, union} or absent |
---|
183 | */ |
---|
184 | VARIETY getVariety() const; |
---|
185 | |
---|
186 | /** |
---|
187 | * If variety is <code>atomic</code> the primitive type definition (a |
---|
188 | * built-in primitive datatype definition or the simple ur-type |
---|
189 | * definition) is available, otherwise <code>null</code>. |
---|
190 | */ |
---|
191 | XSSimpleTypeDefinition *getPrimitiveType(); |
---|
192 | |
---|
193 | /** |
---|
194 | * If variety is <code>list</code> the item type definition (an atomic or |
---|
195 | * union simple type definition) is available, otherwise |
---|
196 | * <code>null</code>. |
---|
197 | */ |
---|
198 | XSSimpleTypeDefinition *getItemType(); |
---|
199 | |
---|
200 | /** |
---|
201 | * If variety is <code>union</code> the list of member type definitions (a |
---|
202 | * non-empty sequence of simple type definitions) is available, |
---|
203 | * otherwise <code>null</code>. |
---|
204 | */ |
---|
205 | XSSimpleTypeDefinitionList *getMemberTypes() const; |
---|
206 | |
---|
207 | /** |
---|
208 | * [facets]: get all facets defined on this type. The value is a bit |
---|
209 | * combination of FACET_XXX constants of all defined facets. |
---|
210 | */ |
---|
211 | int getDefinedFacets() const; |
---|
212 | |
---|
213 | /** |
---|
214 | * Convenience method. [Facets]: check whether a facet is defined on this |
---|
215 | * type. |
---|
216 | * @param facetName The name of the facet. |
---|
217 | * @return True if the facet is defined, false otherwise. |
---|
218 | */ |
---|
219 | bool isDefinedFacet(FACET facetName); |
---|
220 | |
---|
221 | /** |
---|
222 | * [facets]: get all facets defined and fixed on this type. |
---|
223 | */ |
---|
224 | int getFixedFacets() const; |
---|
225 | |
---|
226 | /** |
---|
227 | * Convenience method. [Facets]: check whether a facet is defined and |
---|
228 | * fixed on this type. |
---|
229 | * @param facetName The name of the facet. |
---|
230 | * @return True if the facet is fixed, false otherwise. |
---|
231 | */ |
---|
232 | bool isFixedFacet(FACET facetName); |
---|
233 | |
---|
234 | /** |
---|
235 | * Convenience method. Returns a value of a single constraining facet for |
---|
236 | * this simple type definition. This method must not be used to retrieve |
---|
237 | * values for <code>enumeration</code> and <code>pattern</code> facets. |
---|
238 | * @param facetName The name of the facet, i.e. |
---|
239 | * <code>FACET_LENGTH, FACET_TOTALDIGITS </code> (see |
---|
240 | * <code>XSConstants</code>).To retrieve value for pattern or |
---|
241 | * enumeration, see <code>enumeration</code> and <code>pattern</code>. |
---|
242 | * @return A value of the facet specified in <code>facetName</code> for |
---|
243 | * this simple type definition or <code>null</code>. |
---|
244 | */ |
---|
245 | const XMLCh *getLexicalFacetValue(FACET facetName); |
---|
246 | |
---|
247 | /** |
---|
248 | * Returns a list of enumeration values. |
---|
249 | */ |
---|
250 | StringList *getLexicalEnumeration(); |
---|
251 | |
---|
252 | /** |
---|
253 | * Returns a list of pattern values. |
---|
254 | */ |
---|
255 | StringList *getLexicalPattern(); |
---|
256 | |
---|
257 | /** |
---|
258 | * Fundamental Facet: ordered |
---|
259 | */ |
---|
260 | ORDERING getOrdered() const; |
---|
261 | |
---|
262 | /** |
---|
263 | * Fundamental Facet: cardinality. |
---|
264 | */ |
---|
265 | bool getFinite() const; |
---|
266 | |
---|
267 | /** |
---|
268 | * Fundamental Facet: bounded. |
---|
269 | */ |
---|
270 | bool getBounded() const; |
---|
271 | |
---|
272 | /** |
---|
273 | * Fundamental Facet: numeric. |
---|
274 | */ |
---|
275 | bool getNumeric() const; |
---|
276 | |
---|
277 | /** |
---|
278 | * Optional. A set of [annotation]s. |
---|
279 | */ |
---|
280 | XSAnnotationList *getAnnotations(); |
---|
281 | /** |
---|
282 | * @return list of constraining facets. |
---|
283 | * This method must not be used to retrieve |
---|
284 | * values for <code>enumeration</code> and <code>pattern</code> facets. |
---|
285 | */ |
---|
286 | XSFacetList *getFacets(); |
---|
287 | |
---|
288 | /** |
---|
289 | * @return list of enumeration and pattern facets. |
---|
290 | */ |
---|
291 | XSMultiValueFacetList *getMultiValueFacets(); |
---|
292 | |
---|
293 | /** |
---|
294 | * The name of type <code>NCName</code> of this declaration as defined in |
---|
295 | * XML Namespaces. |
---|
296 | */ |
---|
297 | const XMLCh* getName(); |
---|
298 | |
---|
299 | /** |
---|
300 | * The [target namespace] of this object, or <code>null</code> if it is |
---|
301 | * unspecified. |
---|
302 | */ |
---|
303 | const XMLCh* getNamespace(); |
---|
304 | |
---|
305 | /** |
---|
306 | * A namespace schema information item corresponding to the target |
---|
307 | * namespace of the component, if it's globally declared; or null |
---|
308 | * otherwise. |
---|
309 | */ |
---|
310 | XSNamespaceItem *getNamespaceItem(); |
---|
311 | |
---|
312 | /** |
---|
313 | * A boolean that specifies if the type definition is |
---|
314 | * anonymous. Convenience attribute. |
---|
315 | */ |
---|
316 | bool getAnonymous() const; |
---|
317 | |
---|
318 | /** |
---|
319 | * {base type definition}: either a simple type definition or a complex |
---|
320 | * type definition. |
---|
321 | */ |
---|
322 | XSTypeDefinition *getBaseType(); |
---|
323 | |
---|
324 | /** |
---|
325 | * Convenience method: check if this type is derived from the given |
---|
326 | * <code>ancestorType</code>. |
---|
327 | * @param ancestorType An ancestor type definition. |
---|
328 | * @return Return true if this type is derived from |
---|
329 | * <code>ancestorType</code>. |
---|
330 | */ |
---|
331 | bool derivedFromType(const XSTypeDefinition* const ancestorType); |
---|
332 | |
---|
333 | /** |
---|
334 | * |
---|
335 | */ |
---|
336 | inline DatatypeValidator* getDatatypeValidator() const; |
---|
337 | |
---|
338 | //@} |
---|
339 | |
---|
340 | //---------------------------------- |
---|
341 | /** methods needed by implementation */ |
---|
342 | |
---|
343 | //@{ |
---|
344 | |
---|
345 | |
---|
346 | //@} |
---|
347 | |
---|
348 | private: |
---|
349 | |
---|
350 | // ----------------------------------------------------------------------- |
---|
351 | // Unimplemented constructors and operators |
---|
352 | // ----------------------------------------------------------------------- |
---|
353 | XSSimpleTypeDefinition(const XSSimpleTypeDefinition&); |
---|
354 | XSSimpleTypeDefinition & operator=(const XSSimpleTypeDefinition &); |
---|
355 | |
---|
356 | /** |
---|
357 | * Helper method for construct |
---|
358 | */ |
---|
359 | void setFacetInfo |
---|
360 | ( |
---|
361 | int definedFacets |
---|
362 | , int fixedFacets |
---|
363 | , XSFacetList* const xsFacetList |
---|
364 | , XSMultiValueFacetList* const xsMultiValueFacetList |
---|
365 | , StringList* const patternList |
---|
366 | ); |
---|
367 | void setPrimitiveType(XSSimpleTypeDefinition* const toSet); |
---|
368 | |
---|
369 | friend class XSObjectFactory; |
---|
370 | |
---|
371 | protected: |
---|
372 | |
---|
373 | // ----------------------------------------------------------------------- |
---|
374 | // data members |
---|
375 | // ----------------------------------------------------------------------- |
---|
376 | int fDefinedFacets; |
---|
377 | int fFixedFacets; |
---|
378 | VARIETY fVariety; |
---|
379 | DatatypeValidator* fDatatypeValidator; |
---|
380 | XSFacetList* fXSFacetList; |
---|
381 | XSMultiValueFacetList* fXSMultiValueFacetList; |
---|
382 | StringList* fPatternList; |
---|
383 | XSSimpleTypeDefinition* fPrimitiveOrItemType; |
---|
384 | XSSimpleTypeDefinitionList* fMemberTypes; |
---|
385 | XSAnnotationList* fXSAnnotationList; |
---|
386 | }; |
---|
387 | |
---|
388 | inline XSSimpleTypeDefinition::VARIETY XSSimpleTypeDefinition::getVariety() const |
---|
389 | { |
---|
390 | return fVariety; |
---|
391 | } |
---|
392 | |
---|
393 | inline XSSimpleTypeDefinition* XSSimpleTypeDefinition::getPrimitiveType() |
---|
394 | { |
---|
395 | if (fVariety == VARIETY_ATOMIC) |
---|
396 | return fPrimitiveOrItemType; |
---|
397 | |
---|
398 | return 0; |
---|
399 | } |
---|
400 | |
---|
401 | inline XSSimpleTypeDefinition* XSSimpleTypeDefinition::getItemType() |
---|
402 | { |
---|
403 | if (fVariety == VARIETY_LIST) |
---|
404 | return fPrimitiveOrItemType; |
---|
405 | |
---|
406 | return 0; |
---|
407 | } |
---|
408 | |
---|
409 | inline XSSimpleTypeDefinitionList* XSSimpleTypeDefinition::getMemberTypes() const |
---|
410 | { |
---|
411 | return fMemberTypes; |
---|
412 | } |
---|
413 | |
---|
414 | inline int XSSimpleTypeDefinition::getDefinedFacets() const |
---|
415 | { |
---|
416 | return fDefinedFacets; |
---|
417 | } |
---|
418 | |
---|
419 | inline int XSSimpleTypeDefinition::getFixedFacets() const |
---|
420 | { |
---|
421 | return fFixedFacets; |
---|
422 | } |
---|
423 | |
---|
424 | inline StringList* XSSimpleTypeDefinition::getLexicalPattern() |
---|
425 | { |
---|
426 | return fPatternList; |
---|
427 | } |
---|
428 | |
---|
429 | inline XSFacetList* XSSimpleTypeDefinition::getFacets() |
---|
430 | { |
---|
431 | return fXSFacetList; |
---|
432 | } |
---|
433 | |
---|
434 | inline XSMultiValueFacetList* XSSimpleTypeDefinition::getMultiValueFacets() |
---|
435 | { |
---|
436 | return fXSMultiValueFacetList; |
---|
437 | } |
---|
438 | |
---|
439 | inline XSAnnotationList *XSSimpleTypeDefinition::getAnnotations() |
---|
440 | { |
---|
441 | return fXSAnnotationList; |
---|
442 | } |
---|
443 | |
---|
444 | inline void |
---|
445 | XSSimpleTypeDefinition::setPrimitiveType(XSSimpleTypeDefinition* const toSet) |
---|
446 | { |
---|
447 | fPrimitiveOrItemType = toSet; |
---|
448 | } |
---|
449 | |
---|
450 | inline DatatypeValidator* |
---|
451 | XSSimpleTypeDefinition::getDatatypeValidator() const |
---|
452 | { |
---|
453 | return fDatatypeValidator; |
---|
454 | } |
---|
455 | |
---|
456 | XERCES_CPP_NAMESPACE_END |
---|
457 | |
---|
458 | #endif |
---|