1 | /*
|
---|
2 | * Copyright 2001-2002,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: TraverseSchema.hpp,v 1.37 2004/09/28 02:14:14 cargilld Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #if !defined(TRAVERSESCHEMA_HPP)
|
---|
22 | #define TRAVERSESCHEMA_HPP
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Instances of this class get delegated to Traverse the Schema and
|
---|
26 | * to populate the SchemaGrammar internal representation.
|
---|
27 | */
|
---|
28 |
|
---|
29 | // ---------------------------------------------------------------------------
|
---|
30 | // Includes
|
---|
31 | // ---------------------------------------------------------------------------
|
---|
32 | #include <xercesc/util/XMLUniDefs.hpp>
|
---|
33 | #include <xercesc/dom/DOMElement.hpp>
|
---|
34 | #include <xercesc/dom/DOMAttr.hpp>
|
---|
35 | #include <xercesc/framework/XMLBuffer.hpp>
|
---|
36 | #include <xercesc/framework/XMLErrorCodes.hpp>
|
---|
37 | #include <xercesc/validators/schema/SchemaSymbols.hpp>
|
---|
38 | #include <xercesc/util/ValueVectorOf.hpp>
|
---|
39 | #include <xercesc/util/RefHash2KeysTableOf.hpp>
|
---|
40 | #include <xercesc/validators/common/ContentSpecNode.hpp>
|
---|
41 | #include <xercesc/validators/schema/SchemaGrammar.hpp>
|
---|
42 | #include <xercesc/validators/schema/SchemaInfo.hpp>
|
---|
43 | #include <xercesc/validators/schema/GeneralAttributeCheck.hpp>
|
---|
44 | #include <xercesc/validators/schema/XSDErrorReporter.hpp>
|
---|
45 | #include <xercesc/util/XMLResourceIdentifier.hpp>
|
---|
46 |
|
---|
47 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
48 |
|
---|
49 | // ---------------------------------------------------------------------------
|
---|
50 | // Forward Declarations
|
---|
51 | // ---------------------------------------------------------------------------
|
---|
52 | class GrammarResolver;
|
---|
53 | class XMLEntityHandler;
|
---|
54 | class XMLScanner;
|
---|
55 | class DatatypeValidator;
|
---|
56 | class DatatypeValidatorFactory;
|
---|
57 | class QName;
|
---|
58 | class ComplexTypeInfo;
|
---|
59 | class XMLAttDef;
|
---|
60 | class NamespaceScope;
|
---|
61 | class SchemaAttDef;
|
---|
62 | class InputSource;
|
---|
63 | class XercesGroupInfo;
|
---|
64 | class XercesAttGroupInfo;
|
---|
65 | class IdentityConstraint;
|
---|
66 | class XSDLocator;
|
---|
67 | class XSDDOMParser;
|
---|
68 | class XMLErrorReporter;
|
---|
69 |
|
---|
70 |
|
---|
71 | class VALIDATORS_EXPORT TraverseSchema : public XMemory
|
---|
72 | {
|
---|
73 | public:
|
---|
74 | // -----------------------------------------------------------------------
|
---|
75 | // Public Constructors/Destructor
|
---|
76 | // -----------------------------------------------------------------------
|
---|
77 | TraverseSchema
|
---|
78 | (
|
---|
79 | DOMElement* const schemaRoot
|
---|
80 | , XMLStringPool* const uriStringPool
|
---|
81 | , SchemaGrammar* const schemaGrammar
|
---|
82 | , GrammarResolver* const grammarResolver
|
---|
83 | , XMLScanner* const xmlScanner
|
---|
84 | , const XMLCh* const schemaURL
|
---|
85 | , XMLEntityHandler* const entityHandler
|
---|
86 | , XMLErrorReporter* const errorReporter
|
---|
87 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
88 | );
|
---|
89 |
|
---|
90 | ~TraverseSchema();
|
---|
91 |
|
---|
92 | private:
|
---|
93 | // This enumeration is defined here for compatibility with the CodeWarrior
|
---|
94 | // compiler, which apparently doesn't like to accept default parameter
|
---|
95 | // arguments that it hasn't yet seen. The Not_All_Context argument is
|
---|
96 | // used in the declaration of checkMinMax, below.
|
---|
97 | //
|
---|
98 | // Flags indicate any special restrictions on minOccurs and maxOccurs
|
---|
99 | // relating to "all".
|
---|
100 | // Not_All_Context - not processing an <all>
|
---|
101 | // All_Element - processing an <element> in an <all>
|
---|
102 | // Group_Ref_With_All - processing <group> reference that contained <all>
|
---|
103 | // All_Group - processing an <all> group itself
|
---|
104 | enum
|
---|
105 | {
|
---|
106 | Not_All_Context = 0
|
---|
107 | , All_Element = 1
|
---|
108 | , Group_Ref_With_All = 2
|
---|
109 | , All_Group = 4
|
---|
110 | };
|
---|
111 |
|
---|
112 | // -----------------------------------------------------------------------
|
---|
113 | // Unimplemented constructors and operators
|
---|
114 | // -----------------------------------------------------------------------
|
---|
115 | TraverseSchema(const TraverseSchema&);
|
---|
116 | TraverseSchema& operator=(const TraverseSchema&);
|
---|
117 |
|
---|
118 | // -----------------------------------------------------------------------
|
---|
119 | // Init/CleanUp methods
|
---|
120 | // -----------------------------------------------------------------------
|
---|
121 | void init();
|
---|
122 | void cleanUp();
|
---|
123 |
|
---|
124 | // -----------------------------------------------------------------------
|
---|
125 | // Traversal methods
|
---|
126 | // -----------------------------------------------------------------------
|
---|
127 | /**
|
---|
128 | * Traverse the Schema DOM tree
|
---|
129 | */
|
---|
130 | void doTraverseSchema(const DOMElement* const schemaRoot);
|
---|
131 | void preprocessSchema(DOMElement* const schemaRoot,
|
---|
132 | const XMLCh* const schemaURL);
|
---|
133 | void traverseSchemaHeader(const DOMElement* const schemaRoot);
|
---|
134 | XSAnnotation* traverseAnnotationDecl(const DOMElement* const childElem,
|
---|
135 | ValueVectorOf<DOMNode*>* const nonXSAttList,
|
---|
136 | const bool topLevel = false);
|
---|
137 | void traverseInclude(const DOMElement* const childElem);
|
---|
138 | void traverseImport(const DOMElement* const childElem);
|
---|
139 | void traverseRedefine(const DOMElement* const childElem);
|
---|
140 | void traverseAttributeDecl(const DOMElement* const childElem,
|
---|
141 | ComplexTypeInfo* const typeInfo,
|
---|
142 | const bool topLevel = false);
|
---|
143 | void traverseSimpleContentDecl(const XMLCh* const typeName,
|
---|
144 | const XMLCh* const qualifiedName,
|
---|
145 | const DOMElement* const contentDecl,
|
---|
146 | ComplexTypeInfo* const typeInfo,
|
---|
147 | Janitor<XSAnnotation>* const janAnnot);
|
---|
148 | void traverseComplexContentDecl(const XMLCh* const typeName,
|
---|
149 | const DOMElement* const contentDecl,
|
---|
150 | ComplexTypeInfo* const typeInfo,
|
---|
151 | const bool isMixed,
|
---|
152 | Janitor<XSAnnotation>* const janAnnot);
|
---|
153 | DatatypeValidator* traverseSimpleTypeDecl(const DOMElement* const childElem,
|
---|
154 | const bool topLevel = true,
|
---|
155 | int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
|
---|
156 | int traverseComplexTypeDecl(const DOMElement* const childElem,
|
---|
157 | const bool topLevel = true,
|
---|
158 | const XMLCh* const recursingTypeName = 0);
|
---|
159 | DatatypeValidator* traverseByList(const DOMElement* const rootElem,
|
---|
160 | const DOMElement* const contentElem,
|
---|
161 | const XMLCh* const typeName,
|
---|
162 | const XMLCh* const qualifiedName,
|
---|
163 | const int finalSet,
|
---|
164 | Janitor<XSAnnotation>* const janAnnot);
|
---|
165 | DatatypeValidator* traverseByRestriction(const DOMElement* const rootElem,
|
---|
166 | const DOMElement* const contentElem,
|
---|
167 | const XMLCh* const typeName,
|
---|
168 | const XMLCh* const qualifiedName,
|
---|
169 | const int finalSet,
|
---|
170 | Janitor<XSAnnotation>* const janAnnot);
|
---|
171 | DatatypeValidator* traverseByUnion(const DOMElement* const rootElem,
|
---|
172 | const DOMElement* const contentElem,
|
---|
173 | const XMLCh* const typeName,
|
---|
174 | const XMLCh* const qualifiedName,
|
---|
175 | const int finalSet,
|
---|
176 | int baseRefContext,
|
---|
177 | Janitor<XSAnnotation>* const janAnnot);
|
---|
178 | SchemaElementDecl* traverseElementDecl(const DOMElement* const childElem,
|
---|
179 | const bool topLevel = false);
|
---|
180 | const XMLCh* traverseNotationDecl(const DOMElement* const childElem);
|
---|
181 | const XMLCh* traverseNotationDecl(const DOMElement* const childElem,
|
---|
182 | const XMLCh* const name,
|
---|
183 | const XMLCh* const uriStr);
|
---|
184 | ContentSpecNode* traverseChoiceSequence(const DOMElement* const elemDecl,
|
---|
185 | const int modelGroupType);
|
---|
186 | ContentSpecNode* traverseAny(const DOMElement* const anyDecl);
|
---|
187 | ContentSpecNode* traverseAll(const DOMElement* const allElem);
|
---|
188 | XercesGroupInfo* traverseGroupDecl(const DOMElement* const childElem,
|
---|
189 | const bool topLevel = true);
|
---|
190 | XercesAttGroupInfo* traverseAttributeGroupDecl(const DOMElement* const elem,
|
---|
191 | ComplexTypeInfo* const typeInfo,
|
---|
192 | const bool topLevel = false);
|
---|
193 | XercesAttGroupInfo* traverseAttributeGroupDeclNS(const DOMElement* const elem,
|
---|
194 | const XMLCh* const uriStr,
|
---|
195 | const XMLCh* const name);
|
---|
196 | SchemaAttDef* traverseAnyAttribute(const DOMElement* const elem);
|
---|
197 | void traverseKey(const DOMElement* const icElem,
|
---|
198 | SchemaElementDecl* const elemDecl);
|
---|
199 | void traverseUnique(const DOMElement* const icElem,
|
---|
200 | SchemaElementDecl* const elemDecl);
|
---|
201 | void traverseKeyRef(const DOMElement* const icElem,
|
---|
202 | SchemaElementDecl* const elemDecl,
|
---|
203 | const unsigned int namespaceDepth);
|
---|
204 | bool traverseIdentityConstraint(IdentityConstraint* const ic,
|
---|
205 | const DOMElement* const icElem);
|
---|
206 |
|
---|
207 | // -----------------------------------------------------------------------
|
---|
208 | // Error Reporting methods
|
---|
209 | // -----------------------------------------------------------------------
|
---|
210 | void reportSchemaError(const XSDLocator* const aLocator,
|
---|
211 | const XMLCh* const msgDomain,
|
---|
212 | const int errorCode);
|
---|
213 | void reportSchemaError(const XSDLocator* const aLocator,
|
---|
214 | const XMLCh* const msgDomain,
|
---|
215 | const int errorCode,
|
---|
216 | const XMLCh* const text1,
|
---|
217 | const XMLCh* const text2 = 0,
|
---|
218 | const XMLCh* const text3 = 0,
|
---|
219 | const XMLCh* const text4 = 0);
|
---|
220 | void reportSchemaError(const DOMElement* const elem,
|
---|
221 | const XMLCh* const msgDomain,
|
---|
222 | const int errorCode);
|
---|
223 | void reportSchemaError(const DOMElement* const elem,
|
---|
224 | const XMLCh* const msgDomain,
|
---|
225 | const int errorCode,
|
---|
226 | const XMLCh* const text1,
|
---|
227 | const XMLCh* const text2 = 0,
|
---|
228 | const XMLCh* const text3 = 0,
|
---|
229 | const XMLCh* const text4 = 0);
|
---|
230 |
|
---|
231 | // -----------------------------------------------------------------------
|
---|
232 | // Private Helper methods
|
---|
233 | // -----------------------------------------------------------------------
|
---|
234 | /**
|
---|
235 | * Retrived the Namespace mapping from the schema element
|
---|
236 | */
|
---|
237 | void retrieveNamespaceMapping(const DOMElement* const schemaRoot);
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Loop through the children, and traverse the corresponding schema type
|
---|
241 | * type declaration (simpleType, complexType, import, ....)
|
---|
242 | */
|
---|
243 | void processChildren(const DOMElement* const root);
|
---|
244 | void preprocessChildren(const DOMElement* const root);
|
---|
245 |
|
---|
246 | void preprocessImport(const DOMElement* const elemNode);
|
---|
247 | void preprocessInclude(const DOMElement* const elemNode);
|
---|
248 | void preprocessRedefine(const DOMElement* const elemNode);
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Parameters:
|
---|
252 | * rootElem - top element for a given type declaration
|
---|
253 | * contentElem - content must be annotation? or some other simple content
|
---|
254 | * isEmpty: - true if (annotation?, smth_else), false if (annotation?)
|
---|
255 | *
|
---|
256 | * Check for Annotation if it is present, traverse it. If a sibling is
|
---|
257 | * found and it is not an annotation return it, otherwise return 0.
|
---|
258 | * Used by traverseSimpleTypeDecl.
|
---|
259 | */
|
---|
260 | DOMElement* checkContent(const DOMElement* const rootElem,
|
---|
261 | DOMElement* const contentElem,
|
---|
262 | const bool isEmpty);
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Parameters:
|
---|
266 | * contentElem - content element to check
|
---|
267 | *
|
---|
268 | * Check for identity constraints content.
|
---|
269 | */
|
---|
270 | const DOMElement* checkIdentityConstraintContent(const DOMElement* const contentElem);
|
---|
271 |
|
---|
272 | DatatypeValidator* getDatatypeValidator(const XMLCh* const uriStr,
|
---|
273 | const XMLCh* const localPartStr);
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Process simpleType content of a list|restriction|union
|
---|
277 | * Return a dataype validator if valid type, otherwise 0.
|
---|
278 | */
|
---|
279 | DatatypeValidator* checkForSimpleTypeValidator(const DOMElement* const content,
|
---|
280 | int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Process complexType content of an element
|
---|
284 | * Return a ComplexTypeInfo if valid type, otherwise 0.
|
---|
285 | */
|
---|
286 | ComplexTypeInfo* checkForComplexTypeInfo(const DOMElement* const content);
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Return DatatypeValidator available for the baseTypeStr.
|
---|
290 | */
|
---|
291 | DatatypeValidator* findDTValidator(const DOMElement* const elem,
|
---|
292 | const XMLCh* const derivedTypeName,
|
---|
293 | const XMLCh* const baseTypeName,
|
---|
294 | const int baseRefContext);
|
---|
295 |
|
---|
296 | const XMLCh* resolvePrefixToURI(const DOMElement* const elem,
|
---|
297 | const XMLCh* const prefix);
|
---|
298 | const XMLCh* resolvePrefixToURI(const DOMElement* const elem,
|
---|
299 | const XMLCh* const prefix,
|
---|
300 | const unsigned int namespaceDepth);
|
---|
301 |
|
---|
302 | /**
|
---|
303 | * Return the prefix for a given rawname string
|
---|
304 | *
|
---|
305 | * Function allocated, caller managed (facm) - pointer to be deleted by
|
---|
306 | * caller.
|
---|
307 | */
|
---|
308 | const XMLCh* getPrefix(const XMLCh* const rawName);
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * Return the local for a given rawname string
|
---|
312 | *
|
---|
313 | * caller allocated, caller managed (cacm)
|
---|
314 | */
|
---|
315 | const XMLCh* getLocalPart(const XMLCh* const rawName);
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Process a 'ref' of an Element declaration
|
---|
319 | */
|
---|
320 | SchemaElementDecl* processElementDeclRef(const DOMElement* const elem,
|
---|
321 | const XMLCh* const refName);
|
---|
322 | void processElemDeclAttrs(const DOMElement* const elem,
|
---|
323 | SchemaElementDecl* const elemDecl,
|
---|
324 | const XMLCh*& valConstraint,
|
---|
325 | bool isTopLevel = false);
|
---|
326 | void processElemDeclIC(DOMElement* const elem,
|
---|
327 | SchemaElementDecl* const elemDecl);
|
---|
328 | bool checkElemDeclValueConstraint(const DOMElement* const elem,
|
---|
329 | SchemaElementDecl* const elemDecl,
|
---|
330 | const XMLCh* const valConstraint,
|
---|
331 | ComplexTypeInfo* const typeInfo,
|
---|
332 | DatatypeValidator* const validator);
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * Process a 'ref' of an Attribute declaration
|
---|
336 | */
|
---|
337 | void processAttributeDeclRef(const DOMElement* const elem,
|
---|
338 | ComplexTypeInfo* const typeInfo,
|
---|
339 | const XMLCh* const refName,
|
---|
340 | const XMLCh* const useVal,
|
---|
341 | const XMLCh* const defaultVal,
|
---|
342 | const XMLCh* const fixedVal);
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * Process a 'ref' on a group
|
---|
346 | */
|
---|
347 | XercesGroupInfo* processGroupRef(const DOMElement* const elem,
|
---|
348 | const XMLCh* const refName);
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Process a 'ref' on a attributeGroup
|
---|
352 | */
|
---|
353 | XercesAttGroupInfo* processAttributeGroupRef(const DOMElement* const elem,
|
---|
354 | const XMLCh* const refName,
|
---|
355 | ComplexTypeInfo* const typeInfo);
|
---|
356 |
|
---|
357 | /**
|
---|
358 | * Parse block & final items
|
---|
359 | */
|
---|
360 | int parseBlockSet(const DOMElement* const elem, const int blockType, const bool isRoot = false);
|
---|
361 | int parseFinalSet(const DOMElement* const elem, const int finalType, const bool isRoot = false);
|
---|
362 |
|
---|
363 | /**
|
---|
364 | * Return true if a name is an identity constraint, otherwise false
|
---|
365 | */
|
---|
366 | bool isIdentityConstraintName(const XMLCh* const constraintName);
|
---|
367 |
|
---|
368 | /**
|
---|
369 | * If 'typeStr' belongs to a different schema, return that schema URI,
|
---|
370 | * otherwise return 0;
|
---|
371 | */
|
---|
372 | const XMLCh* checkTypeFromAnotherSchema(const DOMElement* const elem,
|
---|
373 | const XMLCh* const typeStr);
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Return the datatype validator for a given element type attribute if
|
---|
377 | * the type is a simple type
|
---|
378 | */
|
---|
379 | DatatypeValidator* getElementTypeValidator(const DOMElement* const elem,
|
---|
380 | const XMLCh* const typeStr,
|
---|
381 | bool& noErrorDetected,
|
---|
382 | const XMLCh* const otherSchemaURI);
|
---|
383 |
|
---|
384 | /**
|
---|
385 | * Return the complexType info for a given element type attribute if
|
---|
386 | * the type is a complex type
|
---|
387 | */
|
---|
388 | ComplexTypeInfo* getElementComplexTypeInfo(const DOMElement* const elem,
|
---|
389 | const XMLCh* const typeStr,
|
---|
390 | const XMLCh* const otherSchemaURI);
|
---|
391 |
|
---|
392 | /**
|
---|
393 | * Return global schema element declaration for a given element name
|
---|
394 | */
|
---|
395 | SchemaElementDecl* getGlobalElemDecl(const DOMElement* const elem,
|
---|
396 | const XMLCh* const name);
|
---|
397 |
|
---|
398 | /**
|
---|
399 | * Check validity constraint of a substitutionGroup attribute in
|
---|
400 | * an element declaration
|
---|
401 | */
|
---|
402 | bool isSubstitutionGroupValid(const DOMElement* const elem,
|
---|
403 | const SchemaElementDecl* const elemDecl,
|
---|
404 | const ComplexTypeInfo* const typeInfo,
|
---|
405 | const DatatypeValidator* const validator,
|
---|
406 | const XMLCh* const elemName,
|
---|
407 | const bool toEmit = true);
|
---|
408 |
|
---|
409 | bool isSubstitutionGroupCircular(SchemaElementDecl* const elemDecl,
|
---|
410 | SchemaElementDecl* const subsElemDecl);
|
---|
411 |
|
---|
412 | void processSubstitutionGroup(const DOMElement* const elem,
|
---|
413 | SchemaElementDecl* elemDecl,
|
---|
414 | ComplexTypeInfo*& typeInfo,
|
---|
415 | DatatypeValidator*& validator,
|
---|
416 | const XMLCh* const subsElemQName);
|
---|
417 |
|
---|
418 | /**
|
---|
419 | * Create a 'SchemaElementDecl' object and add it to SchemaGrammar
|
---|
420 | */
|
---|
421 | SchemaElementDecl* createSchemaElementDecl(const DOMElement* const elem,
|
---|
422 | const XMLCh* const name,
|
---|
423 | bool& isDuplicate,
|
---|
424 | const XMLCh*& valConstraint,
|
---|
425 | const bool topLevel);
|
---|
426 |
|
---|
427 | /**
|
---|
428 | * Return the value of a given attribute name from an element node
|
---|
429 | */
|
---|
430 | const XMLCh* getElementAttValue(const DOMElement* const elem,
|
---|
431 | const XMLCh* const attName,
|
---|
432 | const bool toTrim = false);
|
---|
433 |
|
---|
434 | void checkMinMax(ContentSpecNode* const specNode,
|
---|
435 | const DOMElement* const elem,
|
---|
436 | const int allContext = Not_All_Context);
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Process complex content for a complexType
|
---|
440 | */
|
---|
441 | void processComplexContent(const DOMElement* const elem,
|
---|
442 | const XMLCh* const typeName,
|
---|
443 | const DOMElement* const childElem,
|
---|
444 | ComplexTypeInfo* const typeInfo,
|
---|
445 | const XMLCh* const baseLocalPart,
|
---|
446 | const bool isMixed,
|
---|
447 | const bool isBaseAnyType = false);
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Process "base" information for a complexType
|
---|
451 | */
|
---|
452 | void processBaseTypeInfo(const DOMElement* const elem,
|
---|
453 | const XMLCh* const baseName,
|
---|
454 | const XMLCh* const localPart,
|
---|
455 | const XMLCh* const uriStr,
|
---|
456 | ComplexTypeInfo* const typeInfo);
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Check if base is from another schema
|
---|
460 | */
|
---|
461 | bool isBaseFromAnotherSchema(const XMLCh* const baseURI);
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Get complexType infp from another schema
|
---|
465 | */
|
---|
466 | ComplexTypeInfo* getTypeInfoFromNS(const DOMElement* const elem,
|
---|
467 | const XMLCh* const uriStr,
|
---|
468 | const XMLCh* const localPart);
|
---|
469 |
|
---|
470 | DatatypeValidator*
|
---|
471 | getAttrDatatypeValidatorNS(const DOMElement* const elem,
|
---|
472 | const XMLCh* localPart,
|
---|
473 | const XMLCh* typeURI);
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Returns true if a DOM Element is an attribute or attribute group
|
---|
477 | */
|
---|
478 | bool isAttrOrAttrGroup(const DOMElement* const elem);
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * Process attributes of a complex type
|
---|
482 | */
|
---|
483 | void processAttributes(const DOMElement* const elem,
|
---|
484 | const DOMElement* const attElem,
|
---|
485 | ComplexTypeInfo* const typeInfo,
|
---|
486 | const bool isBaseAnyType = false);
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Generate a name for an anonymous type
|
---|
490 | */
|
---|
491 | const XMLCh* genAnonTypeName(const XMLCh* const prefix);
|
---|
492 |
|
---|
493 | void defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo);
|
---|
494 |
|
---|
495 | /**
|
---|
496 | * Resolve a schema location attribute value to an input source.
|
---|
497 | * Caller to delete the returned object.
|
---|
498 | */
|
---|
499 | InputSource* resolveSchemaLocation
|
---|
500 | (
|
---|
501 | const XMLCh* const loc
|
---|
502 | , const XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType
|
---|
503 | , const XMLCh* const nameSpace=0
|
---|
504 | );
|
---|
505 |
|
---|
506 | void restoreSchemaInfo(SchemaInfo* const toRestore,
|
---|
507 | SchemaInfo::ListType const aListType = SchemaInfo::INCLUDE,
|
---|
508 | const int saveScope = Grammar::TOP_LEVEL_SCOPE);
|
---|
509 | void popCurrentTypeNameStack();
|
---|
510 |
|
---|
511 | /**
|
---|
512 | * Check whether a mixed content is emptiable or not.
|
---|
513 | * Needed to validate element constraint values (defualt, fixed)
|
---|
514 | */
|
---|
515 | bool emptiableParticle(const ContentSpecNode* const specNode);
|
---|
516 |
|
---|
517 | void checkFixedFacet(const DOMElement* const, const XMLCh* const,
|
---|
518 | const DatatypeValidator* const, unsigned int&);
|
---|
519 | void buildValidSubstitutionListF(const DOMElement* const elem,
|
---|
520 | SchemaElementDecl* const,
|
---|
521 | SchemaElementDecl* const);
|
---|
522 | void buildValidSubstitutionListB(const DOMElement* const elem,
|
---|
523 | SchemaElementDecl* const,
|
---|
524 | SchemaElementDecl* const);
|
---|
525 |
|
---|
526 | void checkEnumerationRequiredNotation(const DOMElement* const elem,
|
---|
527 | const XMLCh* const name,
|
---|
528 | const XMLCh* const typeStr);
|
---|
529 |
|
---|
530 | void processElements(const DOMElement* const elem,
|
---|
531 | ComplexTypeInfo* const baseTypeInfo,
|
---|
532 | ComplexTypeInfo* const newTypeInfo);
|
---|
533 |
|
---|
534 | void processElements(const DOMElement* const elem,
|
---|
535 | XercesGroupInfo* const fromGroup,
|
---|
536 | ComplexTypeInfo* const typeInfo);
|
---|
537 |
|
---|
538 | void copyGroupElements(const DOMElement* const elem,
|
---|
539 | XercesGroupInfo* const fromGroup,
|
---|
540 | XercesGroupInfo* const toGroup,
|
---|
541 | ComplexTypeInfo* const typeInfo);
|
---|
542 |
|
---|
543 | void copyAttGroupAttributes(const DOMElement* const elem,
|
---|
544 | XercesAttGroupInfo* const fromAttGroup,
|
---|
545 | XercesAttGroupInfo* const toAttGroup,
|
---|
546 | ComplexTypeInfo* const typeInfo);
|
---|
547 |
|
---|
548 | void checkForEmptyTargetNamespace(const DOMElement* const elem);
|
---|
549 |
|
---|
550 | /**
|
---|
551 | * Attribute wild card intersection.
|
---|
552 | *
|
---|
553 | * Note:
|
---|
554 | * The first parameter will be the result of the intersection, so
|
---|
555 | * we need to make sure that first parameter is a copy of the
|
---|
556 | * actual attribute definition we need to intersect with.
|
---|
557 | *
|
---|
558 | * What we need to wory about is: type, defaultType, namespace,
|
---|
559 | * and URI. All remaining data members should be the same.
|
---|
560 | */
|
---|
561 | void attWildCardIntersection(SchemaAttDef* const resultWildCart,
|
---|
562 | const SchemaAttDef* const toCompareWildCard);
|
---|
563 |
|
---|
564 | /**
|
---|
565 | * Attribute wild card union.
|
---|
566 | *
|
---|
567 | * Note:
|
---|
568 | * The first parameter will be the result of the union, so
|
---|
569 | * we need to make sure that first parameter is a copy of the
|
---|
570 | * actual attribute definition we need to intersect with.
|
---|
571 | *
|
---|
572 | * What we need to wory about is: type, defaultType, namespace,
|
---|
573 | * and URI. All remaining data members should be the same.
|
---|
574 | */
|
---|
575 | void attWildCardUnion(SchemaAttDef* const resultWildCart,
|
---|
576 | const SchemaAttDef* const toCompareWildCard);
|
---|
577 |
|
---|
578 | void copyWildCardData(const SchemaAttDef* const srcWildCard,
|
---|
579 | SchemaAttDef* const destWildCard);
|
---|
580 |
|
---|
581 | /**
|
---|
582 | * Check that the attributes of a type derived by restriction satisfy
|
---|
583 | * the constraints of derivation valid restriction
|
---|
584 | */
|
---|
585 | void checkAttDerivationOK(const DOMElement* const elem,
|
---|
586 | const ComplexTypeInfo* const baseTypeInfo,
|
---|
587 | const ComplexTypeInfo* const childTypeInfo);
|
---|
588 | void checkAttDerivationOK(const DOMElement* const elem,
|
---|
589 | const XercesAttGroupInfo* const baseAttGrpInfo,
|
---|
590 | const XercesAttGroupInfo* const childAttGrpInfo);
|
---|
591 |
|
---|
592 | /**
|
---|
593 | * Check whether a namespace value is valid with respect to wildcard
|
---|
594 | * constraint
|
---|
595 | */
|
---|
596 | bool wildcardAllowsNamespace(const SchemaAttDef* const baseAttWildCard,
|
---|
597 | const unsigned int nameURI);
|
---|
598 |
|
---|
599 | /**
|
---|
600 | * Check whether a namespace constraint is an intensional subset of
|
---|
601 | * another namespace constraint
|
---|
602 | */
|
---|
603 | bool isWildCardSubset(const SchemaAttDef* const baseAttWildCard,
|
---|
604 | const SchemaAttDef* const childAttWildCard);
|
---|
605 |
|
---|
606 | bool openRedefinedSchema(const DOMElement* const redefineElem);
|
---|
607 |
|
---|
608 | /**
|
---|
609 | * The purpose of this method is twofold:
|
---|
610 | * 1. To find and appropriately modify all information items
|
---|
611 | * in redefinedSchema with names that are redefined by children of
|
---|
612 | * redefineElem.
|
---|
613 | * 2. To make sure the redefine element represented by
|
---|
614 | * redefineElem is valid as far as content goes and with regard to
|
---|
615 | * properly referencing components to be redefined.
|
---|
616 | *
|
---|
617 | * No traversing is done here!
|
---|
618 | * This method also takes actions to find and, if necessary, modify
|
---|
619 | * the names of elements in <redefine>'s in the schema that's being
|
---|
620 | * redefined.
|
---|
621 | */
|
---|
622 | void renameRedefinedComponents(const DOMElement* const redefineElem,
|
---|
623 | SchemaInfo* const redefiningSchemaInfo,
|
---|
624 | SchemaInfo* const redefinedSchemaInfo);
|
---|
625 |
|
---|
626 | /**
|
---|
627 | * This method returns true if the redefine component is valid, and if
|
---|
628 | * it was possible to revise it correctly.
|
---|
629 | */
|
---|
630 | bool validateRedefineNameChange(const DOMElement* const redefineChildElem,
|
---|
631 | const XMLCh* const redefineChildElemName,
|
---|
632 | const XMLCh* const redefineChildDeclName,
|
---|
633 | const int redefineNameCounter,
|
---|
634 | SchemaInfo* const redefiningSchemaInfo);
|
---|
635 |
|
---|
636 | /**
|
---|
637 | * This function looks among the children of 'redefineChildElem' for a
|
---|
638 | * component of type 'redefineChildComponentName'. If it finds one, it
|
---|
639 | * evaluates whether its ref attribute contains a reference to
|
---|
640 | * 'refChildTypeName'. If it does, it returns 1 + the value returned by
|
---|
641 | * calls to itself on all other children. In all other cases it returns
|
---|
642 | * 0 plus the sum of the values returned by calls to itself on
|
---|
643 | * redefineChildElem's children. It also resets the value of ref so that
|
---|
644 | * it will refer to the renamed type from the schema being redefined.
|
---|
645 | */
|
---|
646 | int changeRedefineGroup(const DOMElement* const redefineChildElem,
|
---|
647 | const XMLCh* const redefineChildComponentName,
|
---|
648 | const XMLCh* const redefineChildTypeName,
|
---|
649 | const int redefineNameCounter);
|
---|
650 |
|
---|
651 | /** This simple function looks for the first occurrence of a
|
---|
652 | * 'redefineChildTypeName' item in the redefined schema and appropriately
|
---|
653 | * changes the value of its name. If it turns out that what we're looking
|
---|
654 | * for is in a <redefine> though, then we just rename it--and it's
|
---|
655 | * reference--to be the same.
|
---|
656 | */
|
---|
657 | void fixRedefinedSchema(const DOMElement* const elem,
|
---|
658 | SchemaInfo* const redefinedSchemaInfo,
|
---|
659 | const XMLCh* const redefineChildComponentName,
|
---|
660 | const XMLCh* const redefineChildTypeName,
|
---|
661 | const int redefineNameCounter);
|
---|
662 |
|
---|
663 | void getRedefineNewTypeName(const XMLCh* const oldTypeName,
|
---|
664 | const int redefineCounter,
|
---|
665 | XMLBuffer& newTypeName);
|
---|
666 |
|
---|
667 | /**
|
---|
668 | * This purpose of this method is threefold:
|
---|
669 | * 1. To extract the schema information of included/redefined schema.
|
---|
670 | * 2. Rename redefined components.
|
---|
671 | * 3. Process components of included/redefined schemas
|
---|
672 | */
|
---|
673 | void preprocessRedefineInclude(SchemaInfo* const currSchemaInfo);
|
---|
674 |
|
---|
675 | /**
|
---|
676 | * Update the list of valid substitution groups in the case of circular
|
---|
677 | * import.
|
---|
678 | */
|
---|
679 | void updateCircularSubstitutionList(SchemaInfo* const aSchemaInfo);
|
---|
680 |
|
---|
681 | void processKeyRefFor(SchemaInfo* const aSchemaInfo,
|
---|
682 | ValueVectorOf<SchemaInfo*>* const infoList);
|
---|
683 |
|
---|
684 | void processAttValue(const XMLCh* const attVal, XMLBuffer& aBuf);
|
---|
685 |
|
---|
686 | // routine to generate synthetic annotations
|
---|
687 | XSAnnotation* generateSyntheticAnnotation(const DOMElement* const elem
|
---|
688 | , ValueVectorOf<DOMNode*>* nonXSAttList);
|
---|
689 |
|
---|
690 | // routine to validate annotations
|
---|
691 | void validateAnnotations();
|
---|
692 |
|
---|
693 | // -----------------------------------------------------------------------
|
---|
694 | // Private constants
|
---|
695 | // -----------------------------------------------------------------------
|
---|
696 | enum
|
---|
697 | {
|
---|
698 | ES_Block
|
---|
699 | , C_Block
|
---|
700 | , S_Final
|
---|
701 | , EC_Final
|
---|
702 | , ECS_Final
|
---|
703 | };
|
---|
704 |
|
---|
705 | enum ExceptionCodes
|
---|
706 | {
|
---|
707 | NoException = 0,
|
---|
708 | InvalidComplexTypeInfo = 1,
|
---|
709 | RecursingElement = 2
|
---|
710 | };
|
---|
711 |
|
---|
712 | enum
|
---|
713 | {
|
---|
714 | Elem_Def_Qualified = 1,
|
---|
715 | Attr_Def_Qualified = 2
|
---|
716 | };
|
---|
717 |
|
---|
718 | // -----------------------------------------------------------------------
|
---|
719 | // Private data members
|
---|
720 | // -----------------------------------------------------------------------
|
---|
721 | bool fFullConstraintChecking;
|
---|
722 | int fTargetNSURI;
|
---|
723 | int fEmptyNamespaceURI;
|
---|
724 | int fCurrentScope;
|
---|
725 | int fScopeCount;
|
---|
726 | unsigned int fAnonXSTypeCount;
|
---|
727 | unsigned int fCircularCheckIndex;
|
---|
728 | const XMLCh* fTargetNSURIString;
|
---|
729 | DatatypeValidatorFactory* fDatatypeRegistry;
|
---|
730 | GrammarResolver* fGrammarResolver;
|
---|
731 | SchemaGrammar* fSchemaGrammar;
|
---|
732 | XMLEntityHandler* fEntityHandler;
|
---|
733 | XMLErrorReporter* fErrorReporter;
|
---|
734 | XMLStringPool* fURIStringPool;
|
---|
735 | XMLStringPool* fStringPool;
|
---|
736 | XMLBuffer fBuffer;
|
---|
737 | XMLScanner* fScanner;
|
---|
738 | NamespaceScope* fNamespaceScope;
|
---|
739 | RefHashTableOf<XMLAttDef>* fAttributeDeclRegistry;
|
---|
740 | RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
|
---|
741 | RefHashTableOf<XercesGroupInfo>* fGroupRegistry;
|
---|
742 | RefHashTableOf<XercesAttGroupInfo>* fAttGroupRegistry;
|
---|
743 | RefHashTableOf<ElemVector>* fIC_ElementsNS;
|
---|
744 | RefHashTableOf<SchemaInfo>* fPreprocessedNodes;
|
---|
745 | SchemaInfo* fSchemaInfo;
|
---|
746 | XercesGroupInfo* fCurrentGroupInfo;
|
---|
747 | XercesAttGroupInfo* fCurrentAttGroupInfo;
|
---|
748 | ComplexTypeInfo* fCurrentComplexType;
|
---|
749 | ValueVectorOf<unsigned int>* fCurrentTypeNameStack;
|
---|
750 | ValueVectorOf<unsigned int>* fCurrentGroupStack;
|
---|
751 | ValueVectorOf<unsigned int>* fIC_NamespaceDepth;
|
---|
752 | ValueVectorOf<SchemaElementDecl*>* fIC_Elements;
|
---|
753 | ValueVectorOf<const DOMElement*>* fDeclStack;
|
---|
754 | ValueVectorOf<unsigned int>** fGlobalDeclarations;
|
---|
755 | ValueVectorOf<DOMNode*>* fNonXSAttList;
|
---|
756 | RefHashTableOf<ValueVectorOf<DOMElement*> >* fIC_NodeListNS;
|
---|
757 | RefHashTableOf<ValueVectorOf<unsigned int> >* fIC_NamespaceDepthNS;
|
---|
758 | RefHash2KeysTableOf<XMLCh>* fNotationRegistry;
|
---|
759 | RefHash2KeysTableOf<XMLCh>* fRedefineComponents;
|
---|
760 | RefHash2KeysTableOf<IdentityConstraint>* fIdentityConstraintNames;
|
---|
761 | RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
|
---|
762 | RefHash2KeysTableOf<SchemaInfo>* fSchemaInfoList;
|
---|
763 | XSDDOMParser* fParser;
|
---|
764 | XSDErrorReporter fXSDErrorReporter;
|
---|
765 | XSDLocator* fLocator;
|
---|
766 | MemoryManager* fMemoryManager;
|
---|
767 | MemoryManager* fGrammarPoolMemoryManager;
|
---|
768 | XSAnnotation* fAnnotation;
|
---|
769 | GeneralAttributeCheck fAttributeCheck;
|
---|
770 |
|
---|
771 | friend class GeneralAttributeCheck;
|
---|
772 | };
|
---|
773 |
|
---|
774 |
|
---|
775 | // ---------------------------------------------------------------------------
|
---|
776 | // TraverseSchema: Helper methods
|
---|
777 | // ---------------------------------------------------------------------------
|
---|
778 | inline const XMLCh* TraverseSchema::getPrefix(const XMLCh* const rawName) {
|
---|
779 |
|
---|
780 | int colonIndex = XMLString::indexOf(rawName, chColon);
|
---|
781 |
|
---|
782 | if (colonIndex == -1 || colonIndex == 0) {
|
---|
783 | return XMLUni::fgZeroLenString;
|
---|
784 | }
|
---|
785 |
|
---|
786 | fBuffer.set(rawName, colonIndex);
|
---|
787 |
|
---|
788 | return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
|
---|
789 | }
|
---|
790 |
|
---|
791 | inline const XMLCh* TraverseSchema::getLocalPart(const XMLCh* const rawName) {
|
---|
792 |
|
---|
793 | int colonIndex = XMLString::indexOf(rawName, chColon);
|
---|
794 | int rawNameLen = XMLString::stringLen(rawName);
|
---|
795 |
|
---|
796 | if (colonIndex + 1 == rawNameLen) {
|
---|
797 | return XMLUni::fgZeroLenString;
|
---|
798 | }
|
---|
799 |
|
---|
800 | if (colonIndex == -1) {
|
---|
801 | fBuffer.set(rawName, rawNameLen);
|
---|
802 | }
|
---|
803 | else {
|
---|
804 |
|
---|
805 | fBuffer.set(rawName + colonIndex + 1, rawNameLen - colonIndex - 1);
|
---|
806 | }
|
---|
807 |
|
---|
808 | return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
|
---|
809 | }
|
---|
810 |
|
---|
811 | inline
|
---|
812 | const XMLCh* TraverseSchema::getElementAttValue(const DOMElement* const elem,
|
---|
813 | const XMLCh* const attName,
|
---|
814 | const bool toTrim) {
|
---|
815 |
|
---|
816 | DOMAttr* attNode = elem->getAttributeNode(attName);
|
---|
817 |
|
---|
818 | if (attNode == 0) {
|
---|
819 | return 0;
|
---|
820 | }
|
---|
821 |
|
---|
822 | const XMLCh* attValue = attNode->getValue();
|
---|
823 |
|
---|
824 | if (toTrim) {
|
---|
825 |
|
---|
826 | fBuffer.set(attValue);
|
---|
827 | XMLCh* bufValue = fBuffer.getRawBuffer();
|
---|
828 | XMLString::trim(bufValue);
|
---|
829 |
|
---|
830 | if (!bufValue || !*bufValue) {
|
---|
831 | return XMLUni::fgZeroLenString;
|
---|
832 | }
|
---|
833 |
|
---|
834 | return fStringPool->getValueForId(fStringPool->addOrFind(bufValue));
|
---|
835 | }
|
---|
836 |
|
---|
837 | return attValue;
|
---|
838 | }
|
---|
839 |
|
---|
840 | inline void
|
---|
841 | TraverseSchema::checkForEmptyTargetNamespace(const DOMElement* const elem) {
|
---|
842 |
|
---|
843 | const XMLCh* targetNS = getElementAttValue(elem, SchemaSymbols::fgATT_TARGETNAMESPACE);
|
---|
844 |
|
---|
845 | if (targetNS && !*targetNS) {
|
---|
846 | reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidTargetNSValue);
|
---|
847 | }
|
---|
848 | }
|
---|
849 |
|
---|
850 | inline bool TraverseSchema::isBaseFromAnotherSchema(const XMLCh* const baseURI)
|
---|
851 | {
|
---|
852 | if (!XMLString::equals(baseURI,fTargetNSURIString)
|
---|
853 | && !XMLString::equals(baseURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)
|
---|
854 | && (baseURI && *baseURI)) {
|
---|
855 | //REVISIT, !!!! a hack: for schema that has no
|
---|
856 | //target namespace, e.g. personal-schema.xml
|
---|
857 | return true;
|
---|
858 | }
|
---|
859 |
|
---|
860 | return false;
|
---|
861 | }
|
---|
862 |
|
---|
863 | inline bool TraverseSchema::isAttrOrAttrGroup(const DOMElement* const elem) {
|
---|
864 |
|
---|
865 | const XMLCh* elementName = elem->getLocalName();
|
---|
866 |
|
---|
867 | if (XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTE) ||
|
---|
868 | XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTEGROUP) ||
|
---|
869 | XMLString::equals(elementName, SchemaSymbols::fgELT_ANYATTRIBUTE)) {
|
---|
870 | return true;
|
---|
871 | }
|
---|
872 |
|
---|
873 | return false;
|
---|
874 | }
|
---|
875 |
|
---|
876 | inline const XMLCh* TraverseSchema::genAnonTypeName(const XMLCh* const prefix) {
|
---|
877 |
|
---|
878 | XMLCh anonCountStr[16]; // a count of 15 digits should be enough
|
---|
879 |
|
---|
880 | XMLString::binToText(fAnonXSTypeCount++, anonCountStr, 15, 10, fMemoryManager);
|
---|
881 | fBuffer.set(prefix);
|
---|
882 | fBuffer.append(anonCountStr);
|
---|
883 |
|
---|
884 | return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
|
---|
885 | }
|
---|
886 |
|
---|
887 | inline void TraverseSchema::popCurrentTypeNameStack() {
|
---|
888 |
|
---|
889 | unsigned int stackSize = fCurrentTypeNameStack->size();
|
---|
890 |
|
---|
891 | if (stackSize != 0) {
|
---|
892 | fCurrentTypeNameStack->removeElementAt(stackSize - 1);
|
---|
893 | }
|
---|
894 | }
|
---|
895 |
|
---|
896 | inline void
|
---|
897 | TraverseSchema::copyWildCardData(const SchemaAttDef* const srcWildCard,
|
---|
898 | SchemaAttDef* const destWildCard) {
|
---|
899 |
|
---|
900 | destWildCard->getAttName()->setURI(srcWildCard->getAttName()->getURI());
|
---|
901 | destWildCard->setType(srcWildCard->getType());
|
---|
902 | destWildCard->setDefaultType(srcWildCard->getDefaultType());
|
---|
903 | }
|
---|
904 |
|
---|
905 | inline void TraverseSchema::getRedefineNewTypeName(const XMLCh* const oldTypeName,
|
---|
906 | const int redefineCounter,
|
---|
907 | XMLBuffer& newTypeName) {
|
---|
908 |
|
---|
909 | newTypeName.set(oldTypeName);
|
---|
910 |
|
---|
911 | for (int i=0; i < redefineCounter; i++) {
|
---|
912 | newTypeName.append(SchemaSymbols::fgRedefIdentifier);
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | XERCES_CPP_NAMESPACE_END
|
---|
917 |
|
---|
918 | #endif
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * End of file TraverseSchema.hpp
|
---|
922 | */
|
---|
923 |
|
---|