|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: ContentSpecNode.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 |
|
39 #if !defined(CONTENTSPECNODE_HPP) |
|
40 #define CONTENTSPECNODE_HPP |
|
41 |
|
42 #include <xercesc/framework/XMLElementDecl.hpp> |
|
43 #include <xercesc/framework/MemoryManager.hpp> |
|
44 |
|
45 #include <xercesc/internal/XSerializable.hpp> |
|
46 |
|
47 XERCES_CPP_NAMESPACE_BEGIN |
|
48 |
|
49 class XMLBuffer; |
|
50 class Grammar; |
|
51 |
|
52 |
|
53 class XMLUTIL_EXPORT ContentSpecNode : public XSerializable, public XMemory |
|
54 { |
|
55 public : |
|
56 // ----------------------------------------------------------------------- |
|
57 // Class specific types |
|
58 // ----------------------------------------------------------------------- |
|
59 enum NodeTypes |
|
60 { |
|
61 Leaf = 0 |
|
62 , ZeroOrOne |
|
63 , ZeroOrMore |
|
64 , OneOrMore |
|
65 , Choice |
|
66 , Sequence |
|
67 , Any |
|
68 , Any_Other |
|
69 , Any_NS = 8 |
|
70 , All = 9 |
|
71 , Any_NS_Choice = 20 |
|
72 , ModelGroupSequence = 21 |
|
73 , Any_Lax = 22 |
|
74 , Any_Other_Lax = 23 |
|
75 , Any_NS_Lax = 24 |
|
76 , ModelGroupChoice = 36 |
|
77 , Any_Skip = 38 |
|
78 , Any_Other_Skip = 39 |
|
79 , Any_NS_Skip = 40 |
|
80 |
|
81 , UnknownType = -1 |
|
82 }; |
|
83 |
|
84 |
|
85 // ----------------------------------------------------------------------- |
|
86 // Constructors and Destructor |
|
87 // ----------------------------------------------------------------------- |
|
88 ContentSpecNode(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
89 ContentSpecNode |
|
90 ( |
|
91 QName* const toAdopt |
|
92 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
93 ); |
|
94 ContentSpecNode |
|
95 ( |
|
96 XMLElementDecl* const elemDecl |
|
97 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
98 ); |
|
99 ContentSpecNode |
|
100 ( |
|
101 QName* const toAdopt |
|
102 , const bool copyQName |
|
103 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
104 ); |
|
105 ContentSpecNode |
|
106 ( |
|
107 const NodeTypes type |
|
108 , ContentSpecNode* const firstToAdopt |
|
109 , ContentSpecNode* const secondToAdopt |
|
110 , const bool adoptFirst = true |
|
111 , const bool adoptSecond = true |
|
112 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
113 ); |
|
114 ContentSpecNode(const ContentSpecNode&); |
|
115 ~ContentSpecNode(); |
|
116 |
|
117 // ----------------------------------------------------------------------- |
|
118 // Getter methods |
|
119 // ----------------------------------------------------------------------- |
|
120 QName* getElement(); |
|
121 const QName* getElement() const; |
|
122 XMLElementDecl* getElementDecl(); |
|
123 const XMLElementDecl* getElementDecl() const; |
|
124 ContentSpecNode* getFirst(); |
|
125 const ContentSpecNode* getFirst() const; |
|
126 ContentSpecNode* getSecond(); |
|
127 const ContentSpecNode* getSecond() const; |
|
128 NodeTypes getType() const; |
|
129 ContentSpecNode* orphanFirst(); |
|
130 ContentSpecNode* orphanSecond(); |
|
131 int getMinOccurs() const; |
|
132 int getMaxOccurs() const; |
|
133 bool isFirstAdopted() const; |
|
134 bool isSecondAdopted() const; |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------- |
|
138 // Setter methods |
|
139 // ----------------------------------------------------------------------- |
|
140 void setElement(QName* const toAdopt); |
|
141 void setFirst(ContentSpecNode* const toAdopt); |
|
142 void setSecond(ContentSpecNode* const toAdopt); |
|
143 void setType(const NodeTypes type); |
|
144 void setMinOccurs(int min); |
|
145 void setMaxOccurs(int max); |
|
146 void setAdoptFirst(bool adoptFirst); |
|
147 void setAdoptSecond(bool adoptSecond); |
|
148 |
|
149 |
|
150 // ----------------------------------------------------------------------- |
|
151 // Miscellaneous |
|
152 // ----------------------------------------------------------------------- |
|
153 void formatSpec (XMLBuffer& bufToFill) const; |
|
154 bool hasAllContent(); |
|
155 int getMinTotalRange() const; |
|
156 int getMaxTotalRange() const; |
|
157 |
|
158 /*** |
|
159 * Support for Serialization/De-serialization |
|
160 ***/ |
|
161 DECL_XSERIALIZABLE(ContentSpecNode) |
|
162 |
|
163 private : |
|
164 // ----------------------------------------------------------------------- |
|
165 // Unimplemented constructors and operators |
|
166 // ----------------------------------------------------------------------- |
|
167 ContentSpecNode& operator=(const ContentSpecNode&); |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------- |
|
171 // Private Data Members |
|
172 // |
|
173 // fElement |
|
174 // If the type is Leaf/Any*, then this is the qName of the element. If the URI |
|
175 // is fgPCDataElemId, then its a PCData node. Else, it is zero. |
|
176 // |
|
177 // fFirst |
|
178 // fSecond |
|
179 // The optional first and second nodes. The fType field indicates |
|
180 // which of these are valid. The validaty constraints are: |
|
181 // |
|
182 // Leaf = Neither valid |
|
183 // ZeroOrOne, ZeroOrMore = First |
|
184 // Choice, Sequence, All = First and Second |
|
185 // Any* = Neither valid |
|
186 // |
|
187 // fType |
|
188 // The type of node. This controls how many of the child node fields |
|
189 // are used. |
|
190 // |
|
191 // fAdoptFirst |
|
192 // Indicate if this ContentSpecNode adopts the fFirst, and is responsible |
|
193 // for deleting it. |
|
194 // |
|
195 // fAdoptSecond |
|
196 // Indicate if this ContentSpecNode adopts the fSecond, and is responsible |
|
197 // for deleting it. |
|
198 // |
|
199 // fMinOccurs |
|
200 // Indicate the minimum times that this node can occur |
|
201 // |
|
202 // fMaxOccurs |
|
203 // Indicate the maximum times that this node can occur |
|
204 // -1 (Unbounded), default (1) |
|
205 // ----------------------------------------------------------------------- |
|
206 MemoryManager* fMemoryManager; |
|
207 QName* fElement; |
|
208 XMLElementDecl* fElementDecl; |
|
209 ContentSpecNode* fFirst; |
|
210 ContentSpecNode* fSecond; |
|
211 NodeTypes fType; |
|
212 bool fAdoptFirst; |
|
213 bool fAdoptSecond; |
|
214 int fMinOccurs; |
|
215 int fMaxOccurs; |
|
216 }; |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // ContentSpecNode: Constructors and Destructor |
|
220 // --------------------------------------------------------------------------- |
|
221 inline ContentSpecNode::ContentSpecNode(MemoryManager* const manager) : |
|
222 |
|
223 fMemoryManager(manager) |
|
224 , fElement(0) |
|
225 , fElementDecl(0) |
|
226 , fFirst(0) |
|
227 , fSecond(0) |
|
228 , fType(ContentSpecNode::Leaf) |
|
229 , fAdoptFirst(true) |
|
230 , fAdoptSecond(true) |
|
231 , fMinOccurs(1) |
|
232 , fMaxOccurs(1) |
|
233 { |
|
234 } |
|
235 |
|
236 inline |
|
237 ContentSpecNode::ContentSpecNode(QName* const element, |
|
238 MemoryManager* const manager) : |
|
239 |
|
240 fMemoryManager(manager) |
|
241 , fElement(0) |
|
242 , fElementDecl(0) |
|
243 , fFirst(0) |
|
244 , fSecond(0) |
|
245 , fType(ContentSpecNode::Leaf) |
|
246 , fAdoptFirst(true) |
|
247 , fAdoptSecond(true) |
|
248 , fMinOccurs(1) |
|
249 , fMaxOccurs(1) |
|
250 { |
|
251 if (element) |
|
252 fElement = new (fMemoryManager) QName(*element); |
|
253 } |
|
254 |
|
255 inline |
|
256 ContentSpecNode::ContentSpecNode(XMLElementDecl* const elemDecl, |
|
257 MemoryManager* const manager) : |
|
258 |
|
259 fMemoryManager(manager) |
|
260 , fElement(0) |
|
261 , fElementDecl(elemDecl) |
|
262 , fFirst(0) |
|
263 , fSecond(0) |
|
264 , fType(ContentSpecNode::Leaf) |
|
265 , fAdoptFirst(true) |
|
266 , fAdoptSecond(true) |
|
267 , fMinOccurs(1) |
|
268 , fMaxOccurs(1) |
|
269 { |
|
270 if (elemDecl) |
|
271 fElement = new (manager) QName(*(elemDecl->getElementName())); |
|
272 } |
|
273 |
|
274 inline |
|
275 ContentSpecNode::ContentSpecNode( QName* const element |
|
276 , const bool copyQName |
|
277 , MemoryManager* const manager) : |
|
278 |
|
279 fMemoryManager(manager) |
|
280 , fElement(0) |
|
281 , fElementDecl(0) |
|
282 , fFirst(0) |
|
283 , fSecond(0) |
|
284 , fType(ContentSpecNode::Leaf) |
|
285 , fAdoptFirst(true) |
|
286 , fAdoptSecond(true) |
|
287 , fMinOccurs(1) |
|
288 , fMaxOccurs(1) |
|
289 { |
|
290 if (copyQName) |
|
291 { |
|
292 if (element) |
|
293 fElement = new (fMemoryManager) QName(*element); |
|
294 } |
|
295 else |
|
296 { |
|
297 fElement = element; |
|
298 } |
|
299 } |
|
300 |
|
301 inline |
|
302 ContentSpecNode::ContentSpecNode(const NodeTypes type |
|
303 , ContentSpecNode* const firstAdopt |
|
304 , ContentSpecNode* const secondAdopt |
|
305 , const bool adoptFirst |
|
306 , const bool adoptSecond |
|
307 , MemoryManager* const manager) : |
|
308 |
|
309 fMemoryManager(manager) |
|
310 , fElement(0) |
|
311 , fElementDecl(0) |
|
312 , fFirst(firstAdopt) |
|
313 , fSecond(secondAdopt) |
|
314 , fType(type) |
|
315 , fAdoptFirst(adoptFirst) |
|
316 , fAdoptSecond(adoptSecond) |
|
317 , fMinOccurs(1) |
|
318 , fMaxOccurs(1) |
|
319 { |
|
320 } |
|
321 |
|
322 inline ContentSpecNode::~ContentSpecNode() |
|
323 { |
|
324 // Delete our children, which cause recursive cleanup |
|
325 if (fAdoptFirst) { |
|
326 delete fFirst; |
|
327 } |
|
328 |
|
329 if (fAdoptSecond) { |
|
330 delete fSecond; |
|
331 } |
|
332 |
|
333 delete fElement; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // ContentSpecNode: Getter methods |
|
338 // --------------------------------------------------------------------------- |
|
339 inline QName* ContentSpecNode::getElement() |
|
340 { |
|
341 return fElement; |
|
342 } |
|
343 |
|
344 inline const QName* ContentSpecNode::getElement() const |
|
345 { |
|
346 return fElement; |
|
347 } |
|
348 |
|
349 inline XMLElementDecl* ContentSpecNode::getElementDecl() |
|
350 { |
|
351 return fElementDecl; |
|
352 } |
|
353 |
|
354 inline const XMLElementDecl* ContentSpecNode::getElementDecl() const |
|
355 { |
|
356 return fElementDecl; |
|
357 } |
|
358 |
|
359 inline ContentSpecNode* ContentSpecNode::getFirst() |
|
360 { |
|
361 return fFirst; |
|
362 } |
|
363 |
|
364 inline const ContentSpecNode* ContentSpecNode::getFirst() const |
|
365 { |
|
366 return fFirst; |
|
367 } |
|
368 |
|
369 inline ContentSpecNode* ContentSpecNode::getSecond() |
|
370 { |
|
371 return fSecond; |
|
372 } |
|
373 |
|
374 inline const ContentSpecNode* ContentSpecNode::getSecond() const |
|
375 { |
|
376 return fSecond; |
|
377 } |
|
378 |
|
379 inline ContentSpecNode::NodeTypes ContentSpecNode::getType() const |
|
380 { |
|
381 return fType; |
|
382 } |
|
383 |
|
384 inline ContentSpecNode* ContentSpecNode::orphanFirst() |
|
385 { |
|
386 ContentSpecNode* retNode = fFirst; |
|
387 fFirst = 0; |
|
388 return retNode; |
|
389 } |
|
390 |
|
391 inline ContentSpecNode* ContentSpecNode::orphanSecond() |
|
392 { |
|
393 ContentSpecNode* retNode = fSecond; |
|
394 fSecond = 0; |
|
395 return retNode; |
|
396 } |
|
397 |
|
398 inline int ContentSpecNode::getMinOccurs() const |
|
399 { |
|
400 return fMinOccurs; |
|
401 } |
|
402 |
|
403 inline int ContentSpecNode::getMaxOccurs() const |
|
404 { |
|
405 return fMaxOccurs; |
|
406 } |
|
407 |
|
408 inline bool ContentSpecNode::isFirstAdopted() const |
|
409 { |
|
410 return fAdoptFirst; |
|
411 } |
|
412 |
|
413 inline bool ContentSpecNode::isSecondAdopted() const |
|
414 { |
|
415 return fAdoptSecond; |
|
416 } |
|
417 |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // ContentSpecType: Setter methods |
|
421 // --------------------------------------------------------------------------- |
|
422 inline void ContentSpecNode::setElement(QName* const element) |
|
423 { |
|
424 delete fElement; |
|
425 fElement = 0; |
|
426 if (element) |
|
427 fElement = new (fMemoryManager) QName(*element); |
|
428 } |
|
429 |
|
430 inline void ContentSpecNode::setFirst(ContentSpecNode* const toAdopt) |
|
431 { |
|
432 if (fAdoptFirst) |
|
433 delete fFirst; |
|
434 fFirst = toAdopt; |
|
435 } |
|
436 |
|
437 inline void ContentSpecNode::setSecond(ContentSpecNode* const toAdopt) |
|
438 { |
|
439 if (fAdoptSecond) |
|
440 delete fSecond; |
|
441 fSecond = toAdopt; |
|
442 } |
|
443 |
|
444 inline void ContentSpecNode::setType(const NodeTypes type) |
|
445 { |
|
446 fType = type; |
|
447 } |
|
448 |
|
449 inline void ContentSpecNode::setMinOccurs(int min) |
|
450 { |
|
451 fMinOccurs = min; |
|
452 } |
|
453 |
|
454 inline void ContentSpecNode::setMaxOccurs(int max) |
|
455 { |
|
456 fMaxOccurs = max; |
|
457 } |
|
458 |
|
459 inline void ContentSpecNode::setAdoptFirst(bool newState) |
|
460 { |
|
461 fAdoptFirst = newState; |
|
462 } |
|
463 |
|
464 inline void ContentSpecNode::setAdoptSecond(bool newState) |
|
465 { |
|
466 fAdoptSecond = newState; |
|
467 } |
|
468 |
|
469 // --------------------------------------------------------------------------- |
|
470 // ContentSpecNode: Miscellaneous |
|
471 // --------------------------------------------------------------------------- |
|
472 inline bool ContentSpecNode::hasAllContent() { |
|
473 |
|
474 if (fType == ContentSpecNode::ZeroOrOne) { |
|
475 return (fFirst->getType() == ContentSpecNode::All); |
|
476 } |
|
477 |
|
478 return (fType == ContentSpecNode::All); |
|
479 } |
|
480 |
|
481 XERCES_CPP_NAMESPACE_END |
|
482 |
|
483 #endif |