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: AbstractNumericFacetValidator.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22 // ---------------------------------------------------------------------------
23 // Includes
24 // ---------------------------------------------------------------------------
25 #include <xercesc/validators/datatype/AbstractNumericFacetValidator.hpp>
26 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>
27 #include <xercesc/util/NumberFormatException.hpp>
28
29 //since we need to dynamically created each and every derivatives
30 //during deserialization by XSerializeEngine>>Derivative, we got
31 //to include all hpp
32 #include <xercesc/util/XMLFloat.hpp>
33 #include <xercesc/util/XMLDouble.hpp>
34 #include <xercesc/util/XMLBigDecimal.hpp>
35 #include <xercesc/util/XMLDateTime.hpp>
36 #include <xercesc/internal/XTemplateSerializer.hpp>
37
38 XERCES_CPP_NAMESPACE_BEGIN
39
40 const int AbstractNumericFacetValidator::INDETERMINATE = 2;
41
42 #define REPORT_FACET_ERROR(val1, val2, except_code, manager) \
43 ThrowXMLwithMemMgr2(InvalidDatatypeFacetException \
44 , except_code \
45 , val1->getFormattedString() \
46 , val2->getFormattedString() \
47 , manager);
48
49 #define FROM_BASE_VALUE_SPACE(val, facetFlag, except_code, manager) \
50 if ((thisFacetsDefined & facetFlag) != 0) \
51 { \
52 try \
53 { \
54 numBase->checkContent(val->getRawData(), (ValidationContext*)0, false, manager); \
55 } \
56 catch ( XMLException& ) \
57 { \
58 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException \
59 , except_code \
60 , val->getRawData() \
61 , manager); \
62 } \
63 }
64
65
66 // ---------------------------------------------------------------------------
67 // Constructors and Destructor
68 // ---------------------------------------------------------------------------
~AbstractNumericFacetValidator()69 AbstractNumericFacetValidator::~AbstractNumericFacetValidator()
70 {
71 if (!fMaxInclusiveInherited && fMaxInclusive)
72 delete fMaxInclusive;
73
74 if (!fMaxExclusiveInherited && fMaxExclusive)
75 delete fMaxExclusive;
76
77 if (!fMinInclusiveInherited && fMinInclusive)
78 delete fMinInclusive;
79
80 if (!fMinExclusiveInherited && fMinExclusive)
81 delete fMinExclusive;
82
83 //~RefVectorOf will delete all adopted elements
84 if (!fEnumerationInherited && fEnumeration)
85 delete fEnumeration;
86
87 if (!fEnumerationInherited && fStrEnumeration)
88 delete fStrEnumeration;
89 }
90
AbstractNumericFacetValidator(DatatypeValidator * const baseValidator,RefHashTableOf<KVStringPair> * const facets,const int finalSet,const ValidatorType type,MemoryManager * const manager)91 AbstractNumericFacetValidator::AbstractNumericFacetValidator(
92 DatatypeValidator* const baseValidator
93 , RefHashTableOf<KVStringPair>* const facets
94 , const int finalSet
95 , const ValidatorType type
96 , MemoryManager* const manager)
97 :DatatypeValidator(baseValidator, facets, finalSet, type, manager)
98 , fMaxInclusiveInherited(false)
99 , fMaxExclusiveInherited(false)
100 , fMinInclusiveInherited(false)
101 , fMinExclusiveInherited(false)
102 , fEnumerationInherited(false)
103 , fMaxInclusive(0)
104 , fMaxExclusive(0)
105 , fMinInclusive(0)
106 , fMinExclusive(0)
107 , fEnumeration(0)
108 , fStrEnumeration(0)
109 {
110 //do not invoke init() here !!!
111 }
112
113 //
114 // P1. Enumeration
115 //
init(RefArrayVectorOf<XMLCh> * const enums,MemoryManager * const manager)116 void AbstractNumericFacetValidator::init(RefArrayVectorOf<XMLCh>* const enums
117 , MemoryManager* const manager)
118 {
119
120 fStrEnumeration = enums; // save the literal value
121 // which is needed for getEnumString()
122
123 if (enums)
124 {
125 setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
126 }
127
128 assignFacet(manager);
129 inspectFacet(manager);
130 inspectFacetBase(manager);
131 inheritFacet();
132 }
133
134 //
135 // Assign facets
136 // assign common facets
137 // assign additional facet
138 //
assignFacet(MemoryManager * const manager)139 void AbstractNumericFacetValidator::assignFacet(MemoryManager* const manager)
140 {
141
142 RefHashTableOf<KVStringPair>* facets = getFacets();
143
144 if (!facets) // no facets defined
145 return;
146
147 XMLCh* key;
148
149 RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager);
150
151 while (e.hasMoreElements())
152 {
153 KVStringPair pair = e.nextElement();
154 key = pair.getKey();
155 XMLCh* value = pair.getValue();
156
157 if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN))
158 {
159 setPattern(value);
160 if (getPattern())
161 setFacetsDefined(DatatypeValidator::FACET_PATTERN);
162 // do not construct regex until needed
163 }
164 else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXINCLUSIVE))
165 {
166 try
167 {
168 setMaxInclusive(value);
169 }
170 catch (NumberFormatException&)
171 {
172 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxIncl, value, manager);
173 }
174 setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE);
175 }
176 else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXEXCLUSIVE))
177 {
178 try
179 {
180 setMaxExclusive(value);
181 }
182 catch (NumberFormatException&)
183 {
184 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxExcl, value, manager);
185 }
186 setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE);
187 }
188 else if (XMLString::equals(key, SchemaSymbols::fgELT_MININCLUSIVE))
189 {
190 try
191 {
192 setMinInclusive(value);
193 }
194 catch (NumberFormatException&)
195 {
196 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinIncl, value, manager);
197 }
198 setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE);
199 }
200 else if (XMLString::equals(key, SchemaSymbols::fgELT_MINEXCLUSIVE))
201 {
202 try
203 {
204 setMinExclusive(value);
205 }
206 catch (NumberFormatException&)
207 {
208 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinExcl, value, manager);
209 }
210 setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE);
211 }
212 else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED))
213 {
214 unsigned int val;
215 bool retStatus;
216 try
217 {
218 retStatus = XMLString::textToBin(value, val, fMemoryManager);
219 }
220 catch (RuntimeException&)
221 {
222 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager);
223 }
224
225 if (!retStatus)
226 {
227 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager);
228 }
229
230 setFixed(val);
231 //no setFacetsDefined here
232
233 }
234 else
235 {
236 assignAdditionalFacet(key, value, manager);
237 }
238
239 }//while
240
241 }// end of assigneFacet()
242
243 //
244 // Check facet among self
245 // check common facets
246 // check Additional Facet Constraint
247 //
inspectFacet(MemoryManager * const manager)248 void AbstractNumericFacetValidator::inspectFacet(MemoryManager* const manager)
249 {
250
251 int thisFacetsDefined = getFacetsDefined();
252 XMLNumber *thisMaxInclusive = getMaxInclusive();
253 XMLNumber *thisMaxExclusive = getMaxExclusive();
254 XMLNumber *thisMinInclusive = getMinInclusive();
255 XMLNumber *thisMinExclusive = getMinExclusive();
256
257 if (!thisFacetsDefined)
258 return;
259
260 // non co-existence checking
261 // check 4.3.8.c1 error: maxInclusive + maxExclusive
262 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&
263 ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) )
264 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_max_Incl_Excl, manager);
265
266 // non co-existence checking
267 // check 4.3.9.c1 error: minInclusive + minExclusive
268 if (((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) &&
269 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) )
270 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_min_Incl_Excl, manager);
271
272 //
273 // minExclusive < minInclusive <= maxInclusive < maxExclusive
274 //
275 // check 4.3.7.c1 must: minInclusive <= maxInclusive
276 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) &&
277 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) )
278 {
279 int result = compareValues(thisMinInclusive, thisMaxInclusive);
280 if ( result == 1 || result == INDETERMINATE )
281 {
282 REPORT_FACET_ERROR(thisMinInclusive
283 , thisMaxInclusive
284 , XMLExcepts::FACET_maxIncl_minIncl
285 , manager)
286 }
287 }
288
289 // check 4.3.8.c2 must: minExclusive <= maxExclusive
290 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&
291 ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) )
292 {
293 int result = compareValues(getMinExclusive(), getMaxExclusive());
294 if ( result == 1 || result == INDETERMINATE )
295 {
296 REPORT_FACET_ERROR(thisMinExclusive
297 , thisMaxExclusive
298 , XMLExcepts::FACET_maxExcl_minExcl
299 , manager)
300 }
301 }
302
303 // check 4.3.9.c2 must: minExclusive < maxInclusive
304 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) &&
305 ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) )
306 {
307 int result = compareValues(getMinExclusive(), getMaxInclusive());
308 if ( result != -1 )
309 {
310 REPORT_FACET_ERROR(thisMinExclusive
311 , thisMaxInclusive
312 , XMLExcepts::FACET_maxIncl_minExcl
313 , manager)
314 }
315 }
316
317 // check 4.3.10.c1 must: minInclusive < maxExclusive
318 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&
319 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) )
320 {
321 int result = compareValues(getMinInclusive(), getMaxExclusive());
322 if ( result != -1)
323 {
324 REPORT_FACET_ERROR(thisMinInclusive
325 , thisMaxExclusive
326 , XMLExcepts::FACET_maxExcl_minIncl
327 , manager)
328 }
329 }
330
331 checkAdditionalFacetConstraints(manager);
332
333 }// end of inspectFacet()
334
335 //
336 // Check vs base
337 // check common facets
338 // check enumeration
339 // check Additional Facet Constraint
340 //
inspectFacetBase(MemoryManager * const manager)341 void AbstractNumericFacetValidator::inspectFacetBase(MemoryManager* const manager)
342 {
343
344 AbstractNumericFacetValidator* numBase = (AbstractNumericFacetValidator*) getBaseValidator();
345 int thisFacetsDefined = getFacetsDefined();
346
347 if ( (!thisFacetsDefined && !fEnumeration) ||
348 !numBase )
349 return;
350
351 int baseFacetsDefined = numBase->getFacetsDefined();
352
353 XMLNumber *thisMaxInclusive = getMaxInclusive();
354 XMLNumber *thisMaxExclusive = getMaxExclusive();
355 XMLNumber *thisMinInclusive = getMinInclusive();
356 XMLNumber *thisMinExclusive = getMinExclusive();
357
358 XMLNumber *baseMaxInclusive = numBase->getMaxInclusive();
359 XMLNumber *baseMaxExclusive = numBase->getMaxExclusive();
360 XMLNumber *baseMinInclusive = numBase->getMinInclusive();
361 XMLNumber *baseMinExclusive = numBase->getMinExclusive();
362 int baseFixed = numBase->getFixed();
363
364 // this
365 // minExclusive maxExclusive
366 // minInclusive maxInclusive
367 //
368 // base
369 // minExclusive maxExclusive
370 // minInclusive maxInclusive
371 //
372
373 // check 4.3.7.c2 error:
374 // maxInclusive > base.maxInclusive && maxInclusive != base.maxInclusive if (base.fixed)
375 // maxInclusive >= base.maxExclusive
376 // maxInclusive < base.minInclusive
377 // maxInclusive <= base.minExclusive
378
379 if ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)
380 {
381 if ((baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)
382 {
383 int result = compareValues(thisMaxInclusive, baseMaxInclusive);
384
385 if (((baseFixed & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) &&
386 (result != 0 ))
387 {
388 REPORT_FACET_ERROR(thisMaxInclusive
389 , baseMaxInclusive
390 , XMLExcepts::FACET_maxIncl_base_fixed
391 , manager)
392 }
393
394 if (result == 1 || result == INDETERMINATE)
395 {
396 REPORT_FACET_ERROR(thisMaxInclusive
397 , baseMaxInclusive
398 , XMLExcepts::FACET_maxIncl_base_maxIncl
399 , manager)
400 }
401
402 }
403
404 if ((baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)
405 {
406 int result = compareValues(thisMaxInclusive, baseMaxExclusive);
407 if (result != -1 )
408 {
409 REPORT_FACET_ERROR(thisMaxInclusive
410 , baseMaxExclusive
411 , XMLExcepts::FACET_maxIncl_base_maxExcl
412 , manager)
413 }
414 }
415
416
417 if ((baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)
418 {
419 int result = compareValues(thisMaxInclusive, baseMinInclusive);
420 if (result == -1 || result == INDETERMINATE)
421 {
422 REPORT_FACET_ERROR(thisMaxInclusive
423 , baseMinInclusive
424 , XMLExcepts::FACET_maxIncl_base_minIncl
425 , manager)
426 }
427 }
428
429 if ((baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)
430 {
431 int result = compareValues(thisMaxInclusive, baseMinExclusive);
432 if (result != 1 )
433 {
434 REPORT_FACET_ERROR(thisMaxInclusive
435 , baseMinExclusive
436 , XMLExcepts::FACET_maxIncl_base_minExcl
437 , manager)
438 }
439 }
440
441 }
442
443 // check 4.3.8.c3 error:
444 // maxExclusive > base.maxExclusive && maxExclusive != base.maxExclusive if (base.fixed)
445 // maxExclusive > base.maxInclusive
446 // maxExclusive <= base.minInclusive
447 // maxExclusive <= base.minExclusive
448
449 if ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)
450 {
451 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)
452 {
453 int result = compareValues(thisMaxExclusive, baseMaxExclusive);
454
455 if (((baseFixed & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&
456 (result != 0 ))
457 {
458 REPORT_FACET_ERROR(thisMaxExclusive
459 , baseMaxExclusive
460 , XMLExcepts::FACET_maxExcl_base_fixed
461 , manager)
462 }
463
464 if (result == 1 || result == INDETERMINATE)
465 {
466 REPORT_FACET_ERROR(thisMaxExclusive
467 , baseMaxExclusive
468 , XMLExcepts::FACET_maxExcl_base_maxExcl
469 , manager)
470 }
471
472 /**
473 * Schema Errata
474 * E2-16 maxExclusive
475 *
476 * derived type's maxExclusive must either be
477 * 1) equal to base' maxExclusive or
478 * 2) from the base type value space
479 *
480 */
481 if (result != 0)
482 {
483 FROM_BASE_VALUE_SPACE(thisMaxExclusive
484 , DatatypeValidator::FACET_MAXEXCLUSIVE
485 , XMLExcepts::FACET_maxExcl_notFromBase
486 , manager)
487 }
488 }
489 else // base has no maxExclusive
490 {
491 FROM_BASE_VALUE_SPACE(thisMaxExclusive
492 , DatatypeValidator::FACET_MAXEXCLUSIVE
493 , XMLExcepts::FACET_maxExcl_notFromBase
494 , manager)
495 }
496
497 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)
498 {
499 int result = compareValues(thisMaxExclusive, baseMaxInclusive);
500 if (result == 1 || result == INDETERMINATE)
501 {
502 REPORT_FACET_ERROR(thisMaxExclusive
503 , baseMaxInclusive
504 , XMLExcepts::FACET_maxExcl_base_maxIncl
505 , manager)
506 }
507 }
508
509 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)
510 {
511 int result = compareValues(thisMaxExclusive, baseMinExclusive);
512 if (result != 1)
513 {
514 REPORT_FACET_ERROR(thisMaxExclusive
515 , baseMinExclusive
516 , XMLExcepts::FACET_maxExcl_base_minExcl
517 , manager)
518 }
519 }
520
521 if (( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)
522 {
523 int result = compareValues(thisMaxExclusive, baseMinInclusive);
524 if (result != 1)
525 {
526 REPORT_FACET_ERROR(thisMaxExclusive
527 , baseMinInclusive
528 , XMLExcepts::FACET_maxExcl_base_minIncl
529 , manager)
530 }
531 }
532 }
533
534 // check 4.3.9.c3 error:
535 // minExclusive < base.minExclusive minExclusive != base.minExclusive if (base.fixed)
536 // minExclusive > base.maxInclusive ??? minExclusive >= base.maxInclusive
537 // minExclusive < base.minInclusive
538 // minExclusive >= base.maxExclusive
539
540 if ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)
541 {
542 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)
543 {
544 int result = compareValues(thisMinExclusive, baseMinExclusive);
545
546 if (((baseFixed & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) &&
547 (result != 0 ))
548 {
549 REPORT_FACET_ERROR(thisMinExclusive
550 , baseMinExclusive
551 , XMLExcepts::FACET_minExcl_base_fixed
552 , manager)
553 }
554
555 if (result == -1 || result == INDETERMINATE)
556 {
557 REPORT_FACET_ERROR(thisMinExclusive
558 , baseMinExclusive
559 , XMLExcepts::FACET_minExcl_base_minExcl
560 , manager)
561 }
562
563 /**
564 * Schema Errata
565 * E2-16 maxExclusive
566 *
567 * derived type's minExclusive must either be
568 * 1) equal to base' minxExclusive or
569 * 2) from the base type value space
570 *
571 * Note: deduced from, not explicitly expressed in the Errata
572 */
573 if (result != 0)
574 {
575 FROM_BASE_VALUE_SPACE(thisMinExclusive
576 , DatatypeValidator::FACET_MINEXCLUSIVE
577 , XMLExcepts::FACET_minExcl_notFromBase
578 , manager)
579 }
580 }
581 else // base has no minExclusive
582 {
583
584 FROM_BASE_VALUE_SPACE(thisMinExclusive
585 , DatatypeValidator::FACET_MINEXCLUSIVE
586 , XMLExcepts::FACET_minExcl_notFromBase
587 , manager)
588 }
589
590 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)
591 {
592 int result = compareValues(thisMinExclusive, baseMaxInclusive);
593 if (result == 1 || result == INDETERMINATE)
594 {
595 REPORT_FACET_ERROR(thisMinExclusive
596 , baseMaxInclusive
597 , XMLExcepts::FACET_minExcl_base_maxIncl
598 , manager)
599 }
600 }
601
602 if (( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)
603 {
604 int result = compareValues(thisMinExclusive, baseMinInclusive);
605 if (result == -1 || result == INDETERMINATE)
606 {
607 REPORT_FACET_ERROR(thisMinExclusive
608 , baseMinInclusive
609 , XMLExcepts::FACET_minExcl_base_minIncl
610 , manager)
611 }
612 }
613
614 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)
615 {
616 int result = compareValues(thisMinExclusive, baseMaxExclusive);
617 if (result != -1)
618 {
619 REPORT_FACET_ERROR(thisMinExclusive
620 , baseMaxExclusive
621 , XMLExcepts::FACET_minExcl_base_maxExcl
622 , manager)
623 }
624 }
625
626 }
627
628 // check 4.3.10.c2 error:
629 // minInclusive < base.minInclusive minInclusive != base.minInclusive if (base.fixed)
630 // minInclusive > base.maxInclusive
631 // minInclusive <= base.minExclusive
632 // minInclusive >= base.maxExclusive
633
634
635 if ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)
636 {
637 if ((baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)
638 {
639 int result = compareValues(thisMinInclusive, baseMinInclusive);
640
641 if (((baseFixed & DatatypeValidator::FACET_MININCLUSIVE) != 0) &&
642 (result != 0 ))
643 {
644 REPORT_FACET_ERROR(thisMinInclusive
645 , baseMinInclusive
646 , XMLExcepts::FACET_minIncl_base_fixed
647 , manager)
648 }
649
650 if (result == -1 || result == INDETERMINATE)
651 {
652 REPORT_FACET_ERROR(thisMinInclusive
653 , baseMinInclusive
654 , XMLExcepts::FACET_minIncl_base_minIncl
655 , manager)
656 }
657 }
658
659 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)
660 {
661 int result = compareValues(thisMinInclusive, baseMaxInclusive);
662 if (result == 1 || result == INDETERMINATE)
663 {
664 REPORT_FACET_ERROR(thisMinInclusive
665 , baseMaxInclusive
666 , XMLExcepts::FACET_minIncl_base_maxIncl
667 , manager)
668 }
669 }
670
671 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)
672 {
673 int result = compareValues(thisMinInclusive, baseMinExclusive);
674 if (result != 1)
675 {
676 REPORT_FACET_ERROR(thisMinInclusive
677 , baseMinExclusive
678 , XMLExcepts::FACET_minIncl_base_minExcl
679 , manager)
680 }
681 }
682
683 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)
684 {
685 int result = compareValues(thisMinInclusive, baseMaxExclusive);
686 if (result != -1)
687 {
688 REPORT_FACET_ERROR(thisMinInclusive
689 , baseMaxExclusive
690 , XMLExcepts::FACET_minIncl_base_maxExcl
691 , manager)
692 }
693 }
694
695 }
696
697 checkAdditionalFacetConstraintsBase(manager);
698
699 // check 4.3.5.c0 must: enumeration values from the value space of base
700 //
701 // In fact, the values in the enumeration shall go through validation
702 // of this class as well.
703 // this->checkContent(value, false);
704 //
705 if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&
706 ( fStrEnumeration ))
707 {
708 setEnumeration(manager);
709 }
710
711 //
712 // maxInclusive, maxExclusive, minInclusive and minExclusive
713 // shall come from the base's value space as well
714 //
715
716 FROM_BASE_VALUE_SPACE(thisMaxInclusive
717 , DatatypeValidator::FACET_MAXINCLUSIVE
718 , XMLExcepts::FACET_maxIncl_notFromBase
719 , manager)
720
721 FROM_BASE_VALUE_SPACE(thisMinInclusive
722 , DatatypeValidator::FACET_MININCLUSIVE
723 , XMLExcepts::FACET_minIncl_notFromBase
724 , manager)
725
726 } //end of inspectFacetBase
727
728 //
729 // Inherit facet from base
730 // a. inherit common facets
731 // b. inherit additional facet
732 //
inheritFacet()733 void AbstractNumericFacetValidator::inheritFacet()
734 {
735
736 AbstractNumericFacetValidator* numBase = (AbstractNumericFacetValidator*) getBaseValidator();
737 if (!numBase)
738 return;
739
740 int thisFacetsDefined = getFacetsDefined();
741 int baseFacetsDefined = numBase->getFacetsDefined();
742
743 // inherit enumeration
744 if ((( baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&
745 (( thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0))
746 {
747 fEnumeration = numBase->fEnumeration;
748 fEnumerationInherited = true;
749 setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
750 }
751
752 // inherit maxInclusive
753 if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) &&
754 (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) &&
755 (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) )
756 {
757 fMaxInclusive = numBase->getMaxInclusive();
758 fMaxInclusiveInherited = true;
759 setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE);
760 }
761
762 // inherit maxExclusive
763 if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&
764 (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) &&
765 (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) )
766 {
767 fMaxExclusive = numBase->getMaxExclusive();
768 fMaxExclusiveInherited = true;
769 setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE);
770 }
771
772 // inherit minExclusive
773 if ((( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) &&
774 (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) &&
775 (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) )
776 {
777 fMinInclusive = numBase->getMinInclusive();
778 fMinInclusiveInherited = true;
779 setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE);
780 }
781
782 // inherit minExclusive
783 if ((( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) &&
784 (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) &&
785 (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) )
786 {
787 fMinExclusive = numBase->getMinExclusive();
788 fMinExclusiveInherited = true;
789 setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE);
790 }
791
792 inheritAdditionalFacet();
793
794 // inherit "fixed" option
795 setFixed(getFixed() | numBase->getFixed());
796
797 }
798
getEnumString() const799 const RefArrayVectorOf<XMLCh>* AbstractNumericFacetValidator::getEnumString() const
800 {
801 return (fEnumerationInherited? getBaseValidator()->getEnumString() : fStrEnumeration );
802 }
803
804
checkAdditionalFacetConstraints(MemoryManager * const) const805 void AbstractNumericFacetValidator::checkAdditionalFacetConstraints(MemoryManager* const) const
806 {
807 return;
808 }
809
checkAdditionalFacetConstraintsBase(MemoryManager * const) const810 void AbstractNumericFacetValidator::checkAdditionalFacetConstraintsBase(MemoryManager* const) const
811 {
812 return;
813 }
814
inheritAdditionalFacet()815 void AbstractNumericFacetValidator::inheritAdditionalFacet()
816 {
817 return;
818 }
819
assignAdditionalFacet(const XMLCh * const key,const XMLCh * const,MemoryManager * const manager)820 void AbstractNumericFacetValidator::assignAdditionalFacet( const XMLCh* const key
821 , const XMLCh* const
822 , MemoryManager* const manager)
823 {
824 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException
825 , XMLExcepts::FACET_Invalid_Tag
826 , key
827 , manager);
828 }
829
830
831
832 /***
833 * Support for Serialization/De-serialization
834 ***/
835
IMPL_XSERIALIZABLE_NOCREATE(AbstractNumericFacetValidator)836 IMPL_XSERIALIZABLE_NOCREATE(AbstractNumericFacetValidator)
837
838 /***
839 * This dv needs to serialize/deserialize four boundary data members
840 * which are derivatives of XMLlNumber.
841 * The derivatives of this class, namely, Deciamldv, Doubledv, Floatdv and
842 * DateTimedv needs to write a typeEnum into the binary data stream, so
843 * during loading, this method reads the typeEnum first, and then instantiate
844 * the right type of objects, say XMLDouble, XMLFloat, XMLBigDecimal and
845 * XMLDateTime.
846 *
847 *
848 ***/
849 void AbstractNumericFacetValidator::serialize(XSerializeEngine& serEng)
850 {
851
852 if (serEng.isStoring())
853 {
854
855 /***
856 * don't move this line out of the if statement,
857 * it is done purposely to allow AbstractNumericFacetValidator
858 * read the number type information before DatatypeValidator
859 * during loading
860 ***/
861 DatatypeValidator::serialize(serEng);
862
863 // need not write type info for the XMLNumber since
864 // the derivative class has done that
865 storeClusive(serEng, fMaxInclusiveInherited, fMaxInclusive);
866 storeClusive(serEng, fMaxExclusiveInherited, fMaxExclusive);
867 storeClusive(serEng, fMinInclusiveInherited, fMinInclusive);
868 storeClusive(serEng, fMinExclusiveInherited, fMinExclusive);
869
870 serEng<<fEnumerationInherited;
871
872 /***
873 * Serialize RefArrayVectorOf<XMLCh>
874 * Serialize RefVectorOf<XMLNumber>
875 ***/
876 XTemplateSerializer::storeObject(fStrEnumeration, serEng);
877 XTemplateSerializer::storeObject(fEnumeration, serEng);
878
879 }
880 else
881 {
882 // Read the number type info for the XMLNumber FIRST!!!
883 int nType;
884 XMLNumber::NumberType numType;
885 serEng>>nType;
886 numType = (XMLNumber::NumberType) nType;
887
888 DatatypeValidator::serialize(serEng);
889
890 loadClusive(serEng, fMaxInclusiveInherited, fMaxInclusive, numType, 1);
891 loadClusive(serEng, fMaxExclusiveInherited, fMaxExclusive, numType, 2);
892 loadClusive(serEng, fMinInclusiveInherited, fMinInclusive, numType, 3);
893 loadClusive(serEng, fMinExclusiveInherited, fMinExclusive, numType, 4);
894
895 serEng>>fEnumerationInherited;
896
897 /***
898 * Deserialize RefArrayVectorOf<XMLCh>
899 * Deserialize RefVectorOf<XMLNumber>
900 ***/
901 XTemplateSerializer::loadObject(&fStrEnumeration, 8, true, serEng);
902 XTemplateSerializer::loadObject(&fEnumeration, 8, true, numType, serEng);
903
904 }
905
906 }
907
908 //
909 // A user defined dv may inherit any of the Max/Min/Inc/Exc from a
910 // built dv, which will create its own Max/Min/Inc/Exc during the
911 // loading. Therefore if the user defined store and load this
912 // facet, and does not own it, that will cause leakage.
913 //
914 // To avoid checking if the facet belongs to a builtIn dv or not, we
915 // do this way, for any inherited *clusive, we will not store it, and later
916 // on during loading, we get it from the base dv.
917 //
storeClusive(XSerializeEngine & serEng,bool inherited,XMLNumber * data)918 void AbstractNumericFacetValidator::storeClusive(XSerializeEngine& serEng
919 , bool inherited
920 , XMLNumber* data)
921 {
922 serEng<<inherited;
923
924 //store only if own it
925 if (!inherited)
926 serEng<<data;
927
928 }
929
930 // it is guranteed that the base dv is loaded before this dv
931 //
loadClusive(XSerializeEngine & serEng,bool & inherited,XMLNumber * & data,XMLNumber::NumberType numType,int flag)932 void AbstractNumericFacetValidator::loadClusive(XSerializeEngine& serEng
933 , bool& inherited
934 , XMLNumber*& data
935 , XMLNumber::NumberType numType
936 , int flag)
937 {
938 serEng>>inherited;
939
940 if (!inherited)
941 data = XMLNumber::loadNumber(numType, serEng);
942 else
943 {
944 AbstractNumericFacetValidator* basedv = (AbstractNumericFacetValidator*) getBaseValidator();
945
946 switch(flag)
947 {
948 case 1:
949 data = basedv->getMaxInclusive();
950 break;
951 case 2:
952 data = basedv->getMaxExclusive();
953 break;
954 case 3:
955 data = basedv->getMinInclusive();
956 break;
957 case 4:
958 data = basedv->getMinExclusive();
959 break;
960 default:
961 break;
962 }
963
964 }
965
966 }
967
968 XERCES_CPP_NAMESPACE_END
969
970 /**
971 * End of file AbstractNumericFacetValidator::cpp
972 */
973