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: UnionDatatypeValidator.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(UNION_DATATYPEVALIDATOR_HPP) |
---|
23 | #define UNION_DATATYPEVALIDATOR_HPP |
---|
24 | |
---|
25 | #include <xercesc/validators/datatype/DatatypeValidator.hpp> |
---|
26 | |
---|
27 | XERCES_CPP_NAMESPACE_BEGIN |
---|
28 | |
---|
29 | class VALIDATORS_EXPORT UnionDatatypeValidator : public DatatypeValidator |
---|
30 | { |
---|
31 | public: |
---|
32 | |
---|
33 | // ----------------------------------------------------------------------- |
---|
34 | // Public ctor/dtor |
---|
35 | // ----------------------------------------------------------------------- |
---|
36 | /** @name Constructors and Destructor. */ |
---|
37 | //@{ |
---|
38 | |
---|
39 | UnionDatatypeValidator |
---|
40 | ( |
---|
41 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
42 | ); |
---|
43 | |
---|
44 | // |
---|
45 | // constructor for native Union datatype validator |
---|
46 | // <simpleType name="nativeUnion"> |
---|
47 | // <union memberTypes="member1 member2 ..."> |
---|
48 | // </simpleType> |
---|
49 | // |
---|
50 | UnionDatatypeValidator |
---|
51 | ( |
---|
52 | RefVectorOf<DatatypeValidator>* const memberTypeValidators |
---|
53 | , const int finalSet |
---|
54 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
55 | ); |
---|
56 | |
---|
57 | // |
---|
58 | // constructor for derived Union datatype validator |
---|
59 | // <simpleType name="derivedUnion"> |
---|
60 | // <restriction base="nativeUnion"> |
---|
61 | // <pattern value="patter_value"/> |
---|
62 | // <enumeration value="enum_value"/> |
---|
63 | // </restriction> |
---|
64 | // </simpleType> |
---|
65 | // |
---|
66 | UnionDatatypeValidator |
---|
67 | ( |
---|
68 | DatatypeValidator* const baseValidator |
---|
69 | , RefHashTableOf<KVStringPair>* const facets |
---|
70 | , RefArrayVectorOf<XMLCh>* const enums |
---|
71 | , const int finalSet |
---|
72 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
73 | , RefVectorOf<DatatypeValidator>* const memberTypeValidators = 0 |
---|
74 | , const bool memberTypesInherited = true |
---|
75 | ); |
---|
76 | |
---|
77 | virtual ~UnionDatatypeValidator(); |
---|
78 | |
---|
79 | //@} |
---|
80 | |
---|
81 | virtual const RefArrayVectorOf<XMLCh>* getEnumString() const; |
---|
82 | |
---|
83 | // ----------------------------------------------------------------------- |
---|
84 | // Getter methods |
---|
85 | // ----------------------------------------------------------------------- |
---|
86 | /** @name Getter Functions */ |
---|
87 | //@{ |
---|
88 | /** |
---|
89 | * Returns whether the type is atomic or not |
---|
90 | */ |
---|
91 | virtual bool isAtomic() const; |
---|
92 | |
---|
93 | virtual const XMLCh* getCanonicalRepresentation |
---|
94 | ( |
---|
95 | const XMLCh* const rawData |
---|
96 | , MemoryManager* const memMgr = 0 |
---|
97 | , bool toValidate = false |
---|
98 | ) const; |
---|
99 | |
---|
100 | //@} |
---|
101 | |
---|
102 | // ----------------------------------------------------------------------- |
---|
103 | // Validation methods |
---|
104 | // ----------------------------------------------------------------------- |
---|
105 | /** @name Validation Function */ |
---|
106 | //@{ |
---|
107 | |
---|
108 | /** |
---|
109 | * validate that a string matches the boolean datatype |
---|
110 | * @param content A string containing the content to be validated |
---|
111 | * |
---|
112 | * @exception throws InvalidDatatypeException if the content is |
---|
113 | * is not valid. |
---|
114 | */ |
---|
115 | |
---|
116 | virtual void validate |
---|
117 | ( |
---|
118 | const XMLCh* const content |
---|
119 | , ValidationContext* const context = 0 |
---|
120 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
121 | ); |
---|
122 | |
---|
123 | /** |
---|
124 | * Checks whether a given type can be used as a substitute |
---|
125 | * |
---|
126 | * @param toCheck A datatype validator of the type to be used as a |
---|
127 | * substitute |
---|
128 | * |
---|
129 | * To be redefined in UnionDatatypeValidator |
---|
130 | */ |
---|
131 | |
---|
132 | virtual bool isSubstitutableBy(const DatatypeValidator* const toCheck); |
---|
133 | |
---|
134 | //@} |
---|
135 | |
---|
136 | // ----------------------------------------------------------------------- |
---|
137 | // Compare methods |
---|
138 | // ----------------------------------------------------------------------- |
---|
139 | /** @name Compare Function */ |
---|
140 | //@{ |
---|
141 | |
---|
142 | /** |
---|
143 | * Compare two boolean data types |
---|
144 | * |
---|
145 | * @param content1 |
---|
146 | * @param content2 |
---|
147 | * @return |
---|
148 | */ |
---|
149 | int compare(const XMLCh* const, const XMLCh* const |
---|
150 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
151 | ); |
---|
152 | |
---|
153 | //@} |
---|
154 | |
---|
155 | /** |
---|
156 | * Returns an instance of the base datatype validator class |
---|
157 | * Used by the DatatypeValidatorFactory. |
---|
158 | */ |
---|
159 | virtual DatatypeValidator* newInstance |
---|
160 | ( |
---|
161 | RefHashTableOf<KVStringPair>* const facets |
---|
162 | , RefArrayVectorOf<XMLCh>* const enums |
---|
163 | , const int finalSet |
---|
164 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
165 | ); |
---|
166 | |
---|
167 | /*** |
---|
168 | * Support for Serialization/De-serialization |
---|
169 | ***/ |
---|
170 | DECL_XSERIALIZABLE(UnionDatatypeValidator) |
---|
171 | |
---|
172 | |
---|
173 | RefVectorOf<DatatypeValidator>* getMemberTypeValidators() const; |
---|
174 | |
---|
175 | |
---|
176 | /** |
---|
177 | * Returns the type name that was actually used to validate the last time validate was called |
---|
178 | * note - this does not mean that it fully validated sucessfully |
---|
179 | * @deprecated |
---|
180 | **/ |
---|
181 | const XMLCh* getMemberTypeName() const; |
---|
182 | |
---|
183 | /** |
---|
184 | * Returns the type uri that was actually used to validate the last time validate was called |
---|
185 | * note - this does not mean that it fully validated sucessfully |
---|
186 | * @deprecated |
---|
187 | **/ |
---|
188 | const XMLCh* getMemberTypeUri() const; |
---|
189 | |
---|
190 | /** |
---|
191 | * Returns true if the type that was actually used to validate the last time validate was called |
---|
192 | * is anonymous |
---|
193 | * @deprecated |
---|
194 | */ |
---|
195 | bool getMemberTypeAnonymous() const; |
---|
196 | |
---|
197 | |
---|
198 | /** |
---|
199 | * Returns the member DatatypeValidator used to validate the content the last time validate |
---|
200 | * was called |
---|
201 | * @deprecated |
---|
202 | */ |
---|
203 | const DatatypeValidator* getMemberTypeValidator() const; |
---|
204 | |
---|
205 | /** |
---|
206 | * Called inbetween uses of this validator to reset PSVI information |
---|
207 | */ |
---|
208 | void reset(); |
---|
209 | |
---|
210 | private: |
---|
211 | // ----------------------------------------------------------------------- |
---|
212 | // Unimplemented constructors and operators |
---|
213 | // ----------------------------------------------------------------------- |
---|
214 | UnionDatatypeValidator(const UnionDatatypeValidator&); |
---|
215 | UnionDatatypeValidator& operator=(const UnionDatatypeValidator&); |
---|
216 | |
---|
217 | virtual void checkContent(const XMLCh* const content |
---|
218 | , ValidationContext* const context |
---|
219 | , bool asBase |
---|
220 | , MemoryManager* const manager); |
---|
221 | |
---|
222 | void init(DatatypeValidator* const baseValidator |
---|
223 | , RefHashTableOf<KVStringPair>* const facets |
---|
224 | , RefArrayVectorOf<XMLCh>* const enums |
---|
225 | , MemoryManager* const manager); |
---|
226 | |
---|
227 | void cleanUp(); |
---|
228 | |
---|
229 | RefArrayVectorOf<XMLCh>* getEnumeration() const; |
---|
230 | |
---|
231 | void setEnumeration(RefArrayVectorOf<XMLCh>*, bool); |
---|
232 | |
---|
233 | |
---|
234 | // ----------------------------------------------------------------------- |
---|
235 | // Private data members |
---|
236 | // |
---|
237 | // fEnumeration |
---|
238 | // we own it (or not, depending on state of fEnumerationInherited). |
---|
239 | // |
---|
240 | // fMemberTypeValidators |
---|
241 | // we own it (or not, depending on the state of fMemberTypesInherited). |
---|
242 | // |
---|
243 | // fValidatedDatatype |
---|
244 | // the dataTypeValidator that was actually used to validate the last time validate was called |
---|
245 | // |
---|
246 | // ----------------------------------------------------------------------- |
---|
247 | |
---|
248 | bool fEnumerationInherited; |
---|
249 | bool fMemberTypesInherited; |
---|
250 | RefArrayVectorOf<XMLCh>* fEnumeration; |
---|
251 | RefVectorOf<DatatypeValidator>* fMemberTypeValidators; |
---|
252 | DatatypeValidator* fValidatedDatatype; |
---|
253 | }; |
---|
254 | |
---|
255 | inline DatatypeValidator* UnionDatatypeValidator::newInstance |
---|
256 | ( |
---|
257 | RefHashTableOf<KVStringPair>* const facets |
---|
258 | , RefArrayVectorOf<XMLCh>* const enums |
---|
259 | , const int finalSet |
---|
260 | , MemoryManager* const manager |
---|
261 | ) |
---|
262 | { |
---|
263 | return (DatatypeValidator*) new (manager) UnionDatatypeValidator(this, facets, enums, finalSet, manager, fMemberTypeValidators, true); |
---|
264 | } |
---|
265 | |
---|
266 | inline void UnionDatatypeValidator::validate( const XMLCh* const content |
---|
267 | , ValidationContext* const context |
---|
268 | , MemoryManager* const manager) |
---|
269 | { |
---|
270 | checkContent(content, context, false, manager); |
---|
271 | } |
---|
272 | |
---|
273 | inline void UnionDatatypeValidator::cleanUp() |
---|
274 | { |
---|
275 | //~RefVectorOf will delete all adopted elements |
---|
276 | if ( !fEnumerationInherited && fEnumeration) |
---|
277 | delete fEnumeration; |
---|
278 | |
---|
279 | if (!fMemberTypesInherited && fMemberTypeValidators) |
---|
280 | delete fMemberTypeValidators; |
---|
281 | |
---|
282 | } |
---|
283 | |
---|
284 | inline RefArrayVectorOf<XMLCh>* UnionDatatypeValidator:: getEnumeration() const |
---|
285 | { |
---|
286 | return fEnumeration; |
---|
287 | } |
---|
288 | |
---|
289 | inline void UnionDatatypeValidator::setEnumeration(RefArrayVectorOf<XMLCh>* enums |
---|
290 | , bool inherited) |
---|
291 | { |
---|
292 | if (enums) |
---|
293 | { |
---|
294 | if ( !fEnumerationInherited && fEnumeration) |
---|
295 | delete fEnumeration; |
---|
296 | |
---|
297 | fEnumeration = enums; |
---|
298 | fEnumerationInherited = inherited; |
---|
299 | setFacetsDefined(DatatypeValidator::FACET_ENUMERATION); |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | // |
---|
304 | // get the native UnionDTV's fMemberTypeValidators |
---|
305 | // |
---|
306 | inline |
---|
307 | RefVectorOf<DatatypeValidator>* UnionDatatypeValidator::getMemberTypeValidators() const |
---|
308 | { |
---|
309 | return this->fMemberTypeValidators; |
---|
310 | } |
---|
311 | |
---|
312 | inline bool UnionDatatypeValidator::isAtomic() const { |
---|
313 | |
---|
314 | |
---|
315 | |
---|
316 | if (!fMemberTypeValidators) { |
---|
317 | return false; |
---|
318 | } |
---|
319 | |
---|
320 | unsigned int memberSize = fMemberTypeValidators->size(); |
---|
321 | |
---|
322 | for (unsigned int i=0; i < memberSize; i++) { |
---|
323 | if (!fMemberTypeValidators->elementAt(i)->isAtomic()) { |
---|
324 | return false; |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | return true; |
---|
329 | } |
---|
330 | |
---|
331 | inline bool UnionDatatypeValidator::isSubstitutableBy(const DatatypeValidator* const toCheck) { |
---|
332 | |
---|
333 | if (toCheck == this) { |
---|
334 | return true; |
---|
335 | } |
---|
336 | |
---|
337 | if (fMemberTypeValidators) { |
---|
338 | unsigned int memberSize = fMemberTypeValidators->size(); |
---|
339 | |
---|
340 | for (unsigned int i=0; i < memberSize; i++) { |
---|
341 | if ((fMemberTypeValidators->elementAt(i)->getType() == DatatypeValidator::Union) && |
---|
342 | (fMemberTypeValidators->elementAt(i) == toCheck)) |
---|
343 | return false; |
---|
344 | if (fMemberTypeValidators->elementAt(i)->isSubstitutableBy(toCheck)) { |
---|
345 | return true; |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | return false; |
---|
350 | } |
---|
351 | |
---|
352 | inline const XMLCh* UnionDatatypeValidator::getMemberTypeName() const { |
---|
353 | if(fValidatedDatatype) { |
---|
354 | return fValidatedDatatype->getTypeLocalName(); |
---|
355 | } |
---|
356 | return 0; |
---|
357 | } |
---|
358 | |
---|
359 | inline const XMLCh* UnionDatatypeValidator::getMemberTypeUri() const |
---|
360 | { |
---|
361 | if(fValidatedDatatype) { |
---|
362 | return fValidatedDatatype->getTypeUri(); |
---|
363 | } |
---|
364 | return 0; |
---|
365 | } |
---|
366 | |
---|
367 | inline bool UnionDatatypeValidator::getMemberTypeAnonymous() const { |
---|
368 | if(fValidatedDatatype) { |
---|
369 | return fValidatedDatatype->getAnonymous(); |
---|
370 | } |
---|
371 | return 0; |
---|
372 | } |
---|
373 | |
---|
374 | inline const DatatypeValidator* UnionDatatypeValidator::getMemberTypeValidator() const { |
---|
375 | return fValidatedDatatype; |
---|
376 | } |
---|
377 | |
---|
378 | inline void UnionDatatypeValidator::reset() { |
---|
379 | fValidatedDatatype = 0; |
---|
380 | } |
---|
381 | |
---|
382 | XERCES_CPP_NAMESPACE_END |
---|
383 | |
---|
384 | #endif |
---|
385 | |
---|
386 | /** |
---|
387 | * End of file UnionDatatypeValidator.hpp |
---|
388 | */ |
---|
389 | |
---|