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: SchemaInfo.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(SCHEMAINFO_HPP) |
---|
23 | #define SCHEMAINFO_HPP |
---|
24 | |
---|
25 | |
---|
26 | /** When in a <redefine>, type definitions being used (and indeed |
---|
27 | * refs to <group>'s and <attributeGroup>'s) may refer to info |
---|
28 | * items either in the schema being redefined, in the <redefine>, |
---|
29 | * or else in the schema doing the redefining. Because of this |
---|
30 | * latter we have to be prepared sometimes to look for our type |
---|
31 | * definitions outside the schema stored in fSchemaRootElement. |
---|
32 | * This simple class does this; it's just a linked list that |
---|
33 | * lets us look at the <schema>'s on the queue; note also that this |
---|
34 | * should provide us with a mechanism to handle nested <redefine>'s. |
---|
35 | * It's also a handy way of saving schema info when importing/including. |
---|
36 | */ |
---|
37 | |
---|
38 | // --------------------------------------------------------------------------- |
---|
39 | // Includes |
---|
40 | // --------------------------------------------------------------------------- |
---|
41 | #include <xercesc/dom/DOMElement.hpp> |
---|
42 | #include <xercesc/util/RefVectorOf.hpp> |
---|
43 | #include <xercesc/util/ValueVectorOf.hpp> |
---|
44 | #include <xercesc/util/RefHashTableOf.hpp> |
---|
45 | |
---|
46 | XERCES_CPP_NAMESPACE_BEGIN |
---|
47 | |
---|
48 | // --------------------------------------------------------------------------- |
---|
49 | // Forward Declarations |
---|
50 | // --------------------------------------------------------------------------- |
---|
51 | class ValidationContext; |
---|
52 | |
---|
53 | |
---|
54 | class VALIDATORS_EXPORT SchemaInfo : public XMemory |
---|
55 | { |
---|
56 | public: |
---|
57 | |
---|
58 | enum ListType { |
---|
59 | // Redefine is treated as an include |
---|
60 | IMPORT = 1, |
---|
61 | INCLUDE = 2 |
---|
62 | }; |
---|
63 | |
---|
64 | enum { |
---|
65 | C_ComplexType, |
---|
66 | C_SimpleType, |
---|
67 | C_Group, |
---|
68 | C_Attribute, |
---|
69 | C_AttributeGroup, |
---|
70 | C_Element, |
---|
71 | C_Notation, |
---|
72 | |
---|
73 | C_Count |
---|
74 | }; |
---|
75 | |
---|
76 | // ----------------------------------------------------------------------- |
---|
77 | // Constructor/Destructor |
---|
78 | // ----------------------------------------------------------------------- |
---|
79 | SchemaInfo(const unsigned short fElemAttrDefaultQualified, |
---|
80 | const int blockDefault, |
---|
81 | const int finalDefault, |
---|
82 | const int targetNSURI, |
---|
83 | const int scopeCount, |
---|
84 | const unsigned int namespaceScopeLevel, |
---|
85 | XMLCh* const schemaURL, |
---|
86 | const XMLCh* const targetNSURIString, |
---|
87 | const DOMElement* const root, |
---|
88 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
89 | ~SchemaInfo(); |
---|
90 | |
---|
91 | |
---|
92 | // ----------------------------------------------------------------------- |
---|
93 | // Getter methods |
---|
94 | // ----------------------------------------------------------------------- |
---|
95 | XMLCh* getCurrentSchemaURL() const; |
---|
96 | const XMLCh* const getTargetNSURIString() const; |
---|
97 | const DOMElement* getRoot() const; |
---|
98 | bool getProcessed() const; |
---|
99 | int getBlockDefault() const; |
---|
100 | int getFinalDefault() const; |
---|
101 | int getTargetNSURI() const; |
---|
102 | int getScopeCount() const; |
---|
103 | unsigned int getNamespaceScopeLevel() const; |
---|
104 | unsigned short getElemAttrDefaultQualified() const; |
---|
105 | BaseRefVectorEnumerator<SchemaInfo> getImportingListEnumerator() const; |
---|
106 | ValueVectorOf<const DOMElement*>* getRecursingAnonTypes() const; |
---|
107 | ValueVectorOf<const XMLCh*>* getRecursingTypeNames() const; |
---|
108 | ValueVectorOf<DOMNode*>* getNonXSAttList() const; |
---|
109 | ValidationContext* getValidationContext() const; |
---|
110 | |
---|
111 | // ----------------------------------------------------------------------- |
---|
112 | // Setter methods |
---|
113 | // ----------------------------------------------------------------------- |
---|
114 | void setProcessed(const bool aValue = true); |
---|
115 | void setScopeCount(const int aValue); |
---|
116 | void setBlockDefault(const int aValue); |
---|
117 | void setFinalDefault(const int aValue); |
---|
118 | void setElemAttrDefaultQualified(const unsigned short aValue); |
---|
119 | |
---|
120 | // ----------------------------------------------------------------------- |
---|
121 | // Access methods |
---|
122 | // ----------------------------------------------------------------------- |
---|
123 | void addSchemaInfo(SchemaInfo* const toAdd, const ListType aListType); |
---|
124 | bool containsInfo(const SchemaInfo* const toCheck, const ListType aListType) const; |
---|
125 | SchemaInfo* getImportInfo(const unsigned int namespaceURI) const; |
---|
126 | DOMElement* getTopLevelComponent(const unsigned short compCategory, |
---|
127 | const XMLCh* const compName, |
---|
128 | const XMLCh* const name); |
---|
129 | DOMElement* getTopLevelComponent(const unsigned short compCategory, |
---|
130 | const XMLCh* const compName, |
---|
131 | const XMLCh* const name, |
---|
132 | SchemaInfo** enclosingSchema); |
---|
133 | void updateImportingInfo(SchemaInfo* const importingInfo); |
---|
134 | bool circularImportExist(const unsigned int nameSpaceURI); |
---|
135 | bool isFailedRedefine(const DOMElement* const anElem); |
---|
136 | void addFailedRedefine(const DOMElement* const anElem); |
---|
137 | bool isImportingNS(const int namespaceURI); |
---|
138 | void addImportedNS(const int namespaceURI); |
---|
139 | void addRecursingType(const DOMElement* const elem, const XMLCh* const name); |
---|
140 | |
---|
141 | private: |
---|
142 | // ----------------------------------------------------------------------- |
---|
143 | // Unimplemented constructors and operators |
---|
144 | // ----------------------------------------------------------------------- |
---|
145 | SchemaInfo(const SchemaInfo&); |
---|
146 | SchemaInfo& operator=(const SchemaInfo&); |
---|
147 | |
---|
148 | // ----------------------------------------------------------------------- |
---|
149 | // Private helper methods |
---|
150 | // ----------------------------------------------------------------------- |
---|
151 | void clearTopLevelComponents(); |
---|
152 | |
---|
153 | // ----------------------------------------------------------------------- |
---|
154 | // Private data members |
---|
155 | // ----------------------------------------------------------------------- |
---|
156 | bool fAdoptInclude; |
---|
157 | bool fProcessed; |
---|
158 | unsigned short fElemAttrDefaultQualified; |
---|
159 | int fBlockDefault; |
---|
160 | int fFinalDefault; |
---|
161 | int fTargetNSURI; |
---|
162 | int fScopeCount; |
---|
163 | unsigned int fNamespaceScopeLevel; |
---|
164 | XMLCh* fCurrentSchemaURL; |
---|
165 | const XMLCh* fTargetNSURIString; |
---|
166 | const DOMElement* fSchemaRootElement; |
---|
167 | RefVectorOf<SchemaInfo>* fIncludeInfoList; |
---|
168 | RefVectorOf<SchemaInfo>* fImportedInfoList; |
---|
169 | RefVectorOf<SchemaInfo>* fImportingInfoList; |
---|
170 | ValueVectorOf<const DOMElement*>* fFailedRedefineList; |
---|
171 | ValueVectorOf<int>* fImportedNSList; |
---|
172 | ValueVectorOf<const DOMElement*>* fRecursingAnonTypes; |
---|
173 | ValueVectorOf<const XMLCh*>* fRecursingTypeNames; |
---|
174 | RefHashTableOf<DOMElement>* fTopLevelComponents[C_Count]; |
---|
175 | DOMElement* fLastTopLevelComponent[C_Count]; |
---|
176 | ValueVectorOf<DOMNode*>* fNonXSAttList; |
---|
177 | ValidationContext* fValidationContext; |
---|
178 | MemoryManager* fMemoryManager; |
---|
179 | }; |
---|
180 | |
---|
181 | // --------------------------------------------------------------------------- |
---|
182 | // SchemaInfo: Getter methods |
---|
183 | // --------------------------------------------------------------------------- |
---|
184 | inline unsigned short SchemaInfo::getElemAttrDefaultQualified() const { |
---|
185 | |
---|
186 | return fElemAttrDefaultQualified; |
---|
187 | } |
---|
188 | |
---|
189 | inline bool SchemaInfo::getProcessed() const { |
---|
190 | |
---|
191 | return fProcessed; |
---|
192 | } |
---|
193 | |
---|
194 | inline int SchemaInfo::getBlockDefault() const { |
---|
195 | |
---|
196 | return fBlockDefault; |
---|
197 | } |
---|
198 | |
---|
199 | inline int SchemaInfo::getFinalDefault() const { |
---|
200 | |
---|
201 | return fFinalDefault; |
---|
202 | } |
---|
203 | |
---|
204 | inline unsigned int SchemaInfo::getNamespaceScopeLevel() const { |
---|
205 | return fNamespaceScopeLevel; |
---|
206 | } |
---|
207 | |
---|
208 | inline XMLCh* SchemaInfo::getCurrentSchemaURL() const { |
---|
209 | |
---|
210 | return fCurrentSchemaURL; |
---|
211 | } |
---|
212 | |
---|
213 | inline const XMLCh* const SchemaInfo::getTargetNSURIString() const { |
---|
214 | |
---|
215 | return fTargetNSURIString; |
---|
216 | } |
---|
217 | |
---|
218 | inline const DOMElement* SchemaInfo::getRoot() const { |
---|
219 | |
---|
220 | return fSchemaRootElement; |
---|
221 | } |
---|
222 | |
---|
223 | inline int SchemaInfo::getTargetNSURI() const { |
---|
224 | |
---|
225 | return fTargetNSURI; |
---|
226 | } |
---|
227 | |
---|
228 | inline int SchemaInfo::getScopeCount() const { |
---|
229 | |
---|
230 | return fScopeCount; |
---|
231 | } |
---|
232 | |
---|
233 | inline BaseRefVectorEnumerator<SchemaInfo> |
---|
234 | SchemaInfo::getImportingListEnumerator() const { |
---|
235 | |
---|
236 | return BaseRefVectorEnumerator<SchemaInfo>(fImportingInfoList); |
---|
237 | } |
---|
238 | |
---|
239 | inline ValueVectorOf<const DOMElement*>* |
---|
240 | SchemaInfo::getRecursingAnonTypes() const { |
---|
241 | |
---|
242 | return fRecursingAnonTypes; |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | inline ValueVectorOf<const XMLCh*>* |
---|
247 | SchemaInfo::getRecursingTypeNames() const { |
---|
248 | |
---|
249 | return fRecursingTypeNames; |
---|
250 | } |
---|
251 | |
---|
252 | inline ValueVectorOf<DOMNode*>* SchemaInfo::getNonXSAttList() const |
---|
253 | { |
---|
254 | return fNonXSAttList; |
---|
255 | } |
---|
256 | |
---|
257 | // --------------------------------------------------------------------------- |
---|
258 | // Setter methods |
---|
259 | // --------------------------------------------------------------------------- |
---|
260 | inline void SchemaInfo::setScopeCount(const int aValue) { |
---|
261 | |
---|
262 | fScopeCount = aValue; |
---|
263 | } |
---|
264 | |
---|
265 | inline void SchemaInfo::setBlockDefault(const int aValue) { |
---|
266 | |
---|
267 | fBlockDefault = aValue; |
---|
268 | } |
---|
269 | |
---|
270 | inline void SchemaInfo::setFinalDefault(const int aValue) { |
---|
271 | |
---|
272 | fFinalDefault = aValue; |
---|
273 | } |
---|
274 | |
---|
275 | inline void SchemaInfo::setElemAttrDefaultQualified(const unsigned short aValue) { |
---|
276 | |
---|
277 | fElemAttrDefaultQualified = aValue; |
---|
278 | } |
---|
279 | |
---|
280 | inline void SchemaInfo::setProcessed(const bool aValue) { |
---|
281 | |
---|
282 | fProcessed = aValue; |
---|
283 | |
---|
284 | /* if (fProcessed && fIncludeInfoList) { |
---|
285 | |
---|
286 | unsigned int includeListLen = fIncludeInfoList->size()); |
---|
287 | for (unsigned int i = 0; i < includeListLen; i++) { |
---|
288 | fIncludeInfoList->elementAt(i)->clearTopLevelComponents(); |
---|
289 | } |
---|
290 | }*/ |
---|
291 | } |
---|
292 | |
---|
293 | // --------------------------------------------------------------------------- |
---|
294 | // SchemaInfo: Access methods |
---|
295 | // --------------------------------------------------------------------------- |
---|
296 | inline void SchemaInfo::addImportedNS(const int namespaceURI) { |
---|
297 | |
---|
298 | if (!fImportedNSList) { |
---|
299 | fImportedNSList = new (fMemoryManager) ValueVectorOf<int>(4, fMemoryManager); |
---|
300 | } |
---|
301 | |
---|
302 | if (!fImportedNSList->containsElement(namespaceURI)) |
---|
303 | fImportedNSList->addElement(namespaceURI); |
---|
304 | } |
---|
305 | |
---|
306 | inline void SchemaInfo::addSchemaInfo(SchemaInfo* const toAdd, |
---|
307 | const ListType aListType) { |
---|
308 | |
---|
309 | if (aListType == IMPORT) { |
---|
310 | |
---|
311 | if (!fImportedInfoList) |
---|
312 | fImportedInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager); |
---|
313 | |
---|
314 | if (!fImportedInfoList->containsElement(toAdd)) { |
---|
315 | |
---|
316 | fImportedInfoList->addElement(toAdd); |
---|
317 | addImportedNS(toAdd->getTargetNSURI()); |
---|
318 | toAdd->updateImportingInfo(this); |
---|
319 | } |
---|
320 | } |
---|
321 | else { |
---|
322 | |
---|
323 | if (!fIncludeInfoList) { |
---|
324 | |
---|
325 | fIncludeInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(8, false, fMemoryManager); |
---|
326 | fAdoptInclude = true; |
---|
327 | } |
---|
328 | |
---|
329 | if (!fIncludeInfoList->containsElement(toAdd)) { |
---|
330 | |
---|
331 | fIncludeInfoList->addElement(toAdd); |
---|
332 | toAdd->fIncludeInfoList = fIncludeInfoList; |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | inline SchemaInfo* SchemaInfo::getImportInfo(const unsigned int namespaceURI) const { |
---|
338 | |
---|
339 | unsigned int importSize = (fImportedInfoList) ? fImportedInfoList->size() : 0; |
---|
340 | SchemaInfo* currInfo = 0; |
---|
341 | |
---|
342 | for (unsigned int i=0; i < importSize; i++) { |
---|
343 | |
---|
344 | currInfo = fImportedInfoList->elementAt(i); |
---|
345 | |
---|
346 | if (currInfo->getTargetNSURI() == (int) namespaceURI) |
---|
347 | break; |
---|
348 | } |
---|
349 | |
---|
350 | return currInfo; |
---|
351 | } |
---|
352 | |
---|
353 | inline ValidationContext* SchemaInfo::getValidationContext() const { |
---|
354 | |
---|
355 | return fValidationContext; |
---|
356 | } |
---|
357 | |
---|
358 | inline bool SchemaInfo::containsInfo(const SchemaInfo* const toCheck, |
---|
359 | const ListType aListType) const { |
---|
360 | |
---|
361 | if ((aListType == INCLUDE) && fIncludeInfoList) { |
---|
362 | return fIncludeInfoList->containsElement(toCheck); |
---|
363 | } |
---|
364 | else if ((aListType == IMPORT) && fImportedInfoList) { |
---|
365 | return fImportedInfoList->containsElement(toCheck); |
---|
366 | } |
---|
367 | |
---|
368 | return false; |
---|
369 | } |
---|
370 | |
---|
371 | inline bool SchemaInfo::circularImportExist(const unsigned int namespaceURI) { |
---|
372 | |
---|
373 | unsigned int importSize = fImportingInfoList->size(); |
---|
374 | |
---|
375 | for (unsigned int i=0; i < importSize; i++) { |
---|
376 | if (fImportingInfoList->elementAt(i)->getTargetNSURI() == (int) namespaceURI) { |
---|
377 | return true; |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | return false; |
---|
382 | } |
---|
383 | |
---|
384 | inline bool SchemaInfo::isFailedRedefine(const DOMElement* const anElem) { |
---|
385 | |
---|
386 | if (fFailedRedefineList) |
---|
387 | return (fFailedRedefineList->containsElement(anElem)); |
---|
388 | |
---|
389 | return false; |
---|
390 | } |
---|
391 | |
---|
392 | inline void SchemaInfo::addFailedRedefine(const DOMElement* const anElem) { |
---|
393 | |
---|
394 | if (!fFailedRedefineList) { |
---|
395 | fFailedRedefineList = new (fMemoryManager) ValueVectorOf<const DOMElement*>(4, fMemoryManager); |
---|
396 | } |
---|
397 | |
---|
398 | fFailedRedefineList->addElement(anElem); |
---|
399 | } |
---|
400 | |
---|
401 | inline bool SchemaInfo::isImportingNS(const int namespaceURI) { |
---|
402 | |
---|
403 | if (!fImportedNSList) |
---|
404 | return false; |
---|
405 | |
---|
406 | return (fImportedNSList->containsElement(namespaceURI)); |
---|
407 | } |
---|
408 | |
---|
409 | inline void SchemaInfo::addRecursingType(const DOMElement* const elem, |
---|
410 | const XMLCh* const name) { |
---|
411 | |
---|
412 | if (!fRecursingAnonTypes) { |
---|
413 | fRecursingAnonTypes = new (fMemoryManager) ValueVectorOf<const DOMElement*>(8, fMemoryManager); |
---|
414 | fRecursingTypeNames = new (fMemoryManager) ValueVectorOf<const XMLCh*>(8, fMemoryManager); |
---|
415 | } |
---|
416 | |
---|
417 | fRecursingAnonTypes->addElement(elem); |
---|
418 | fRecursingTypeNames->addElement(name); |
---|
419 | } |
---|
420 | |
---|
421 | inline void SchemaInfo::clearTopLevelComponents() { |
---|
422 | |
---|
423 | for (unsigned int i = 0; i < C_Count; i++) { |
---|
424 | |
---|
425 | delete fTopLevelComponents[i]; |
---|
426 | fTopLevelComponents[i] = 0; |
---|
427 | fLastTopLevelComponent[i] = 0; |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | XERCES_CPP_NAMESPACE_END |
---|
432 | |
---|
433 | #endif |
---|
434 | |
---|
435 | /** |
---|
436 | * End of file SchemaInfo.hpp |
---|
437 | */ |
---|
438 | |
---|