1 57 58 package com.sun.org.apache.xerces.internal.impl.dv.xs; 59 60 import java.util.StringTokenizer ; 61 import java.util.Vector ; 62 63 import com.sun.org.apache.xerces.internal.impl.Constants; 64 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException; 65 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeFacetException; 66 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 67 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; 68 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 69 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets; 70 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 71 import com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression; 72 import com.sun.org.apache.xerces.internal.xs.StringList; 73 import com.sun.org.apache.xerces.internal.xs.XSAnnotation; 74 import com.sun.org.apache.xerces.internal.xs.XSConstants; 75 import com.sun.org.apache.xerces.internal.xs.XSFacet; 76 import com.sun.org.apache.xerces.internal.xs.XSMultiValueFacet; 77 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 78 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 79 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; 80 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 81 import com.sun.org.apache.xerces.internal.impl.xs.util.ShortListImpl; 82 import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl; 83 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 84 import com.sun.org.apache.xerces.internal.util.XMLChar; 85 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 86 87 93 public class XSSimpleTypeDecl implements XSSimpleType { 94 95 static final short DV_STRING = PRIMITIVE_STRING; 96 static final short DV_BOOLEAN = PRIMITIVE_BOOLEAN; 97 static final short DV_DECIMAL = PRIMITIVE_DECIMAL; 98 static final short DV_FLOAT = PRIMITIVE_FLOAT; 99 static final short DV_DOUBLE = PRIMITIVE_DOUBLE; 100 static final short DV_DURATION = PRIMITIVE_DURATION; 101 static final short DV_DATETIME = PRIMITIVE_DATETIME; 102 static final short DV_TIME = PRIMITIVE_TIME; 103 static final short DV_DATE = PRIMITIVE_DATE; 104 static final short DV_GYEARMONTH = PRIMITIVE_GYEARMONTH; 105 static final short DV_GYEAR = PRIMITIVE_GYEAR; 106 static final short DV_GMONTHDAY = PRIMITIVE_GMONTHDAY; 107 static final short DV_GDAY = PRIMITIVE_GDAY; 108 static final short DV_GMONTH = PRIMITIVE_GMONTH; 109 static final short DV_HEXBINARY = PRIMITIVE_HEXBINARY; 110 static final short DV_BASE64BINARY = PRIMITIVE_BASE64BINARY; 111 static final short DV_ANYURI = PRIMITIVE_ANYURI; 112 static final short DV_QNAME = PRIMITIVE_QNAME; 113 static final short DV_NOTATION = PRIMITIVE_NOTATION; 114 115 static final short DV_ANYSIMPLETYPE = 0; 116 static final short DV_ID = DV_NOTATION + 1; 117 static final short DV_IDREF = DV_NOTATION + 2; 118 static final short DV_ENTITY = DV_NOTATION + 3; 119 static final short DV_INTEGER = DV_NOTATION + 4; 120 static final short DV_LIST = DV_NOTATION + 5; 121 static final short DV_UNION = DV_NOTATION + 6; 122 123 static final TypeValidator[] fDVs = { 124 new AnySimpleDV(), 125 new StringDV(), 126 new BooleanDV(), 127 new DecimalDV(), 128 new FloatDV(), 129 new DoubleDV(), 130 new DurationDV(), 131 new DateTimeDV(), 132 new TimeDV(), 133 new DateDV(), 134 new YearMonthDV(), 135 new YearDV(), 136 new MonthDayDV(), 137 new DayDV(), 138 new MonthDV(), 139 new HexBinaryDV(), 140 new Base64BinaryDV(), 141 new AnyURIDV(), 142 new QNameDV(), 143 new QNameDV(), new IDDV(), 145 new IDREFDV(), 146 new EntityDV(), 147 new IntegerDV(), 148 new ListDV(), 149 new UnionDV() 150 }; 151 152 static final short NORMALIZE_NONE = 0; 153 static final short NORMALIZE_TRIM = 1; 154 static final short NORMALIZE_FULL = 2; 155 static final short[] fDVNormalizeType = { 156 NORMALIZE_NONE, NORMALIZE_FULL, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_NONE, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_FULL, NORMALIZE_NONE, }; 183 184 static final short SPECIAL_PATTERN_NONE = 0; 185 static final short SPECIAL_PATTERN_NMTOKEN = 1; 186 static final short SPECIAL_PATTERN_NAME = 2; 187 static final short SPECIAL_PATTERN_NCNAME = 3; 188 189 static final String [] SPECIAL_PATTERN_STRING = { 190 "NONE", "NMTOKEN", "Name", "NCName" 191 }; 192 193 static final String [] WS_FACET_STRING = { 194 "preserve", "replace", "collapse" 195 }; 196 197 static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema"; 198 static final String ANY_TYPE = "anyType"; 199 200 static final ValidationContext fEmptyContext = new ValidationContext() { 201 public boolean needFacetChecking() { 202 return true; 203 } 204 public boolean needExtraChecking() { 205 return false; 206 } 207 public boolean needToNormalize() { 208 return true; 209 } 210 public boolean useNamespaces () { 211 return true; 212 } 213 public boolean isEntityDeclared (String name) { 214 return false; 215 } 216 public boolean isEntityUnparsed (String name) { 217 return false; 218 } 219 public boolean isIdDeclared (String name) { 220 return false; 221 } 222 public void addId(String name) { 223 } 224 public void addIdRef(String name) { 225 } 226 public String getSymbol (String symbol) { 227 return null; 228 } 229 public String getURI(String prefix) { 230 return null; 231 } 232 }; 233 234 private boolean fIsImmutable = false; 238 239 private XSSimpleTypeDecl fItemType; 240 private XSSimpleTypeDecl[] fMemberTypes; 241 private short fBuiltInKind; 243 244 private String fTypeName; 245 private String fTargetNamespace; 246 private short fFinalSet = 0; 247 private XSSimpleTypeDecl fBase; 248 private short fVariety = -1; 249 private short fValidationDV = -1; 250 251 private short fFacetsDefined = 0; 252 private short fFixedFacet = 0; 253 254 private short fWhiteSpace = 0; 256 private int fLength = -1; 257 private int fMinLength = -1; 258 private int fMaxLength = -1; 259 private int fTotalDigits = -1; 260 private int fFractionDigits = -1; 261 private Vector fPattern; 262 private Vector fPatternStr; 263 private Vector fEnumeration; 264 private StringList fLexicalPattern; 265 private StringList fLexicalEnumeration; 266 private Object fMaxInclusive; 267 private Object fMaxExclusive; 268 private Object fMinExclusive; 269 private Object fMinInclusive; 270 271 public XSAnnotation lengthAnnotation; 273 public XSAnnotation minLengthAnnotation; 274 public XSAnnotation maxLengthAnnotation; 275 public XSAnnotation whiteSpaceAnnotation; 276 public XSAnnotation totalDigitsAnnotation; 277 public XSAnnotation fractionDigitsAnnotation; 278 public XSObjectListImpl patternAnnotations; 279 public XSObjectList enumerationAnnotations; 280 public XSAnnotation maxInclusiveAnnotation; 281 public XSAnnotation maxExclusiveAnnotation; 282 public XSAnnotation minInclusiveAnnotation; 283 public XSAnnotation minExclusiveAnnotation; 284 285 private XSObjectListImpl fFacets; 287 288 private XSObjectListImpl fMultiValueFacets; 290 291 private XSObjectList fAnnotations = null; 293 294 private short fPatternType = SPECIAL_PATTERN_NONE; 295 296 private short fOrdered; 298 private boolean fFinite; 299 private boolean fBounded; 300 private boolean fNumeric; 301 302 306 private final int fUniqueId = getNextId(); 307 308 private static int fIdCounter=0; 309 private static synchronized int getNextId() { return fIdCounter++; } 310 311 312 public XSSimpleTypeDecl(){} 314 315 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, short validateDV, 317 short ordered, boolean bounded, boolean finite, 318 boolean numeric, boolean isImmutable, short builtInKind) { 319 fIsImmutable = isImmutable; 320 fBase = base; 321 fTypeName = name; 322 fTargetNamespace = URI_SCHEMAFORSCHEMA; 323 fVariety = VARIETY_ATOMIC; 325 fValidationDV = validateDV; 326 fFacetsDefined = FACET_WHITESPACE; 327 if (validateDV == DV_STRING) { 328 fWhiteSpace = WS_PRESERVE; 329 } else { 330 fWhiteSpace = WS_COLLAPSE; 331 fFixedFacet = FACET_WHITESPACE; 332 } 333 this.fOrdered = ordered; 334 this.fBounded = bounded; 335 this.fFinite = finite; 336 this.fNumeric = numeric; 337 fAnnotations = null; 338 339 fBuiltInKind = builtInKind; 341 } 342 343 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, String uri, short finalSet, boolean isImmutable, 345 XSObjectList annotations, short builtInKind) { 346 this(base, name, uri, finalSet, isImmutable, annotations); 347 fBuiltInKind = builtInKind; 349 } 350 351 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, String uri, short finalSet, boolean isImmutable, 353 XSObjectList annotations) { 354 fBase = base; 355 fTypeName = name; 356 fTargetNamespace = uri; 357 fFinalSet = finalSet; 358 fAnnotations = annotations; 359 360 fVariety = fBase.fVariety; 361 fValidationDV = fBase.fValidationDV; 362 switch (fVariety) { 363 case VARIETY_ATOMIC: 364 break; 365 case VARIETY_LIST: 366 fItemType = fBase.fItemType; 367 break; 368 case VARIETY_UNION: 369 fMemberTypes = fBase.fMemberTypes; 370 break; 371 } 372 373 fLength = fBase.fLength; 376 fMinLength = fBase.fMinLength; 377 fMaxLength = fBase.fMaxLength; 378 fPattern = fBase.fPattern; 379 fPatternStr = fBase.fPatternStr; 380 fEnumeration = fBase.fEnumeration; 381 fWhiteSpace = fBase.fWhiteSpace; 382 fMaxExclusive = fBase.fMaxExclusive; 383 fMaxInclusive = fBase.fMaxInclusive; 384 fMinExclusive = fBase.fMinExclusive; 385 fMinInclusive = fBase.fMinInclusive; 386 fTotalDigits = fBase.fTotalDigits; 387 fFractionDigits = fBase.fFractionDigits; 388 fPatternType = fBase.fPatternType; 389 fFixedFacet = fBase.fFixedFacet; 390 fFacetsDefined = fBase.fFacetsDefined; 391 392 caclFundamentalFacets(); 394 fIsImmutable = isImmutable; 395 396 fBuiltInKind = base.fBuiltInKind; 398 } 399 400 protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, boolean isImmutable, 402 XSObjectList annotations) { 403 fBase = fAnySimpleType; 404 fTypeName = name; 405 fTargetNamespace = uri; 406 fFinalSet = finalSet; 407 fAnnotations = annotations; 408 409 fVariety = VARIETY_LIST; 410 fItemType = (XSSimpleTypeDecl)itemType; 411 fValidationDV = DV_LIST; 412 fFacetsDefined = FACET_WHITESPACE; 413 fFixedFacet = FACET_WHITESPACE; 414 fWhiteSpace = WS_COLLAPSE; 415 416 caclFundamentalFacets(); 418 fIsImmutable = isImmutable; 419 420 fBuiltInKind = XSConstants.LIST_DT; 422 } 423 424 protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes, 426 XSObjectList annotations) { 427 fBase = fAnySimpleType; 428 fTypeName = name; 429 fTargetNamespace = uri; 430 fFinalSet = finalSet; 431 fAnnotations = annotations; 432 433 fVariety = VARIETY_UNION; 434 fMemberTypes = memberTypes; 435 fValidationDV = DV_UNION; 436 fFacetsDefined = FACET_WHITESPACE; 441 fWhiteSpace = WS_COLLAPSE; 442 443 caclFundamentalFacets(); 445 fIsImmutable = false; 448 449 fBuiltInKind = XSConstants.UNAVAILABLE_DT; 451 } 452 453 protected XSSimpleTypeDecl setRestrictionValues(XSSimpleTypeDecl base, String name, String uri, short finalSet, 455 XSObjectList annotations) { 456 if(fIsImmutable) return null; 458 fBase = base; 459 fTypeName = name; 460 fTargetNamespace = uri; 461 fFinalSet = finalSet; 462 fAnnotations = annotations; 463 464 fVariety = fBase.fVariety; 465 fValidationDV = fBase.fValidationDV; 466 switch (fVariety) { 467 case VARIETY_ATOMIC: 468 break; 469 case VARIETY_LIST: 470 fItemType = fBase.fItemType; 471 break; 472 case VARIETY_UNION: 473 fMemberTypes = fBase.fMemberTypes; 474 break; 475 } 476 477 fLength = fBase.fLength; 480 fMinLength = fBase.fMinLength; 481 fMaxLength = fBase.fMaxLength; 482 fPattern = fBase.fPattern; 483 fPatternStr = fBase.fPatternStr; 484 fEnumeration = fBase.fEnumeration; 485 fWhiteSpace = fBase.fWhiteSpace; 486 fMaxExclusive = fBase.fMaxExclusive; 487 fMaxInclusive = fBase.fMaxInclusive; 488 fMinExclusive = fBase.fMinExclusive; 489 fMinInclusive = fBase.fMinInclusive; 490 fTotalDigits = fBase.fTotalDigits; 491 fFractionDigits = fBase.fFractionDigits; 492 fPatternType = fBase.fPatternType; 493 fFixedFacet = fBase.fFixedFacet; 494 fFacetsDefined = fBase.fFacetsDefined; 495 496 caclFundamentalFacets(); 498 return this; 499 } 500 501 protected XSSimpleTypeDecl setListValues(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, 503 XSObjectList annotations) { 504 if(fIsImmutable) return null; 506 fBase = fAnySimpleType; 507 fTypeName = name; 508 fTargetNamespace = uri; 509 fFinalSet = finalSet; 510 fAnnotations = annotations; 511 512 fVariety = VARIETY_LIST; 513 fItemType = (XSSimpleTypeDecl)itemType; 514 fValidationDV = DV_LIST; 515 fFacetsDefined = FACET_WHITESPACE; 516 fFixedFacet = FACET_WHITESPACE; 517 fWhiteSpace = WS_COLLAPSE; 518 519 caclFundamentalFacets(); 521 return this; 522 } 523 524 protected XSSimpleTypeDecl setUnionValues(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes, 526 XSObjectList annotations) { 527 if(fIsImmutable) return null; 529 fBase = fAnySimpleType; 530 fTypeName = name; 531 fTargetNamespace = uri; 532 fFinalSet = finalSet; 533 fAnnotations = annotations; 534 535 fVariety = VARIETY_UNION; 536 fMemberTypes = memberTypes; 537 fValidationDV = DV_UNION; 538 fFacetsDefined = FACET_WHITESPACE; 543 fWhiteSpace = WS_COLLAPSE; 544 545 caclFundamentalFacets(); 547 return this; 548 } 549 550 public short getType () { 551 return XSConstants.TYPE_DEFINITION; 552 } 553 554 public short getTypeCategory () { 555 return SIMPLE_TYPE; 556 } 557 558 public String getName() { 559 return fTypeName; 560 } 561 562 public String getNamespace() { 563 return fTargetNamespace; 564 } 565 566 public short getFinal(){ 567 return fFinalSet; 568 } 569 570 public boolean isFinal(short derivation) { 571 return (fFinalSet & derivation) != 0; 572 } 573 574 public XSTypeDefinition getBaseType(){ 575 return fBase; 576 } 577 578 public boolean getAnonymous() { 579 return fTypeName == null; 580 } 581 582 public short getVariety(){ 583 return fValidationDV == DV_ANYSIMPLETYPE ? VARIETY_ABSENT : fVariety; 585 } 586 587 public boolean isIDType(){ 588 switch (fVariety) { 589 case VARIETY_ATOMIC: 590 return fValidationDV == DV_ID; 591 case VARIETY_LIST: 592 return fItemType.isIDType(); 593 case VARIETY_UNION: 594 for (int i = 0; i < fMemberTypes.length; i++) { 595 if (fMemberTypes[i].isIDType()) 596 return true; 597 } 598 } 599 return false; 600 } 601 602 public short getWhitespace() throws DatatypeException{ 603 if (fVariety == VARIETY_UNION) { 604 throw new DatatypeException("dt-whitespace", new Object []{fTypeName}); 605 } 606 return fWhiteSpace; 607 } 608 609 public short getPrimitiveKind() { 610 if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) { 611 if (fValidationDV == DV_ID || fValidationDV == DV_IDREF || fValidationDV == DV_ENTITY) 612 return DV_STRING; 613 else if (fValidationDV == DV_INTEGER) 614 return DV_DECIMAL; 615 else 616 return fValidationDV; 617 } 618 else { 619 return (short)0; 621 } 622 } 623 624 public short getBuiltInKind() { 625 return this.fBuiltInKind; 626 } 627 628 public XSSimpleTypeDefinition getPrimitiveType() { 629 if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) { 630 XSSimpleTypeDecl pri = this; 631 while (pri.fBase != fAnySimpleType) 633 pri = pri.fBase; 634 return pri; 635 } 636 else { 637 return null; 639 } 640 } 641 642 public XSSimpleTypeDefinition getItemType() { 643 if (fVariety == VARIETY_LIST) { 644 return fItemType; 645 } 646 else { 647 return null; 649 } 650 } 651 652 public XSObjectList getMemberTypes() { 653 if (fVariety == VARIETY_UNION) { 654 return new XSObjectListImpl(fMemberTypes, fMemberTypes.length); 655 } 656 else { 657 return null; 659 } 660 } 661 662 665 public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, ValidationContext context) 666 throws InvalidDatatypeFacetException { 667 applyFacets(facets, presentFacet, fixedFacet, SPECIAL_PATTERN_NONE, context); 668 } 669 670 673 void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet) { 674 675 try { 676 applyFacets(facets, presentFacet, fixedFacet, SPECIAL_PATTERN_NONE, fDummyContext); 677 } catch (InvalidDatatypeFacetException e) { 678 throw new RuntimeException ("internal error"); 680 } 681 fIsImmutable = true; 683 } 684 685 688 void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet, short patternType) { 689 690 try { 691 applyFacets(facets, presentFacet, fixedFacet, patternType, fDummyContext); 692 } catch (InvalidDatatypeFacetException e) { 693 throw new RuntimeException ("internal error"); 695 } 696 fIsImmutable = true; 698 } 699 700 703 void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short patternType, ValidationContext context) 704 throws InvalidDatatypeFacetException { 705 706 if(fIsImmutable) return; 708 ValidatedInfo tempInfo = new ValidatedInfo(); 709 710 717 fFacetsDefined = 0; 718 fFixedFacet = 0; 719 720 int result = 0 ; 721 722 short allowedFacet = fDVs[fValidationDV].getAllowedFacets(); 724 725 if ((presentFacet & FACET_LENGTH) != 0) { 727 if ((allowedFacet & FACET_LENGTH) == 0) { 728 reportError("cos-applicable-facets", new Object []{"length", fTypeName}); 729 } else { 730 fLength = facets.length; 731 lengthAnnotation = facets.lengthAnnotation; 732 fFacetsDefined |= FACET_LENGTH; 733 if ((fixedFacet & FACET_LENGTH) != 0) 734 fFixedFacet |= FACET_LENGTH; 735 } 736 } 737 if ((presentFacet & FACET_MINLENGTH) != 0) { 739 if ((allowedFacet & FACET_MINLENGTH) == 0) { 740 reportError("cos-applicable-facets", new Object []{"minLength", fTypeName}); 741 } else { 742 fMinLength = facets.minLength; 743 minLengthAnnotation = facets.minLengthAnnotation; 744 fFacetsDefined |= FACET_MINLENGTH; 745 if ((fixedFacet & FACET_MINLENGTH) != 0) 746 fFixedFacet |= FACET_MINLENGTH; 747 } 748 } 749 if ((presentFacet & FACET_MAXLENGTH) != 0) { 751 if ((allowedFacet & FACET_MAXLENGTH) == 0) { 752 reportError("cos-applicable-facets", new Object []{"maxLength", fTypeName}); 753 } else { 754 fMaxLength = facets.maxLength; 755 maxLengthAnnotation = facets.maxLengthAnnotation; 756 fFacetsDefined |= FACET_MAXLENGTH; 757 if ((fixedFacet & FACET_MAXLENGTH) != 0) 758 fFixedFacet |= FACET_MAXLENGTH; 759 } 760 } 761 if ((presentFacet & FACET_PATTERN) != 0) { 763 if ((allowedFacet & FACET_PATTERN) == 0) { 764 reportError("cos-applicable-facets", new Object []{"pattern", fTypeName}); 765 } else { 766 patternAnnotations = facets.patternAnnotations; 767 RegularExpression regex = null; 768 try { 769 regex = new RegularExpression(facets.pattern, "X"); 770 } catch (Exception e) { 771 reportError("InvalidRegex", new Object []{facets.pattern, e.getLocalizedMessage()}); 772 } 773 if (regex != null) { 774 fPattern = new Vector (); 775 fPattern.addElement(regex); 776 fPatternStr = new Vector (); 777 fPatternStr.addElement(facets.pattern); 778 fFacetsDefined |= FACET_PATTERN; 779 if ((fixedFacet & FACET_PATTERN) != 0) 780 fFixedFacet |= FACET_PATTERN; 781 } 782 } 783 } 784 785 if ((presentFacet & FACET_ENUMERATION) != 0) { 787 if ((allowedFacet & FACET_ENUMERATION) == 0) { 788 reportError("cos-applicable-facets", new Object []{"enumeration", fTypeName}); 789 } else { 790 fEnumeration = new Vector (); 791 Vector enumVals = facets.enumeration; 792 Vector enumNSDecls = facets.enumNSDecls; 793 ValidationContextImpl ctx = new ValidationContextImpl(context); 794 enumerationAnnotations = facets.enumAnnotations; 795 for (int i = 0; i < enumVals.size(); i++) { 796 if (enumNSDecls != null) 797 ctx.setNSContext((NamespaceContext)enumNSDecls.elementAt(i)); 798 try { 799 fEnumeration.addElement(this.fBase.validate((String )enumVals.elementAt(i), ctx, tempInfo)); 801 } catch (InvalidDatatypeValueException ide) { 802 reportError("enumeration-valid-restriction", new Object []{enumVals.elementAt(i), this.getBaseType().getName()}); 803 } 804 } 805 fFacetsDefined |= FACET_ENUMERATION; 806 if ((fixedFacet & FACET_ENUMERATION) != 0) 807 fFixedFacet |= FACET_ENUMERATION; 808 } 809 } 810 if ((presentFacet & FACET_WHITESPACE) != 0) { 812 if ((allowedFacet & FACET_WHITESPACE) == 0) { 813 reportError("cos-applicable-facets", new Object []{"whiteSpace", fTypeName}); 814 } else { 815 fWhiteSpace = facets.whiteSpace; 816 whiteSpaceAnnotation = facets.whiteSpaceAnnotation; 817 fFacetsDefined |= FACET_WHITESPACE; 818 if ((fixedFacet & FACET_WHITESPACE) != 0) 819 fFixedFacet |= FACET_WHITESPACE; 820 } 821 } 822 823 boolean needCheckBase = true; 824 if ((presentFacet & FACET_MAXINCLUSIVE) != 0) { 826 if ((allowedFacet & FACET_MAXINCLUSIVE) == 0) { 827 reportError("cos-applicable-facets", new Object []{"maxInclusive", fTypeName}); 828 } else { 829 maxInclusiveAnnotation = facets.maxInclusiveAnnotation; 830 try { 831 fMaxInclusive = getActualValue(facets.maxInclusive, context, tempInfo, true); 832 fFacetsDefined |= FACET_MAXINCLUSIVE; 833 if ((fixedFacet & FACET_MAXINCLUSIVE) != 0) 834 fFixedFacet |= FACET_MAXINCLUSIVE; 835 } catch (InvalidDatatypeValueException ide) { 836 reportError(ide.getKey(), ide.getArgs()); 837 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxInclusive, 838 "maxInclusive", fBase.getName()}); 839 } 840 841 if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 843 result = fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMaxInclusive); 844 if ((fBase.fFixedFacet & FACET_MAXINCLUSIVE) != 0 && result != 0) { 845 reportError( "FixedFacetValue", new Object []{"maxInclusive", fMaxInclusive, fBase.fMaxInclusive, fTypeName}); 846 } 847 if (result == 0) { 848 needCheckBase = false; 849 } 850 } 851 if (needCheckBase) { 852 try { 853 fBase.validate(context, tempInfo); 854 } catch (InvalidDatatypeValueException ide) { 855 reportError(ide.getKey(), ide.getArgs()); 856 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxInclusive, 857 "maxInclusive", fBase.getName()}); 858 } 859 } 860 } 861 } 862 863 needCheckBase = true; 865 if ((presentFacet & FACET_MAXEXCLUSIVE) != 0) { 866 if ((allowedFacet & FACET_MAXEXCLUSIVE) == 0) { 867 reportError("cos-applicable-facets", new Object []{"maxExclusive", fTypeName}); 868 } else { 869 maxExclusiveAnnotation = facets.maxExclusiveAnnotation; 870 try { 871 fMaxExclusive = getActualValue(facets.maxExclusive, context, tempInfo, true); 872 fFacetsDefined |= FACET_MAXEXCLUSIVE; 873 if ((fixedFacet & FACET_MAXEXCLUSIVE) != 0) 874 fFixedFacet |= FACET_MAXEXCLUSIVE; 875 } catch (InvalidDatatypeValueException ide) { 876 reportError(ide.getKey(), ide.getArgs()); 877 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxExclusive, 878 "maxExclusive", fBase.getName()}); 879 } 880 881 if (((fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) { 883 result = fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMaxExclusive); 884 if ((fBase.fFixedFacet & FACET_MAXEXCLUSIVE) != 0 && result != 0) { 885 reportError( "FixedFacetValue", new Object []{"maxExclusive", facets.maxExclusive, fBase.fMaxExclusive, fTypeName}); 886 } 887 if (result == 0) { 888 needCheckBase = false; 889 } 890 } 891 if (needCheckBase) { 892 try { 893 fBase.validate(context, tempInfo); 894 } catch (InvalidDatatypeValueException ide) { 895 reportError(ide.getKey(), ide.getArgs()); 896 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxExclusive, 897 "maxExclusive", fBase.getName()}); 898 } 899 } 900 } 901 } 902 needCheckBase = true; 904 if ((presentFacet & FACET_MINEXCLUSIVE) != 0) { 905 if ((allowedFacet & FACET_MINEXCLUSIVE) == 0) { 906 reportError("cos-applicable-facets", new Object []{"minExclusive", fTypeName}); 907 } else { 908 minExclusiveAnnotation = facets.minExclusiveAnnotation; 909 try { 910 fMinExclusive = getActualValue(facets.minExclusive, context, tempInfo, true); 911 fFacetsDefined |= FACET_MINEXCLUSIVE; 912 if ((fixedFacet & FACET_MINEXCLUSIVE) != 0) 913 fFixedFacet |= FACET_MINEXCLUSIVE; 914 } catch (InvalidDatatypeValueException ide) { 915 reportError(ide.getKey(), ide.getArgs()); 916 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minExclusive, 917 "minExclusive", fBase.getName()}); 918 } 919 920 if (((fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 922 result = fDVs[fValidationDV].compare(fMinExclusive, fBase.fMinExclusive); 923 if ((fBase.fFixedFacet & FACET_MINEXCLUSIVE) != 0 && result != 0) { 924 reportError( "FixedFacetValue", new Object []{"minExclusive", facets.minExclusive, fBase.fMinExclusive, fTypeName}); 925 } 926 if (result == 0) { 927 needCheckBase = false; 928 } 929 } 930 if (needCheckBase) { 931 try { 932 fBase.validate(context, tempInfo); 933 } catch (InvalidDatatypeValueException ide) { 934 reportError(ide.getKey(), ide.getArgs()); 935 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minExclusive, 936 "minExclusive", fBase.getName()}); 937 } 938 } 939 } 940 } 941 needCheckBase = true; 943 if ((presentFacet & FACET_MININCLUSIVE) != 0) { 944 if ((allowedFacet & FACET_MININCLUSIVE) == 0) { 945 reportError("cos-applicable-facets", new Object []{"minInclusive", fTypeName}); 946 } else { 947 minInclusiveAnnotation = facets.minInclusiveAnnotation; 948 try { 949 fMinInclusive = getActualValue(facets.minInclusive, context, tempInfo, true); 950 fFacetsDefined |= FACET_MININCLUSIVE; 951 if ((fixedFacet & FACET_MININCLUSIVE) != 0) 952 fFixedFacet |= FACET_MININCLUSIVE; 953 } catch (InvalidDatatypeValueException ide) { 954 reportError(ide.getKey(), ide.getArgs()); 955 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minInclusive, 956 "minInclusive", fBase.getName()}); 957 } 958 959 if (((fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 961 result = fDVs[fValidationDV].compare(fMinInclusive, fBase.fMinInclusive); 962 if ((fBase.fFixedFacet & FACET_MININCLUSIVE) != 0 && result != 0) { 963 reportError( "FixedFacetValue", new Object []{"minInclusive", facets.minInclusive, fBase.fMinInclusive, fTypeName}); 964 } 965 if (result == 0) { 966 needCheckBase = false; 967 } 968 } 969 if (needCheckBase) { 970 try { 971 fBase.validate(context, tempInfo); 972 } catch (InvalidDatatypeValueException ide) { 973 reportError(ide.getKey(), ide.getArgs()); 974 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minInclusive, 975 "minInclusive", fBase.getName()}); 976 } 977 } 978 } 979 } 980 981 if ((presentFacet & FACET_TOTALDIGITS) != 0) { 983 if ((allowedFacet & FACET_TOTALDIGITS) == 0) { 984 reportError("cos-applicable-facets", new Object []{"totalDigits", fTypeName}); 985 } else { 986 totalDigitsAnnotation = facets.totalDigitsAnnotation; 987 fTotalDigits = facets.totalDigits; 988 fFacetsDefined |= FACET_TOTALDIGITS; 989 if ((fixedFacet & FACET_TOTALDIGITS) != 0) 990 fFixedFacet |= FACET_TOTALDIGITS; 991 } 992 } 993 if ((presentFacet & FACET_FRACTIONDIGITS) != 0) { 995 if ((allowedFacet & FACET_FRACTIONDIGITS) == 0) { 996 reportError("cos-applicable-facets", new Object []{"fractionDigits", fTypeName}); 997 } else { 998 fFractionDigits = facets.fractionDigits; 999 fractionDigitsAnnotation = facets.fractionDigitsAnnotation; 1000 fFacetsDefined |= FACET_FRACTIONDIGITS; 1001 if ((fixedFacet & FACET_FRACTIONDIGITS) != 0) 1002 fFixedFacet |= FACET_FRACTIONDIGITS; 1003 } 1004 } 1005 1006 if (patternType != SPECIAL_PATTERN_NONE) { 1008 fPatternType = patternType; 1009 } 1010 1011 if(fFacetsDefined != 0) { 1013 1014 if((fFacetsDefined & FACET_LENGTH) != 0 ){ 1016 if ((fFacetsDefined & FACET_MINLENGTH) != 0) { 1017 if ((fFacetsDefined & FACET_MAXLENGTH) != 0) { 1018 reportError("length-minLength-maxLength.a", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMinLength), Integer.toString(fMaxLength)}); 1020 } 1021 else { 1022 reportError("length-minLength-maxLength.b", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMinLength)}); 1024 } 1025 } 1026 else if ((fFacetsDefined & FACET_MAXLENGTH) != 0) { 1027 reportError("length-minLength-maxLength.c", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMaxLength)}); 1029 } 1030 } 1031 1032 if(((fFacetsDefined & FACET_MINLENGTH ) != 0 ) && ((fFacetsDefined & FACET_MAXLENGTH) != 0)) 1034 { 1035 if(fMinLength > fMaxLength) 1036 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fMinLength), Integer.toString(fMaxLength), fTypeName}); 1037 } 1038 1039 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1041 reportError( "maxInclusive-maxExclusive", new Object []{fMaxInclusive, fMaxExclusive, fTypeName}); 1042 } 1043 1044 if (((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1046 reportError("minInclusive-minExclusive", new Object []{fMinInclusive, fMinExclusive, fTypeName}); 1047 } 1048 1049 if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1051 result = fDVs[fValidationDV].compare(fMinInclusive, fMaxInclusive); 1052 if (result != -1 && result != 0) 1053 reportError("minInclusive-less-than-equal-to-maxInclusive", new Object []{fMinInclusive, fMaxInclusive, fTypeName}); 1054 } 1055 1056 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 1058 result = fDVs[fValidationDV].compare(fMinExclusive, fMaxExclusive); 1059 if (result != -1 && result != 0) 1060 reportError( "minExclusive-less-than-equal-to-maxExclusive", new Object []{fMinExclusive, fMaxExclusive, fTypeName}); 1061 } 1062 1063 if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 1065 if (fDVs[fValidationDV].compare(fMinExclusive, fMaxInclusive) != -1) 1066 reportError( "minExclusive-less-than-maxInclusive", new Object []{fMinExclusive, fMaxInclusive, fTypeName}); 1067 } 1068 1069 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1071 if (fDVs[fValidationDV].compare(fMinInclusive, fMaxExclusive) != -1) 1072 reportError( "minInclusive-less-than-maxExclusive", new Object []{fMinInclusive, fMaxExclusive, fTypeName}); 1073 } 1074 1075 if (((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) && 1077 ((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1078 if (fFractionDigits > fTotalDigits) 1079 reportError( "fractionDigits-totalDigits", new Object []{Integer.toString(fFractionDigits), Integer.toString(fTotalDigits), fTypeName}); 1080 } 1081 1082 if((fFacetsDefined & FACET_LENGTH) != 0 ){ 1085 if ((fBase.fFacetsDefined & FACET_MINLENGTH) != 0 && 1086 fLength < fBase.fMinLength) { 1087 reportError("length-minLength-maxLength.d", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fBase.fMinLength)}); 1089 } 1090 if ((fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 && 1091 fLength > fBase.fMaxLength) { 1092 reportError("length-minLength-maxLength.e", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fBase.fMaxLength)}); 1094 } 1095 if ( (fBase.fFacetsDefined & FACET_LENGTH) != 0 ) { 1096 if ( fLength != fBase.fLength ) 1098 reportError( "length-valid-restriction", new Object []{Integer.toString(fLength), Integer.toString(fBase.fLength), fTypeName}); 1099 } 1100 } 1101 1102 else if((fBase.fFacetsDefined & FACET_LENGTH) != 0 ){ 1104 if ((fFacetsDefined & FACET_MINLENGTH) != 0 && 1105 fBase.fLength < fMinLength) { 1106 reportError("length-minLength-maxLength.d", new Object []{fTypeName, Integer.toString(fBase.fLength), Integer.toString(fMinLength)}); 1108 } 1109 if ((fFacetsDefined & FACET_MAXLENGTH) != 0 && 1110 fBase.fLength > fMaxLength) { 1111 reportError("length-minLength-maxLength.e", new Object []{this, Integer.toString(fBase.fLength), Integer.toString(fMaxLength)}); 1113 } 1114 } 1115 1116 if ( ((fFacetsDefined & FACET_MINLENGTH ) != 0 ) ) { 1118 if ( (fBase.fFacetsDefined & FACET_MAXLENGTH ) != 0 ) { 1119 if ( fMinLength > fBase.fMaxLength ) { 1120 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fMinLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1121 } 1122 } 1123 else if ( (fBase.fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1124 if ( (fBase.fFixedFacet & FACET_MINLENGTH) != 0 && fMinLength != fBase.fMinLength ) { 1125 reportError( "FixedFacetValue", new Object []{"minLength", Integer.toString(fMinLength), Integer.toString(fBase.fMinLength), fTypeName}); 1126 } 1127 1128 if ( fMinLength < fBase.fMinLength ) { 1130 reportError( "minLength-valid-restriction", new Object []{Integer.toString(fMinLength), Integer.toString(fBase.fMinLength), fTypeName}); 1131 } 1132 } 1133 } 1134 1135 1136 if ( ((fFacetsDefined & FACET_MAXLENGTH ) != 0 ) && ((fBase.fFacetsDefined & FACET_MINLENGTH ) != 0 )) { 1138 if ( fMaxLength < fBase.fMinLength) { 1139 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fBase.fMinLength), Integer.toString(fMaxLength)}); 1140 } 1141 } 1142 1143 if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1145 if ( (fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 ){ 1146 if(( (fBase.fFixedFacet & FACET_MAXLENGTH) != 0 )&& fMaxLength != fBase.fMaxLength ) { 1147 reportError( "FixedFacetValue", new Object []{"maxLength", Integer.toString(fMaxLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1148 } 1149 if ( fMaxLength > fBase.fMaxLength ) { 1150 reportError( "maxLength-valid-restriction", new Object []{Integer.toString(fMaxLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1151 } 1152 } 1153 } 1154 1155 1287 if (((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1289 if ((( fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1290 if ((fBase.fFixedFacet & FACET_TOTALDIGITS) != 0 && fTotalDigits != fBase.fTotalDigits) { 1291 reportError("FixedFacetValue", new Object []{"totalDigits", Integer.toString(fTotalDigits), Integer.toString(fBase.fTotalDigits), fTypeName}); 1292 } 1293 if (fTotalDigits > fBase.fTotalDigits) { 1294 reportError( "totalDigits-valid-restriction", new Object []{Integer.toString(fTotalDigits), Integer.toString(fBase.fTotalDigits), fTypeName}); 1295 } 1296 } 1297 } 1298 1299 if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) { 1301 if ((fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0) { 1302 if (fFractionDigits > fBase.fTotalDigits) 1303 reportError( "fractionDigits-totalDigits", new Object []{Integer.toString(fFractionDigits), Integer.toString(fTotalDigits), fTypeName}); 1304 } 1305 } 1306 1307 if (((fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1310 if ((( fBase.fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1311 if ((fBase.fFixedFacet & FACET_FRACTIONDIGITS) != 0 && fFractionDigits != fBase.fFractionDigits) { 1312 reportError("FixedFacetValue", new Object []{"fractionDigits", Integer.toString(fFractionDigits), Integer.toString(fBase.fFractionDigits), fTypeName}); 1313 } 1314 if (fFractionDigits > fBase.fFractionDigits) { 1315 reportError( "fractionDigits-valid-restriction", new Object []{Integer.toString(fFractionDigits), Integer.toString(fBase.fFractionDigits), fTypeName}); 1316 } 1317 } 1318 } 1319 1320 1324 if ( (fFacetsDefined & FACET_WHITESPACE) != 0 && (fBase.fFacetsDefined & FACET_WHITESPACE) != 0 ){ 1325 if ( (fBase.fFixedFacet & FACET_WHITESPACE) != 0 && fWhiteSpace != fBase.fWhiteSpace ) { 1326 reportError( "FixedFacetValue", new Object []{"whiteSpace", whiteSpaceValue(fWhiteSpace), whiteSpaceValue(fBase.fWhiteSpace), fTypeName}); 1327 } 1328 1329 if ( fWhiteSpace == WS_PRESERVE && fBase.fWhiteSpace == WS_COLLAPSE ){ 1330 reportError( "whiteSpace-valid-restriction.1", new Object []{fTypeName, "preserve"}); 1331 } 1332 if ( fWhiteSpace == WS_REPLACE && fBase.fWhiteSpace == WS_COLLAPSE ){ 1333 reportError( "whiteSpace-valid-restriction.1", new Object []{fTypeName, "replace"}); 1334 } 1335 if ( fWhiteSpace == WS_PRESERVE && fBase.fWhiteSpace == WS_REPLACE ){ 1336 reportError( "whiteSpace-valid-restriction.2", new Object []{fTypeName}); 1337 } 1338 } 1339 } 1341 1343 if ( (fFacetsDefined & FACET_LENGTH) == 0 && (fBase.fFacetsDefined & FACET_LENGTH) != 0 ) { 1345 fFacetsDefined |= FACET_LENGTH; 1346 fLength = fBase.fLength; 1347 lengthAnnotation = fBase.lengthAnnotation; 1348 } 1349 if ( (fFacetsDefined & FACET_MINLENGTH) == 0 && (fBase.fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1351 fFacetsDefined |= FACET_MINLENGTH; 1352 fMinLength = fBase.fMinLength; 1353 minLengthAnnotation = fBase.minLengthAnnotation; 1354 } 1355 if ((fFacetsDefined & FACET_MAXLENGTH) == 0 && (fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1357 fFacetsDefined |= FACET_MAXLENGTH; 1358 fMaxLength = fBase.fMaxLength; 1359 maxLengthAnnotation = fBase.maxLengthAnnotation; 1360 } 1361 if ( (fBase.fFacetsDefined & FACET_PATTERN) != 0 ) { 1363 if ((fFacetsDefined & FACET_PATTERN) == 0) { 1364 fPattern = fBase.fPattern; 1365 fPatternStr = fBase.fPatternStr; 1366 fFacetsDefined |= FACET_PATTERN; 1367 } 1368 else { 1369 for (int i = fBase.fPattern.size()-1; i >= 0; i--) { 1370 fPattern.addElement(fBase.fPattern.elementAt(i)); 1371 fPatternStr.addElement(fBase.fPatternStr.elementAt(i)); 1372 } 1373 if (fBase.patternAnnotations != null){ 1374 for (int i = fBase.patternAnnotations.getLength()-1;i>=0;i--){ 1375 patternAnnotations.add(fBase.patternAnnotations.item(i)); 1376 } 1377 } 1378 } 1379 } 1380 if ( (fFacetsDefined & FACET_WHITESPACE) == 0 && (fBase.fFacetsDefined & FACET_WHITESPACE) != 0 ) { 1382 fFacetsDefined |= FACET_WHITESPACE; 1383 fWhiteSpace = fBase.fWhiteSpace; 1384 whiteSpaceAnnotation = fBase.whiteSpaceAnnotation; 1385 } 1386 if ((fFacetsDefined & FACET_ENUMERATION) == 0 && (fBase.fFacetsDefined & FACET_ENUMERATION) != 0) { 1388 fFacetsDefined |= FACET_ENUMERATION; 1389 fEnumeration = fBase.fEnumeration; 1390 enumerationAnnotations = fBase.enumerationAnnotations; 1391 } 1392 if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && 1394 !((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1395 fFacetsDefined |= FACET_MAXEXCLUSIVE; 1396 fMaxExclusive = fBase.fMaxExclusive; 1397 maxExclusiveAnnotation = fBase.maxExclusiveAnnotation; 1398 } 1399 if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && 1401 !((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1402 fFacetsDefined |= FACET_MAXINCLUSIVE; 1403 fMaxInclusive = fBase.fMaxInclusive; 1404 maxInclusiveAnnotation = fBase.maxInclusiveAnnotation; 1405 } 1406 if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && 1408 !((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1409 fFacetsDefined |= FACET_MINEXCLUSIVE; 1410 fMinExclusive = fBase.fMinExclusive; 1411 minExclusiveAnnotation = fBase.minExclusiveAnnotation; 1412 } 1413 if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0) && 1415 !((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1416 fFacetsDefined |= FACET_MININCLUSIVE; 1417 fMinInclusive = fBase.fMinInclusive; 1418 minInclusiveAnnotation = fBase.minInclusiveAnnotation; 1419 } 1420 if ((( fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0) && 1422 !((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1423 fFacetsDefined |= FACET_TOTALDIGITS; 1424 fTotalDigits = fBase.fTotalDigits; 1425 totalDigitsAnnotation = fBase.totalDigitsAnnotation; 1426 } 1427 if ((( fBase.fFacetsDefined & FACET_FRACTIONDIGITS) != 0) 1429 && !((fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1430 fFacetsDefined |= FACET_FRACTIONDIGITS; 1431 fFractionDigits = fBase.fFractionDigits; 1432 fractionDigitsAnnotation = fBase.fractionDigitsAnnotation; 1433 } 1434 if ((fPatternType == SPECIAL_PATTERN_NONE ) && (fBase.fPatternType != SPECIAL_PATTERN_NONE)) { 1436 fPatternType = fBase.fPatternType ; 1437 } 1438 1439 fFixedFacet |= fBase.fFixedFacet; 1441 1442 caclFundamentalFacets(); 1444 1445 } 1447 1450 public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1451 1452 if (context == null) 1453 context = fEmptyContext; 1454 1455 if (validatedInfo == null) 1456 validatedInfo = new ValidatedInfo(); 1457 else 1458 validatedInfo.memberType = null; 1459 1460 boolean needNormalize = context==null||context.needToNormalize(); 1462 Object ob = getActualValue(content, context, validatedInfo, needNormalize); 1463 1464 validate(context, validatedInfo); 1465 1466 return ob; 1467 1468 } 1469 1470 1473 public Object validate(Object content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1474 1475 if (context == null) 1476 context = fEmptyContext; 1477 1478 if (validatedInfo == null) 1479 validatedInfo = new ValidatedInfo(); 1480 else 1481 validatedInfo.memberType = null; 1482 1483 boolean needNormalize = context==null||context.needToNormalize(); 1485 Object ob = getActualValue(content, context, validatedInfo, needNormalize); 1486 1487 validate(context, validatedInfo); 1488 1489 return ob; 1490 1491 } 1492 1493 1500 public void validate(ValidationContext context, ValidatedInfo validatedInfo) 1501 throws InvalidDatatypeValueException { 1502 1503 if (context == null) 1504 context = fEmptyContext; 1505 1506 if (context.needFacetChecking() && 1508 (fFacetsDefined != 0 && fFacetsDefined != FACET_WHITESPACE)) { 1509 checkFacets(validatedInfo); 1510 } 1511 1512 if (context.needExtraChecking()) { 1514 checkExtraRules(context, validatedInfo); 1515 } 1516 1517 } 1518 1519 private void checkFacets(ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1520 1521 Object ob = validatedInfo.actualValue; 1522 String content = validatedInfo.normalizedValue; 1523 1524 if (fValidationDV != DV_QNAME && fValidationDV != DV_NOTATION) { 1526 int length = fDVs[fValidationDV].getDataLength(ob); 1527 1528 if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1530 if ( length > fMaxLength ) { 1531 throw new InvalidDatatypeValueException("cvc-maxLength-valid", 1532 new Object []{content, Integer.toString(length), Integer.toString(fMaxLength), fTypeName}); 1533 } 1534 } 1535 1536 if ( (fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1538 if ( length < fMinLength ) { 1539 throw new InvalidDatatypeValueException("cvc-minLength-valid", 1540 new Object []{content, Integer.toString(length), Integer.toString(fMinLength), fTypeName}); 1541 } 1542 } 1543 1544 if ( (fFacetsDefined & FACET_LENGTH) != 0 ) { 1546 if ( length != fLength ) { 1547 throw new InvalidDatatypeValueException("cvc-length-valid", 1548 new Object []{content, Integer.toString(length), Integer.toString(fLength), fTypeName}); 1549 } 1550 } 1551 } 1552 1553 if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) { 1555 boolean present = false; 1556 for (int i = 0; i < fEnumeration.size(); i++) { 1557 if (fEnumeration.elementAt(i).equals(ob)) { 1558 present = true; 1559 break; 1560 } 1561 } 1562 if(!present){ 1563 throw new InvalidDatatypeValueException("cvc-enumeration-valid", 1564 new Object [] {content, fEnumeration.toString()}); 1565 } 1566 } 1567 1568 if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) { 1570 int scale = fDVs[fValidationDV].getFractionDigits(ob); 1571 if (scale > fFractionDigits) { 1572 throw new InvalidDatatypeValueException("cvc-fractionDigits-valid", 1573 new Object [] {content, Integer.toString(scale), Integer.toString(fFractionDigits)}); 1574 } 1575 } 1576 1577 if ((fFacetsDefined & FACET_TOTALDIGITS)!=0) { 1579 int totalDigits = fDVs[fValidationDV].getTotalDigits(ob); 1580 if (totalDigits > fTotalDigits) { 1581 throw new InvalidDatatypeValueException("cvc-totalDigits-valid", 1582 new Object [] {content, Integer.toString(totalDigits), Integer.toString(fTotalDigits)}); 1583 } 1584 } 1585 1586 int compare; 1587 1588 if ( (fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) { 1590 compare = fDVs[fValidationDV].compare(ob, fMaxInclusive); 1591 if (compare != -1 && compare != 0) { 1592 throw new InvalidDatatypeValueException("cvc-maxInclusive-valid", 1593 new Object [] {content, fMaxInclusive, fTypeName}); 1594 } 1595 } 1596 1597 if ( (fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 ) { 1599 compare = fDVs[fValidationDV].compare(ob, fMaxExclusive ); 1600 if (compare != -1) { 1601 throw new InvalidDatatypeValueException("cvc-maxExclusive-valid", 1602 new Object [] {content, fMaxExclusive, fTypeName}); 1603 } 1604 } 1605 1606 if ( (fFacetsDefined & FACET_MININCLUSIVE) != 0 ) { 1608 compare = fDVs[fValidationDV].compare(ob, fMinInclusive); 1609 if (compare != 1 && compare != 0) { 1610 throw new InvalidDatatypeValueException("cvc-minInclusive-valid", 1611 new Object [] {content, fMinInclusive, fTypeName}); 1612 } 1613 } 1614 1615 if ( (fFacetsDefined & FACET_MINEXCLUSIVE) != 0 ) { 1617 compare = fDVs[fValidationDV].compare(ob, fMinExclusive); 1618 if (compare != 1) { 1619 throw new InvalidDatatypeValueException("cvc-minExclusive-valid", 1620 new Object [] {content, fMinExclusive, fTypeName}); 1621 } 1622 } 1623 1624 } 1625 1626 private void checkExtraRules(ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1627 1628 Object ob = validatedInfo.actualValue; 1629 1630 if (fVariety == VARIETY_ATOMIC) { 1631 1632 fDVs[fValidationDV].checkExtraRules(ob, context); 1633 1634 } else if (fVariety == VARIETY_LIST) { 1635 1636 ListDV.ListData values = (ListDV.ListData)ob; 1637 int len = values.length(); 1638 if (fItemType.fVariety == VARIETY_UNION) { 1639 XSSimpleTypeDecl[] memberTypes = (XSSimpleTypeDecl[])validatedInfo.memberTypes; 1640 XSSimpleType memberType = validatedInfo.memberType; 1641 for (int i = len-1; i >= 0; i--) { 1642 validatedInfo.actualValue = values.item(i); 1643 validatedInfo.memberType = memberTypes[i]; 1644 fItemType.checkExtraRules(context, validatedInfo); 1645 } 1646 validatedInfo.memberType = memberType; 1647 } else { for (int i = len-1; i >= 0; i--) { 1649 validatedInfo.actualValue = values.item(i); 1650 fItemType.checkExtraRules(context, validatedInfo); 1651 } 1652 } 1653 validatedInfo.actualValue = values; 1654 1655 } else { 1657 ((XSSimpleTypeDecl)validatedInfo.memberType).checkExtraRules(context, validatedInfo); 1658 1659 } 1660 1661 } 1663 private Object getActualValue(Object content, ValidationContext context, 1665 ValidatedInfo validatedInfo, boolean needNormalize) 1666 throws InvalidDatatypeValueException{ 1667 1668 String nvalue; 1669 if (needNormalize) { 1670 nvalue = normalize(content, fWhiteSpace); 1671 } else { 1672 nvalue = content.toString(); 1673 } 1674 if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) { 1675 RegularExpression regex; 1676 for (int idx = fPattern.size()-1; idx >= 0; idx--) { 1677 regex = (RegularExpression)fPattern.elementAt(idx); 1678 if (!regex.matches(nvalue)){ 1679 throw new InvalidDatatypeValueException("cvc-pattern-valid", 1680 new Object []{content, 1681 fPatternStr.elementAt(idx), 1682 1683 fTypeName}); 1684 } 1685 } 1686 } 1687 1688 if (fVariety == VARIETY_ATOMIC) { 1689 1690 if (fPatternType != SPECIAL_PATTERN_NONE) { 1692 1693 boolean seenErr = false; 1694 if (fPatternType == SPECIAL_PATTERN_NMTOKEN) { 1695 seenErr = !XMLChar.isValidNmtoken(nvalue); 1697 } 1698 else if (fPatternType == SPECIAL_PATTERN_NAME) { 1699 seenErr = !XMLChar.isValidName(nvalue); 1701 } 1702 else if (fPatternType == SPECIAL_PATTERN_NCNAME) { 1703 seenErr = !XMLChar.isValidNCName(nvalue); 1705 } 1706 if (seenErr) { 1707 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", 1708 new Object []{nvalue, SPECIAL_PATTERN_STRING[fPatternType]}); 1709 } 1710 } 1711 1712 validatedInfo.normalizedValue = nvalue; 1713 Object avalue = fDVs[fValidationDV].getActualValue(nvalue, context); 1714 validatedInfo.actualValue = avalue; 1715 validatedInfo.actualValueType = fBuiltInKind; 1716 1717 return avalue; 1718 1719 } else if (fVariety == VARIETY_LIST) { 1720 1721 StringTokenizer parsedList = new StringTokenizer (nvalue, " "); 1722 int countOfTokens = parsedList.countTokens() ; 1723 Object [] avalue = new Object [countOfTokens]; 1724 boolean isUnion = fItemType.getVariety() == VARIETY_UNION; 1725 short[] itemTypes = new short[isUnion ? countOfTokens : 1]; 1726 if (!isUnion) 1727 itemTypes[0] = fItemType.fBuiltInKind; 1728 XSSimpleTypeDecl[] memberTypes = new XSSimpleTypeDecl[countOfTokens]; 1729 for(int i = 0 ; i < countOfTokens ; i ++){ 1730 avalue[i] = fItemType.getActualValue(parsedList.nextToken(), context, validatedInfo, false); 1737 if (context.needFacetChecking() && 1738 (fItemType.fFacetsDefined != 0 && fItemType.fFacetsDefined != FACET_WHITESPACE)) { 1739 fItemType.checkFacets(validatedInfo); 1740 } 1741 memberTypes[i] = (XSSimpleTypeDecl)validatedInfo.memberType; 1742 if (isUnion) 1743 itemTypes[i] = memberTypes[i].fBuiltInKind; 1744 } 1745 1746 ListDV.ListData v = new ListDV.ListData(avalue); 1747 validatedInfo.actualValue = v; 1748 validatedInfo.actualValueType = isUnion ? XSConstants.LISTOFUNION_DT : XSConstants.LIST_DT; 1749 validatedInfo.memberType = null; 1750 validatedInfo.memberTypes = memberTypes; 1751 validatedInfo.itemValueTypes = new ShortListImpl(itemTypes, itemTypes.length); 1752 validatedInfo.normalizedValue = nvalue; 1753 1754 return v; 1755 1756 } else { for(int i = 0 ; i < fMemberTypes.length; i++) { 1758 try { 1759 Object aValue = fMemberTypes[i].getActualValue(content, context, validatedInfo, true); 1766 if (context.needFacetChecking() && 1767 (fMemberTypes[i].fFacetsDefined != 0 && fMemberTypes[i].fFacetsDefined != FACET_WHITESPACE)) { 1768 fMemberTypes[i].checkFacets(validatedInfo); 1769 } 1770 validatedInfo.memberType = fMemberTypes[i]; 1771 return aValue; 1772 } catch(InvalidDatatypeValueException invalidValue) { 1773 } 1774 } 1775 1776 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.2", 1777 new Object []{content, fTypeName}); 1778 } 1779 1780 } 1782 public boolean isEqual(Object value1, Object value2) { 1783 if (value1 == null) 1784 return false; 1785 return value1.equals(value2); 1786 } 1788 public static String normalize(String content, short ws) { 1790 int len = content == null ? 0 : content.length(); 1791 if (len == 0 || ws == WS_PRESERVE) 1792 return content; 1793 1794 StringBuffer sb = new StringBuffer (); 1795 if (ws == WS_REPLACE) { 1796 char ch; 1797 for (int i = 0; i < len; i++) { 1799 ch = content.charAt(i); 1800 if (ch != 0x9 && ch != 0xa && ch != 0xd) 1801 sb.append(ch); 1802 else 1803 sb.append((char)0x20); 1804 } 1805 } else { 1806 char ch; 1807 int i; 1808 boolean isLeading = true; 1809 for (i = 0; i < len; i++) { 1811 ch = content.charAt(i); 1812 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { 1814 sb.append(ch); 1815 isLeading = false; 1816 } 1817 else { 1818 for (; i < len-1; i++) { 1820 ch = content.charAt(i+1); 1821 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) 1822 break; 1823 } 1824 if (i < len - 1 && !isLeading) 1826 sb.append((char)0x20); 1827 } 1828 } 1829 } 1830 1831 return sb.toString(); 1832 } 1833 1834 protected String normalize(Object content, short ws) { 1836 if (content == null) 1837 return null; 1838 1839 if ( (fFacetsDefined & FACET_PATTERN ) == 0 ) { 1843 short norm_type = fDVNormalizeType[fValidationDV]; 1844 if (norm_type == NORMALIZE_NONE) { 1845 return content.toString(); 1846 } 1847 else if (norm_type == NORMALIZE_TRIM) { 1848 return content.toString().trim(); 1849 } 1850 } 1851 1852 if (!(content instanceof StringBuffer )) { 1853 String strContent = content.toString(); 1854 return normalize(strContent, ws); 1855 } 1856 1857 StringBuffer sb = (StringBuffer )content; 1858 int len = sb.length(); 1859 if (len == 0) 1860 return ""; 1861 if (ws == WS_PRESERVE) 1862 return sb.toString(); 1863 1864 if (ws == WS_REPLACE) { 1865 char ch; 1866 for (int i = 0; i < len; i++) { 1868 ch = sb.charAt(i); 1869 if (ch == 0x9 || ch == 0xa || ch == 0xd) 1870 sb.setCharAt(i, (char)0x20); 1871 } 1872 } else { 1873 char ch; 1874 int i, j = 0; 1875 boolean isLeading = true; 1876 for (i = 0; i < len; i++) { 1878 ch = sb.charAt(i); 1879 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { 1881 sb.setCharAt(j++, ch); 1882 isLeading = false; 1883 } 1884 else { 1885 for (; i < len-1; i++) { 1887 ch = sb.charAt(i+1); 1888 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) 1889 break; 1890 } 1891 if (i < len - 1 && !isLeading) 1893 sb.setCharAt(j++, (char)0x20); 1894 } 1895 } 1896 sb.setLength(j); 1897 } 1898 1899 return sb.toString(); 1900 } 1901 1902 void reportError(String key, Object [] args) throws InvalidDatatypeFacetException { 1903 throw new InvalidDatatypeFacetException(key, args); 1904 } 1905 1906 1907 private String whiteSpaceValue(short ws){ 1908 return WS_FACET_STRING[ws]; 1909 } 1910 1911 public short getOrdered() { 1912 return fOrdered; 1913 } 1914 1915 public boolean getBounded(){ 1916 return fBounded; 1917 } 1918 1919 public boolean getFinite(){ 1920 return fFinite; 1921 } 1922 1923 public boolean getNumeric(){ 1924 return fNumeric; 1925 } 1926 1927 public boolean isDefinedFacet(short facetName) { 1928 if ((fFacetsDefined & facetName) != 0) 1929 return true; 1930 if (fPatternType != SPECIAL_PATTERN_NONE) 1931 return facetName == FACET_PATTERN; 1932 if (fValidationDV == DV_INTEGER) 1933 return facetName == FACET_PATTERN || facetName == FACET_FRACTIONDIGITS; 1934 return false; 1935 } 1936 1937 public short getDefinedFacets() { 1938 if (fPatternType != SPECIAL_PATTERN_NONE) 1939 return (short)(fFacetsDefined | FACET_PATTERN); 1940 if (fValidationDV == DV_INTEGER) 1941 return (short)(fFacetsDefined | FACET_PATTERN | FACET_FRACTIONDIGITS); 1942 return fFacetsDefined; 1943 } 1944 1945 public boolean isFixedFacet(short facetName) { 1946 if ((fFixedFacet & facetName) != 0) 1947 return true; 1948 if (fValidationDV == DV_INTEGER) 1949 return facetName == FACET_FRACTIONDIGITS; 1950 return false; 1951 } 1952 1953 public short getFixedFacets() { 1954 if (fValidationDV == DV_INTEGER) 1955 return (short)(fFixedFacet | FACET_FRACTIONDIGITS); 1956 return fFixedFacet; 1957 } 1958 1959 public String getLexicalFacetValue(short facetName) { 1960 switch (facetName) { 1961 case FACET_LENGTH: 1962 return (fLength == -1)?null:Integer.toString(fLength); 1963 case FACET_MINLENGTH: 1964 return (fMinLength == -1)?null:Integer.toString(fMinLength); 1965 case FACET_MAXLENGTH: 1966 return (fMaxLength == -1)?null:Integer.toString(fMaxLength); 1967 case FACET_WHITESPACE: 1968 return WS_FACET_STRING[fWhiteSpace]; 1969 case FACET_MAXINCLUSIVE: 1970 return (fMaxInclusive == null)?null:fMaxInclusive.toString(); 1971 case FACET_MAXEXCLUSIVE: 1972 return (fMaxExclusive == null)?null:fMaxExclusive.toString(); 1973 case FACET_MINEXCLUSIVE: 1974 return (fMinExclusive == null)?null:fMinExclusive.toString(); 1975 case FACET_MININCLUSIVE: 1976 return (fMinInclusive == null)?null:fMinInclusive.toString(); 1977 case FACET_TOTALDIGITS: 1978 if (fValidationDV == DV_INTEGER) 1979 return "0"; 1980 return (fTotalDigits == -1)?null:Integer.toString(fTotalDigits); 1981 case FACET_FRACTIONDIGITS: 1982 return (fFractionDigits == -1)?null:Integer.toString(fFractionDigits); 1983 } 1984 return null; 1985 } 1986 1987 public StringList getLexicalEnumeration() { 1988 if (fLexicalEnumeration == null){ 1989 if (fEnumeration == null) 1990 return null; 1991 int size = fEnumeration.size(); 1992 String [] strs = new String [size]; 1993 for (int i = 0; i < size; i++) 1994 strs[i] = fEnumeration.elementAt(i).toString(); 1995 fLexicalEnumeration = new StringListImpl(strs, size); 1996 } 1997 return fLexicalEnumeration; 1998 } 1999 2000 public StringList getLexicalPattern() { 2001 if (fPatternType == SPECIAL_PATTERN_NONE && fValidationDV != DV_INTEGER && fPatternStr == null) 2002 return null; 2003 if (fLexicalPattern == null){ 2004 int size = fPatternStr == null ? 0 : fPatternStr.size(); 2005 String [] strs; 2006 if (fPatternType == SPECIAL_PATTERN_NMTOKEN) { 2007 strs = new String [size+1]; 2008 strs[size] = "\\c+"; 2009 } 2010 else if (fPatternType == SPECIAL_PATTERN_NAME) { 2011 strs = new String [size+1]; 2012 strs[size] = "\\i\\c*"; 2013 } 2014 else if (fPatternType == SPECIAL_PATTERN_NCNAME) { 2015 strs = new String [size+2]; 2016 strs[size] = "\\i\\c*"; 2017 strs[size+1] = "[\\i-[:]][\\c-[:]]*"; 2018 } 2019 else if (fValidationDV == DV_INTEGER) { 2020 strs = new String [size+1]; 2021 strs[size] = "[+\\-]?[0-9]+"; 2022 } 2023 else { 2024 strs = new String [size]; 2025 } 2026 for (int i = 0; i < size; i++) 2027 strs[i] = (String )fPatternStr.elementAt(i); 2028 fLexicalPattern = new StringListImpl(strs, size); 2029 } 2030 return fLexicalPattern; 2031 } 2032 2033 public XSObjectList getAnnotations() { 2034 return fAnnotations; 2035 } 2036 2037 private void caclFundamentalFacets() { 2038 setOrdered(); 2039 setNumeric(); 2040 setBounded(); 2041 setCardinality(); 2042 } 2043 2044 private void setOrdered(){ 2045 2046 if(fVariety == VARIETY_ATOMIC){ 2048 this.fOrdered = fBase.fOrdered; 2049 } 2050 2051 else if(fVariety == VARIETY_LIST){ 2053 this.fOrdered = ORDERED_FALSE; 2054 } 2055 2056 else if(fVariety == VARIETY_UNION){ 2060 int length = fMemberTypes.length; 2061 if (length == 0) { 2063 this.fOrdered = ORDERED_PARTIAL; 2064 return; 2065 } 2066 short ancestorId = getPrimitiveDV(fMemberTypes[0].fValidationDV); 2068 boolean commonAnc = ancestorId != DV_ANYSIMPLETYPE; 2069 boolean allFalse = fMemberTypes[0].fOrdered == ORDERED_FALSE; 2070 for (int i = 1; i < fMemberTypes.length && (commonAnc || allFalse); i++) { 2073 if (commonAnc) 2074 commonAnc = ancestorId == getPrimitiveDV(fMemberTypes[i].fValidationDV); 2075 if (allFalse) 2076 allFalse = fMemberTypes[i].fOrdered == ORDERED_FALSE; 2077 } 2078 if (commonAnc) { 2079 this.fOrdered = fMemberTypes[0].fOrdered; 2082 } else if (allFalse) { 2083 this.fOrdered = ORDERED_FALSE; 2084 } else { 2085 this.fOrdered = ORDERED_PARTIAL; 2086 } 2087 } 2088 2089 } 2091 private void setNumeric(){ 2092 if(fVariety == VARIETY_ATOMIC){ 2093 this.fNumeric = fBase.fNumeric; 2094 } 2095 else if(fVariety == VARIETY_LIST){ 2096 this.fNumeric = false; 2097 } 2098 else if(fVariety == VARIETY_UNION){ 2099 XSSimpleType[] memberTypes = fMemberTypes; 2100 for(int i = 0 ; i < memberTypes.length ; i++){ 2101 if(!memberTypes[i].getNumeric() ){ 2102 this.fNumeric = false; 2103 return; 2104 } 2105 } 2106 this.fNumeric = true; 2107 } 2108 2109 } 2111 private void setBounded(){ 2112 if(fVariety == VARIETY_ATOMIC){ 2113 if( (((this.fFacetsDefined & FACET_MININCLUSIVE) != 0) || ((this.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) 2114 && (((this.fFacetsDefined & FACET_MAXINCLUSIVE) != 0) || ((this.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) ){ 2115 this.fBounded = true; 2116 } 2117 else{ 2118 this.fBounded = false; 2119 } 2120 } 2121 else if(fVariety == VARIETY_LIST){ 2122 if( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ( ((this.fFacetsDefined & FACET_MINLENGTH) != 0 ) 2123 && ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 )) ){ 2124 this.fBounded = true; 2125 } 2126 else{ 2127 this.fBounded = false; 2128 } 2129 2130 } 2131 else if(fVariety == VARIETY_UNION){ 2132 2133 XSSimpleTypeDecl [] memberTypes = this.fMemberTypes; 2134 short ancestorId = 0 ; 2135 2136 if(memberTypes.length > 0){ 2137 ancestorId = getPrimitiveDV(memberTypes[0].fValidationDV); 2138 } 2139 2140 for(int i = 0 ; i < memberTypes.length ; i++){ 2141 if(!memberTypes[i].getBounded() || (ancestorId != getPrimitiveDV(memberTypes[i].fValidationDV)) ){ 2142 this.fBounded = false; 2143 return; 2144 } 2145 } 2146 this.fBounded = true; 2147 } 2148 2149 } 2151 private boolean specialCardinalityCheck(){ 2152 if( (fBase.fValidationDV == XSSimpleTypeDecl.DV_DATE) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GYEARMONTH) 2153 || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GYEAR) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GMONTHDAY) 2154 || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GDAY) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GMONTH) ){ 2155 return true; 2156 } 2157 return false; 2158 2159 } 2161 private void setCardinality(){ 2162 if(fVariety == VARIETY_ATOMIC){ 2163 if(fBase.fFinite){ 2164 this.fFinite = true; 2165 } 2166 else { if ( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 ) 2168 || ((this.fFacetsDefined & FACET_TOTALDIGITS) != 0 ) ){ 2169 this.fFinite = true; 2170 } 2171 else if( (((this.fFacetsDefined & FACET_MININCLUSIVE) != 0 ) || ((this.fFacetsDefined & FACET_MINEXCLUSIVE) != 0 )) 2172 && (((this.fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) || ((this.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 )) ){ 2173 if( ((this.fFacetsDefined & FACET_FRACTIONDIGITS) != 0 ) || specialCardinalityCheck()){ 2174 this.fFinite = true; 2175 } 2176 else{ 2177 this.fFinite = false; 2178 } 2179 } 2180 else{ 2181 this.fFinite = false; 2182 } 2183 } 2184 } 2185 else if(fVariety == VARIETY_LIST){ 2186 if( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ( ((this.fFacetsDefined & FACET_MINLENGTH) != 0 ) 2187 && ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 )) ){ 2188 this.fFinite = true; 2189 } 2190 else{ 2191 this.fFinite = false; 2192 } 2193 2194 } 2195 else if(fVariety == VARIETY_UNION){ 2196 XSSimpleType [] memberTypes = fMemberTypes; 2197 for(int i = 0 ; i < memberTypes.length ; i++){ 2198 if(!(memberTypes[i].getFinite()) ){ 2199 this.fFinite = false; 2200 return; 2201 } 2202 } 2203 this.fFinite = true; 2204 } 2205 2206 } 2208 private short getPrimitiveDV(short validationDV){ 2209 2210 if (validationDV == DV_ID || validationDV == DV_IDREF || validationDV == DV_ENTITY){ 2211 return DV_STRING; 2212 } 2213 else if (validationDV == DV_INTEGER) { 2214 return DV_DECIMAL; 2215 } 2216 else { 2217 return validationDV; 2218 } 2219 2220 } 2222 public boolean derivedFromType(XSTypeDefinition ancestor, short derivation) { 2223 2225 if (ancestor == null) 2227 return false; 2228 if (ancestor.getBaseType() == ancestor) 2231 return true; 2232 XSTypeDefinition type = this; 2234 while (type != ancestor && type != fAnySimpleType) { type = type.getBaseType(); 2237 } 2238 2239 return type == ancestor; 2240 } 2241 2242 public boolean derivedFrom(String ancestorNS, String ancestorName, short derivation) { 2243 2245 if (ancestorName == null) 2247 return false; 2248 if (URI_SCHEMAFORSCHEMA.equals(ancestorNS) && 2250 ANY_TYPE.equals(ancestorName)) { 2251 return true; 2252 } 2253 2254 XSTypeDefinition type = this; 2256 while (!(ancestorName.equals(type.getName()) && 2257 ((ancestorNS == null && type.getNamespace() == null) || 2258 (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) && type != fAnySimpleType) { type = (XSTypeDefinition)type.getBaseType(); 2261 } 2262 2263 return type != fAnySimpleType; 2264 } 2265 2266 static final XSSimpleTypeDecl fAnySimpleType = new XSSimpleTypeDecl(null, "anySimpleType", DV_ANYSIMPLETYPE, ORDERED_FALSE, false, true, false, true, XSConstants.ANYSIMPLETYPE_DT); 2267 2268 2271 static final ValidationContext fDummyContext = new ValidationContext() { 2272 public boolean needFacetChecking() { 2273 return true; 2274 } 2275 2276 public boolean needExtraChecking() { 2277 return false; 2278 } 2279 public boolean needToNormalize() { 2280 return false; 2281 } 2282 public boolean useNamespaces() { 2283 return true; 2284 } 2285 2286 public boolean isEntityDeclared(String name) { 2287 return false; 2288 } 2289 2290 public boolean isEntityUnparsed(String name) { 2291 return false; 2292 } 2293 2294 public boolean isIdDeclared(String name) { 2295 return false; 2296 } 2297 2298 public void addId(String name) { 2299 } 2300 2301 public void addIdRef(String name) { 2302 } 2303 2304 public String getSymbol (String symbol) { 2305 return null; 2306 } 2307 2308 public String getURI(String prefix) { 2309 return null; 2310 } 2311 }; 2312 2313 2317 class ValidationContextImpl implements ValidationContext { 2318 ValidationContext fExternal; 2319 ValidationContextImpl(ValidationContext external) { 2320 fExternal = external; 2321 } 2322 2323 NamespaceContext fNSContext; 2324 void setNSContext(NamespaceContext nsContext) { 2325 fNSContext = nsContext; 2326 } 2327 2328 public boolean needFacetChecking() { 2329 return fExternal.needFacetChecking(); 2330 } 2331 2332 public boolean needExtraChecking() { 2333 return fExternal.needExtraChecking(); 2334 } 2335 public boolean needToNormalize() { 2336 return fExternal.needToNormalize(); 2337 } 2338 public boolean useNamespaces() { 2340 return true; 2341 } 2342 2343 public boolean isEntityDeclared (String name) { 2344 return fExternal.isEntityDeclared(name); 2345 } 2346 2347 public boolean isEntityUnparsed (String name) { 2348 return fExternal.isEntityUnparsed(name); 2349 } 2350 2351 public boolean isIdDeclared (String name) { 2352 return fExternal.isIdDeclared(name); 2353 } 2354 2355 public void addId(String name) { 2356 fExternal.addId(name); 2357 } 2358 2359 public void addIdRef(String name) { 2360 fExternal.addIdRef(name); 2361 } 2362 2363 public String getSymbol (String symbol) { 2364 return fExternal.getSymbol(symbol); 2365 } 2366 2367 public String getURI(String prefix) { 2368 if (fNSContext == null) 2369 return fExternal.getURI(prefix); 2370 else 2371 return fNSContext.getURI(prefix); 2372 } 2373 } 2374 2375 public void reset(){ 2376 2377 if (fIsImmutable) return; 2379 fItemType = null; 2380 fMemberTypes = null; 2381 2382 fTypeName = null; 2383 fTargetNamespace = null; 2384 fFinalSet = 0; 2385 fBase = null; 2386 fVariety = -1; 2387 fValidationDV = -1; 2388 2389 fFacetsDefined = 0; 2390 fFixedFacet = 0; 2391 2392 fWhiteSpace = 0; 2394 fLength = -1; 2395 fMinLength = -1; 2396 fMaxLength = -1; 2397 fTotalDigits = -1; 2398 fFractionDigits = -1; 2399 fPattern = null; 2400 fPatternStr = null; 2401 fEnumeration = null; 2402 fLexicalPattern = null; 2403 fLexicalEnumeration = null; 2404 fMaxInclusive = null; 2405 fMaxExclusive = null; 2406 fMinExclusive = null; 2407 fMinInclusive = null; 2408 lengthAnnotation = null; 2409 minLengthAnnotation = null; 2410 maxLengthAnnotation = null; 2411 whiteSpaceAnnotation = null; 2412 totalDigitsAnnotation = null; 2413 fractionDigitsAnnotation = null; 2414 patternAnnotations = null; 2415 enumerationAnnotations = null; 2416 maxInclusiveAnnotation = null; 2417 maxExclusiveAnnotation = null; 2418 minInclusiveAnnotation = null; 2419 minExclusiveAnnotation = null; 2420 2421 fPatternType = SPECIAL_PATTERN_NONE; 2422 fAnnotations = null; 2423 fFacets = null; 2424 2425 } 2427 2430 public XSNamespaceItem getNamespaceItem() { 2431 return null; 2433 } 2434 2435 2438 public String toString() { 2439 return this.fTargetNamespace+"," +this.fTypeName; 2440 } 2441 2442 2445 public XSObjectList getFacets() { 2446 if (fFacets == null && 2447 (fFacetsDefined != 0 || fValidationDV == DV_INTEGER)) { 2448 2449 XSFacetImpl[] facets = new XSFacetImpl[10]; 2450 int count = 0; 2451 if ((fFacetsDefined & FACET_WHITESPACE) != 0) { 2452 facets[count] = 2453 new XSFacetImpl( 2454 FACET_WHITESPACE, 2455 WS_FACET_STRING[fWhiteSpace], 2456 (fFixedFacet & FACET_WHITESPACE) != 0, 2457 whiteSpaceAnnotation); 2458 count++; 2459 } 2460 if (fLength != -1) { 2461 facets[count] = 2462 new XSFacetImpl( 2463 FACET_LENGTH, 2464 Integer.toString(fLength), 2465 (fFixedFacet & FACET_LENGTH) != 0, 2466 lengthAnnotation); 2467 count++; 2468 } 2469 if (fMinLength != -1) { 2470 facets[count] = 2471 new XSFacetImpl( 2472 FACET_MINLENGTH, 2473 Integer.toString(fMinLength), 2474 (fFixedFacet & FACET_MINLENGTH) != 0, 2475 minLengthAnnotation); 2476 count++; 2477 } 2478 if (fMaxLength != -1) { 2479 facets[count] = 2480 new XSFacetImpl( 2481 FACET_MAXLENGTH, 2482 Integer.toString(fMaxLength), 2483 (fFixedFacet & FACET_MAXLENGTH) != 0, 2484 maxLengthAnnotation); 2485 count++; 2486 } 2487 if (fTotalDigits != -1) { 2488 facets[count] = 2489 new XSFacetImpl( 2490 FACET_TOTALDIGITS, 2491 Integer.toString(fTotalDigits), 2492 (fFixedFacet & FACET_TOTALDIGITS) != 0, 2493 totalDigitsAnnotation); 2494 count++; 2495 } 2496 if (fValidationDV == DV_INTEGER) { 2497 facets[count] = 2498 new XSFacetImpl( 2499 FACET_FRACTIONDIGITS, 2500 "0", 2501 true, 2502 null); 2503 count++; 2504 } 2505 if (fFractionDigits != -1) { 2506 facets[count] = 2507 new XSFacetImpl( 2508 FACET_FRACTIONDIGITS, 2509 Integer.toString(fFractionDigits), 2510 (fFixedFacet & FACET_FRACTIONDIGITS) != 0, 2511 fractionDigitsAnnotation); 2512 count++; 2513 } 2514 if (fMaxInclusive != null) { 2515 facets[count] = 2516 new XSFacetImpl( 2517 FACET_MAXINCLUSIVE, 2518 fMaxInclusive.toString(), 2519 (fFixedFacet & FACET_MAXINCLUSIVE) != 0, 2520 maxInclusiveAnnotation); 2521 count++; 2522 } 2523 if (fMaxExclusive != null) { 2524 facets[count] = 2525 new XSFacetImpl( 2526 FACET_MAXEXCLUSIVE, 2527 fMaxExclusive.toString(), 2528 (fFixedFacet & FACET_MAXEXCLUSIVE) != 0, 2529 maxExclusiveAnnotation); 2530 count++; 2531 } 2532 if (fMinExclusive != null) { 2533 facets[count] = 2534 new XSFacetImpl( 2535 FACET_MINEXCLUSIVE, 2536 fMinExclusive.toString(), 2537 (fFixedFacet & FACET_MINEXCLUSIVE) != 0, 2538 minExclusiveAnnotation); 2539 count++; 2540 } 2541 if (fMinInclusive != null) { 2542 facets[count] = 2543 new XSFacetImpl( 2544 FACET_MININCLUSIVE, 2545 fMinInclusive.toString(), 2546 (fFixedFacet & FACET_MININCLUSIVE) != 0, 2547 minInclusiveAnnotation); 2548 count++; 2549 } 2550 fFacets = new XSObjectListImpl(facets, count); 2551 } 2552 return fFacets; 2553 } 2554 2555 public XSObjectList getMultiValueFacets(){ 2556 if (fMultiValueFacets == null && 2557 ((fFacetsDefined & FACET_ENUMERATION) != 0 || 2558 (fFacetsDefined & FACET_PATTERN) != 0 || 2559 fPatternType != SPECIAL_PATTERN_NONE || 2560 fValidationDV == DV_INTEGER)) { 2561 2562 XSMVFacetImpl[] facets = new XSMVFacetImpl[2]; 2563 int count = 0; 2564 if ((fFacetsDefined & FACET_PATTERN) != 0 || 2565 fPatternType != SPECIAL_PATTERN_NONE || 2566 fValidationDV == DV_INTEGER) { 2567 facets[count] = 2568 new XSMVFacetImpl( 2569 FACET_PATTERN, 2570 this.getLexicalPattern(), 2571 patternAnnotations); 2572 count++; 2573 } 2574 if (fEnumeration != null) { 2575 facets[count] = 2576 new XSMVFacetImpl( 2577 FACET_ENUMERATION, 2578 this.getLexicalEnumeration(), 2579 enumerationAnnotations); 2580 count++; 2581 } 2582 fMultiValueFacets = new XSObjectListImpl(facets, count); 2583 } 2584 return fMultiValueFacets; 2585 } 2586 2587 private static final class XSFacetImpl implements XSFacet { 2588 final short kind; 2589 final String value; 2590 final boolean fixed; 2591 final XSAnnotation annotation; 2592 2593 public XSFacetImpl(short kind, String value, boolean fixed, XSAnnotation annotation) { 2594 this.kind = kind; 2595 this.value = value; 2596 this.fixed = fixed; 2597 this.annotation = annotation; 2598 } 2599 2602 public XSAnnotation getAnnotation() { 2603 return annotation; 2604 } 2605 2606 2609 public short getFacetKind() { 2610 return kind; 2611 } 2612 2613 2616 public String getLexicalFacetValue() { 2617 return value; 2618 } 2619 2620 2623 public boolean getFixed() { 2624 return fixed; 2625 } 2626 2627 2630 public String getName() { 2631 return null; 2632 } 2633 2634 2637 public String getNamespace() { 2638 return null; 2639 } 2640 2641 2644 public XSNamespaceItem getNamespaceItem() { 2645 return null; 2647 } 2648 2649 2652 public short getType() { 2653 return XSConstants.FACET; 2654 } 2655 2656 } 2657 2658 private static final class XSMVFacetImpl implements XSMultiValueFacet { 2659 final short kind; 2660 XSObjectList annotations; 2661 StringList values; 2662 2663 public XSMVFacetImpl(short kind, StringList values, XSObjectList annotations) { 2664 this.kind = kind; 2665 this.values = values; 2666 this.annotations = annotations; 2667 } 2668 2669 2670 2673 public short getFacetKind() { 2674 return kind; 2675 } 2676 2677 2678 2681 public XSObjectList getAnnotations() { 2682 return annotations; 2683 } 2684 2685 2688 public StringList getLexicalFacetValues() { 2689 return values; 2690 } 2691 2692 2695 public String getName() { 2696 return null; 2697 } 2698 2699 2702 public String getNamespace() { 2703 return null; 2704 } 2705 2706 2709 public XSNamespaceItem getNamespaceItem() { 2710 return null; 2712 } 2713 2714 2717 public short getType() { 2718 return XSConstants.MULTIVALUE_FACET; 2719 } 2720 } 2721 2722 2725 public String getTypeName() { 2726 if(getAnonymous()) 2727 return "anonymousSimpleType"+fUniqueId; 2728 else 2729 return getName(); 2730 } 2731 2732 2735 public String getTypeNamespace() { 2736 return getNamespace(); 2737 } 2738 2739 public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) { 2740 return derivedFrom(typeNamespaceArg,typeNameArg,(short)derivationMethod); 2741 } 2742 2743 2744} 2746 | Popular Tags |