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: SimpleContentModel.hpp 901107 2010-01-20 08:45:02Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XERCESC_INCLUDE_GUARD_SIMPLECONTENTMODEL_HPP) |
---|
23 | #define XERCESC_INCLUDE_GUARD_SIMPLECONTENTMODEL_HPP |
---|
24 | |
---|
25 | #include <xercesc/framework/XMLContentModel.hpp> |
---|
26 | #include <xercesc/validators/common/ContentSpecNode.hpp> |
---|
27 | |
---|
28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
29 | |
---|
30 | // |
---|
31 | // SimpleContentModel is a derivative of the abstract content model base |
---|
32 | // class that handles a small set of simple content models that are just |
---|
33 | // way overkill to give the DFA treatment. |
---|
34 | // |
---|
35 | // DESCRIPTION: |
---|
36 | // |
---|
37 | // This guy handles the following scenarios: |
---|
38 | // |
---|
39 | // a |
---|
40 | // a? |
---|
41 | // a* |
---|
42 | // a+ |
---|
43 | // a,b |
---|
44 | // a|b |
---|
45 | // |
---|
46 | // These all involve a unary operation with one element type, or a binary |
---|
47 | // operation with two elements. These are very simple and can be checked |
---|
48 | // in a simple way without a DFA and without the overhead of setting up a |
---|
49 | // DFA for such a simple check. |
---|
50 | // |
---|
51 | // NOTE: Pass the XMLElementDecl::fgPCDataElemId value to represent a |
---|
52 | // PCData node. Pass XMLElementDecl::fgInvalidElemId for unused element |
---|
53 | // |
---|
54 | class SimpleContentModel : public XMLContentModel |
---|
55 | { |
---|
56 | public : |
---|
57 | // ----------------------------------------------------------------------- |
---|
58 | // Constructors and Destructor |
---|
59 | // ----------------------------------------------------------------------- |
---|
60 | SimpleContentModel |
---|
61 | ( |
---|
62 | const bool dtd |
---|
63 | , QName* const firstChild |
---|
64 | , QName* const secondChild |
---|
65 | , const ContentSpecNode::NodeTypes cmOp |
---|
66 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
67 | ); |
---|
68 | |
---|
69 | ~SimpleContentModel(); |
---|
70 | |
---|
71 | |
---|
72 | // ----------------------------------------------------------------------- |
---|
73 | // Implementation of the ContentModel virtual interface |
---|
74 | // ----------------------------------------------------------------------- |
---|
75 | |
---|
76 | virtual bool validateContent |
---|
77 | ( |
---|
78 | #ifdef STORE_CHILDREN_INFORMATION_IN_PARSER |
---|
79 | XMLElementDecl ** const children |
---|
80 | #else |
---|
81 | QName** const children |
---|
82 | #endif |
---|
83 | , XMLSize_t childCount |
---|
84 | , XMLSize_t* indexFailingChild |
---|
85 | , MemoryManager* const manager |
---|
86 | ) const; |
---|
87 | |
---|
88 | virtual bool validateContentSpecial |
---|
89 | ( |
---|
90 | #ifdef STORE_CHILDREN_INFORMATION_IN_PARSER |
---|
91 | XMLElementDecl ** const children |
---|
92 | #else |
---|
93 | QName** const children |
---|
94 | #endif |
---|
95 | , XMLSize_t childCount |
---|
96 | , GrammarResolver* const pGrammarResolver |
---|
97 | , XMLNamespaceResolver* const pUriResolver |
---|
98 | , XMLSize_t* indexFailingChild |
---|
99 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
100 | ) const; |
---|
101 | |
---|
102 | virtual void checkUniqueParticleAttribution |
---|
103 | ( |
---|
104 | SchemaGrammar* const pGrammar |
---|
105 | , GrammarResolver* const pGrammarResolver |
---|
106 | , XMLNamespaceResolver* const pUriResolver |
---|
107 | , XMLValidator* const pValidator |
---|
108 | , unsigned int* const pContentSpecOrgURI |
---|
109 | , const XMLCh* pComplexTypeName = 0 |
---|
110 | ); |
---|
111 | |
---|
112 | /** @@@ DEPRECATED @@@ **/ |
---|
113 | virtual bool validateContent |
---|
114 | ( |
---|
115 | QName** const children |
---|
116 | , XMLSize_t childCount |
---|
117 | , unsigned int emptyNamespaceId |
---|
118 | , XMLSize_t* indexFailingChild |
---|
119 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
120 | ) const; |
---|
121 | |
---|
122 | /** @@@ DEPRECATED @@@ **/ |
---|
123 | virtual bool validateContentSpecial |
---|
124 | ( |
---|
125 | QName** const children |
---|
126 | , XMLSize_t childCount |
---|
127 | , unsigned int emptyNamespaceId |
---|
128 | , GrammarResolver* const pGrammarResolver |
---|
129 | , XMLStringPool* const pStringPool |
---|
130 | , XMLSize_t* indexFailingChild |
---|
131 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
132 | ) const; |
---|
133 | |
---|
134 | /** @@@ DEPRECATED @@@ **/ |
---|
135 | virtual void checkUniqueParticleAttribution |
---|
136 | ( |
---|
137 | SchemaGrammar* const pGrammar |
---|
138 | , GrammarResolver* const pGrammarResolver |
---|
139 | , XMLStringPool* const pStringPool |
---|
140 | , XMLValidator* const pValidator |
---|
141 | , unsigned int* const pContentSpecOrgURI |
---|
142 | , const XMLCh* pComplexTypeName = 0 |
---|
143 | ); |
---|
144 | |
---|
145 | virtual ContentLeafNameTypeVector *getContentLeafNameTypeVector() const; |
---|
146 | |
---|
147 | virtual unsigned int getNextState(unsigned int currentState, |
---|
148 | XMLSize_t elementIndex) const; |
---|
149 | |
---|
150 | virtual bool handleRepetitions( const QName* const curElem, |
---|
151 | unsigned int curState, |
---|
152 | unsigned int currentLoop, |
---|
153 | unsigned int& nextState, |
---|
154 | unsigned int& nextLoop, |
---|
155 | XMLSize_t elementIndex, |
---|
156 | SubstitutionGroupComparator * comparator) const; |
---|
157 | |
---|
158 | #ifdef PRINT_DEBUG_MESSAGE |
---|
159 | virtual void debug_out(std::ostream & out) const |
---|
160 | { |
---|
161 | out << "(SimpleContentModel: " |
---|
162 | << fFirstChild |
---|
163 | << ',' << fSecondChild |
---|
164 | << ',' << fOp |
---|
165 | << ',' << fDTD |
---|
166 | << ')'; |
---|
167 | } |
---|
168 | #endif |
---|
169 | |
---|
170 | private : |
---|
171 | // ----------------------------------------------------------------------- |
---|
172 | // Unimplemented constructors and operators |
---|
173 | // ----------------------------------------------------------------------- |
---|
174 | SimpleContentModel(); |
---|
175 | SimpleContentModel(const SimpleContentModel&); |
---|
176 | SimpleContentModel& operator=(const SimpleContentModel&); |
---|
177 | |
---|
178 | |
---|
179 | // ----------------------------------------------------------------------- |
---|
180 | // Private data members |
---|
181 | // |
---|
182 | // fFirstChild |
---|
183 | // fSecondChild |
---|
184 | // The first (and optional second) child node. The |
---|
185 | // operation code tells us whether the second child is used or not. |
---|
186 | // |
---|
187 | // fOp |
---|
188 | // The operation that this object represents. Since this class only |
---|
189 | // does simple contents, there is only ever a single operation |
---|
190 | // involved (i.e. the children of the operation are always one or |
---|
191 | // two leafs.) |
---|
192 | // |
---|
193 | // fDTD |
---|
194 | // Boolean to allow DTDs to validate even with namespace support. */ |
---|
195 | // |
---|
196 | // ----------------------------------------------------------------------- |
---|
197 | QName* fFirstChild; |
---|
198 | QName* fSecondChild; |
---|
199 | ContentSpecNode::NodeTypes fOp; |
---|
200 | bool fDTD; |
---|
201 | MemoryManager* const fMemoryManager; |
---|
202 | }; |
---|
203 | |
---|
204 | |
---|
205 | // --------------------------------------------------------------------------- |
---|
206 | // SimpleContentModel: Constructors and Destructor |
---|
207 | // --------------------------------------------------------------------------- |
---|
208 | inline SimpleContentModel::SimpleContentModel |
---|
209 | ( |
---|
210 | const bool dtd |
---|
211 | , QName* const firstChild |
---|
212 | , QName* const secondChild |
---|
213 | , const ContentSpecNode::NodeTypes cmOp |
---|
214 | , MemoryManager* const manager |
---|
215 | ) |
---|
216 | : fFirstChild(0) |
---|
217 | , fSecondChild(0) |
---|
218 | , fOp(cmOp) |
---|
219 | , fDTD(dtd) |
---|
220 | , fMemoryManager(manager) |
---|
221 | { |
---|
222 | if (firstChild) |
---|
223 | fFirstChild = new (manager) QName(*firstChild); |
---|
224 | else |
---|
225 | fFirstChild = new (manager) QName(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId, manager); |
---|
226 | |
---|
227 | if (secondChild) |
---|
228 | fSecondChild = new (manager) QName(*secondChild); |
---|
229 | else |
---|
230 | fSecondChild = new (manager) QName(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId, manager); |
---|
231 | } |
---|
232 | |
---|
233 | inline SimpleContentModel::~SimpleContentModel() |
---|
234 | { |
---|
235 | delete fFirstChild; |
---|
236 | delete fSecondChild; |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | // --------------------------------------------------------------------------- |
---|
241 | // SimpleContentModel: Virtual methods |
---|
242 | // --------------------------------------------------------------------------- |
---|
243 | inline unsigned int |
---|
244 | SimpleContentModel::getNextState(unsigned int, |
---|
245 | XMLSize_t) const { |
---|
246 | |
---|
247 | return XMLContentModel::gInvalidTrans; |
---|
248 | } |
---|
249 | |
---|
250 | inline bool |
---|
251 | SimpleContentModel::handleRepetitions( const QName* const /*curElem*/, |
---|
252 | unsigned int /*curState*/, |
---|
253 | unsigned int /*currentLoop*/, |
---|
254 | unsigned int& /*nextState*/, |
---|
255 | unsigned int& /*nextLoop*/, |
---|
256 | XMLSize_t /*elementIndex*/, |
---|
257 | SubstitutionGroupComparator * /*comparator*/) const |
---|
258 | { |
---|
259 | return true; |
---|
260 | } |
---|
261 | |
---|
262 | XERCES_CPP_NAMESPACE_END |
---|
263 | |
---|
264 | #endif |
---|