1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import java.util.StringTokenizer ; 20 import java.util.Vector ; 21 22 import org.apache.xerces.impl.Constants; 23 import org.apache.xerces.impl.dv.DatatypeException; 24 import org.apache.xerces.impl.dv.InvalidDatatypeFacetException; 25 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 26 import org.apache.xerces.impl.dv.ValidatedInfo; 27 import org.apache.xerces.impl.dv.ValidationContext; 28 import org.apache.xerces.impl.dv.XSFacets; 29 import org.apache.xerces.impl.dv.XSSimpleType; 30 import org.apache.xerces.impl.xpath.regex.RegularExpression; 31 import org.apache.xerces.impl.xs.SchemaSymbols; 32 import org.apache.xerces.impl.xs.util.ShortListImpl; 33 import org.apache.xerces.impl.xs.util.StringListImpl; 34 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 35 import org.apache.xerces.util.XMLChar; 36 import org.apache.xerces.xni.NamespaceContext; 37 import org.apache.xerces.xs.ShortList; 38 import org.apache.xerces.xs.StringList; 39 import org.apache.xerces.xs.XSAnnotation; 40 import org.apache.xerces.xs.XSConstants; 41 import org.apache.xerces.xs.XSFacet; 42 import org.apache.xerces.xs.XSMultiValueFacet; 43 import org.apache.xerces.xs.XSNamespaceItem; 44 import org.apache.xerces.xs.XSObjectList; 45 import org.apache.xerces.xs.XSSimpleTypeDefinition; 46 import org.apache.xerces.xs.XSTypeDefinition; 47 import org.apache.xerces.xs.datatypes.ObjectList; 48 import org.w3c.dom.TypeInfo ; 49 50 58 public class XSSimpleTypeDecl implements XSSimpleType, TypeInfo { 59 60 static final short DV_STRING = PRIMITIVE_STRING; 61 static final short DV_BOOLEAN = PRIMITIVE_BOOLEAN; 62 static final short DV_DECIMAL = PRIMITIVE_DECIMAL; 63 static final short DV_FLOAT = PRIMITIVE_FLOAT; 64 static final short DV_DOUBLE = PRIMITIVE_DOUBLE; 65 static final short DV_DURATION = PRIMITIVE_DURATION; 66 static final short DV_DATETIME = PRIMITIVE_DATETIME; 67 static final short DV_TIME = PRIMITIVE_TIME; 68 static final short DV_DATE = PRIMITIVE_DATE; 69 static final short DV_GYEARMONTH = PRIMITIVE_GYEARMONTH; 70 static final short DV_GYEAR = PRIMITIVE_GYEAR; 71 static final short DV_GMONTHDAY = PRIMITIVE_GMONTHDAY; 72 static final short DV_GDAY = PRIMITIVE_GDAY; 73 static final short DV_GMONTH = PRIMITIVE_GMONTH; 74 static final short DV_HEXBINARY = PRIMITIVE_HEXBINARY; 75 static final short DV_BASE64BINARY = PRIMITIVE_BASE64BINARY; 76 static final short DV_ANYURI = PRIMITIVE_ANYURI; 77 static final short DV_QNAME = PRIMITIVE_QNAME; 78 static final short DV_PRECISIONDECIMAL = PRIMITIVE_PRECISIONDECIMAL; 79 static final short DV_NOTATION = PRIMITIVE_NOTATION; 80 81 static final short DV_ANYSIMPLETYPE = 0; 82 static final short DV_ID = DV_NOTATION + 1; 83 static final short DV_IDREF = DV_NOTATION + 2; 84 static final short DV_ENTITY = DV_NOTATION + 3; 85 static final short DV_INTEGER = DV_NOTATION + 4; 86 static final short DV_LIST = DV_NOTATION + 5; 87 static final short DV_UNION = DV_NOTATION + 6; 88 static final short DV_YEARMONTHDURATION = DV_NOTATION + 7; 89 static final short DV_DAYTIMEDURATION = DV_NOTATION + 8; 90 static final short DV_ANYATOMICTYPE = DV_NOTATION + 9; 91 92 static final TypeValidator[] fDVs = { 93 new AnySimpleDV(), 94 new StringDV(), 95 new BooleanDV(), 96 new DecimalDV(), 97 new FloatDV(), 98 new DoubleDV(), 99 new DurationDV(), 100 new DateTimeDV(), 101 new TimeDV(), 102 new DateDV(), 103 new YearMonthDV(), 104 new YearDV(), 105 new MonthDayDV(), 106 new DayDV(), 107 new MonthDV(), 108 new HexBinaryDV(), 109 new Base64BinaryDV(), 110 new AnyURIDV(), 111 new QNameDV(), 112 new PrecisionDecimalDV(), new QNameDV(), new IDDV(), 115 new IDREFDV(), 116 new EntityDV(), 117 new IntegerDV(), 118 new ListDV(), 119 new UnionDV(), 120 new YearMonthDurationDV(), new DayTimeDurationDV(), new AnyAtomicDV() }; 124 125 static final short NORMALIZE_NONE = 0; 126 static final short NORMALIZE_TRIM = 1; 127 static final short NORMALIZE_FULL = 2; 128 static final short[] fDVNormalizeType = { 129 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_TRIM, NORMALIZE_FULL, NORMALIZE_NONE, NORMALIZE_TRIM, NORMALIZE_TRIM, NORMALIZE_NONE, }; 160 161 static final short SPECIAL_PATTERN_NONE = 0; 162 static final short SPECIAL_PATTERN_NMTOKEN = 1; 163 static final short SPECIAL_PATTERN_NAME = 2; 164 static final short SPECIAL_PATTERN_NCNAME = 3; 165 166 static final String [] SPECIAL_PATTERN_STRING = { 167 "NONE", "NMTOKEN", "Name", "NCName" 168 }; 169 170 static final String [] WS_FACET_STRING = { 171 "preserve", "replace", "collapse" 172 }; 173 174 static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema"; 175 static final String ANY_TYPE = "anyType"; 176 177 public static final short YEARMONTHDURATION_DT = 46; 179 public static final short DAYTIMEDURATION_DT = 47; 180 public static final short PRECISIONDECIMAL_DT = 48; 181 public static final short ANYATOMICTYPE_DT = 49; 182 183 static final int DERIVATION_ANY = 0; 185 static final int DERIVATION_RESTRICTION = 1; 186 static final int DERIVATION_EXTENSION = 2; 187 static final int DERIVATION_UNION = 4; 188 static final int DERIVATION_LIST = 8; 189 190 static final ValidationContext fEmptyContext = new ValidationContext() { 191 public boolean needFacetChecking() { 192 return true; 193 } 194 public boolean needExtraChecking() { 195 return false; 196 } 197 public boolean needToNormalize() { 198 return true; 199 } 200 public boolean useNamespaces () { 201 return true; 202 } 203 public boolean isEntityDeclared (String name) { 204 return false; 205 } 206 public boolean isEntityUnparsed (String name) { 207 return false; 208 } 209 public boolean isIdDeclared (String name) { 210 return false; 211 } 212 public void addId(String name) { 213 } 214 public void addIdRef(String name) { 215 } 216 public String getSymbol (String symbol) { 217 return symbol.intern(); 218 } 219 public String getURI(String prefix) { 220 return null; 221 } 222 }; 223 224 private boolean fIsImmutable = false; 228 229 private XSSimpleTypeDecl fItemType; 230 private XSSimpleTypeDecl[] fMemberTypes; 231 private short fBuiltInKind; 233 234 private String fTypeName; 235 private String fTargetNamespace; 236 private short fFinalSet = 0; 237 private XSSimpleTypeDecl fBase; 238 private short fVariety = -1; 239 private short fValidationDV = -1; 240 241 private short fFacetsDefined = 0; 242 private short fFixedFacet = 0; 243 244 private short fWhiteSpace = 0; 246 private int fLength = -1; 247 private int fMinLength = -1; 248 private int fMaxLength = -1; 249 private int fTotalDigits = -1; 250 private int fFractionDigits = -1; 251 private Vector fPattern; 252 private Vector fPatternStr; 253 private Vector fEnumeration; 254 private short[] fEnumerationType; 255 private ShortList[] fEnumerationItemType; private ShortList fEnumerationTypeList; 257 private ObjectList fEnumerationItemTypeList; 258 private StringList fLexicalPattern; 259 private StringList fLexicalEnumeration; 260 private ObjectList fActualEnumeration; 261 private Object fMaxInclusive; 262 private Object fMaxExclusive; 263 private Object fMinExclusive; 264 private Object fMinInclusive; 265 266 public XSAnnotation lengthAnnotation; 268 public XSAnnotation minLengthAnnotation; 269 public XSAnnotation maxLengthAnnotation; 270 public XSAnnotation whiteSpaceAnnotation; 271 public XSAnnotation totalDigitsAnnotation; 272 public XSAnnotation fractionDigitsAnnotation; 273 public XSObjectListImpl patternAnnotations; 274 public XSObjectList enumerationAnnotations; 275 public XSAnnotation maxInclusiveAnnotation; 276 public XSAnnotation maxExclusiveAnnotation; 277 public XSAnnotation minInclusiveAnnotation; 278 public XSAnnotation minExclusiveAnnotation; 279 280 private XSObjectListImpl fFacets; 282 283 private XSObjectListImpl fMultiValueFacets; 285 286 private XSObjectList fAnnotations = null; 288 289 private short fPatternType = SPECIAL_PATTERN_NONE; 290 291 private short fOrdered; 293 private boolean fFinite; 294 private boolean fBounded; 295 private boolean fNumeric; 296 297 public XSSimpleTypeDecl(){} 299 300 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, short validateDV, 302 short ordered, boolean bounded, boolean finite, 303 boolean numeric, boolean isImmutable, short builtInKind) { 304 fIsImmutable = isImmutable; 305 fBase = base; 306 fTypeName = name; 307 fTargetNamespace = URI_SCHEMAFORSCHEMA; 308 fVariety = VARIETY_ATOMIC; 310 fValidationDV = validateDV; 311 fFacetsDefined = FACET_WHITESPACE; 312 if (validateDV == DV_STRING) { 313 fWhiteSpace = WS_PRESERVE; 314 } else { 315 fWhiteSpace = WS_COLLAPSE; 316 fFixedFacet = FACET_WHITESPACE; 317 } 318 this.fOrdered = ordered; 319 this.fBounded = bounded; 320 this.fFinite = finite; 321 this.fNumeric = numeric; 322 fAnnotations = null; 323 324 fBuiltInKind = builtInKind; 326 } 327 328 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, String uri, short finalSet, boolean isImmutable, 330 XSObjectList annotations, short builtInKind) { 331 this(base, name, uri, finalSet, isImmutable, annotations); 332 fBuiltInKind = builtInKind; 334 } 335 336 protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, String uri, short finalSet, boolean isImmutable, 338 XSObjectList annotations) { 339 fBase = base; 340 fTypeName = name; 341 fTargetNamespace = uri; 342 fFinalSet = finalSet; 343 fAnnotations = annotations; 344 345 fVariety = fBase.fVariety; 346 fValidationDV = fBase.fValidationDV; 347 switch (fVariety) { 348 case VARIETY_ATOMIC: 349 break; 350 case VARIETY_LIST: 351 fItemType = fBase.fItemType; 352 break; 353 case VARIETY_UNION: 354 fMemberTypes = fBase.fMemberTypes; 355 break; 356 } 357 358 fLength = fBase.fLength; 361 fMinLength = fBase.fMinLength; 362 fMaxLength = fBase.fMaxLength; 363 fPattern = fBase.fPattern; 364 fPatternStr = fBase.fPatternStr; 365 fEnumeration = fBase.fEnumeration; 366 fEnumerationType = fBase.fEnumerationType; 367 fEnumerationItemType = fBase.fEnumerationItemType; 368 fWhiteSpace = fBase.fWhiteSpace; 369 fMaxExclusive = fBase.fMaxExclusive; 370 fMaxInclusive = fBase.fMaxInclusive; 371 fMinExclusive = fBase.fMinExclusive; 372 fMinInclusive = fBase.fMinInclusive; 373 fTotalDigits = fBase.fTotalDigits; 374 fFractionDigits = fBase.fFractionDigits; 375 fPatternType = fBase.fPatternType; 376 fFixedFacet = fBase.fFixedFacet; 377 fFacetsDefined = fBase.fFacetsDefined; 378 379 caclFundamentalFacets(); 381 fIsImmutable = isImmutable; 382 383 fBuiltInKind = base.fBuiltInKind; 385 } 386 387 protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, boolean isImmutable, 389 XSObjectList annotations) { 390 fBase = fAnySimpleType; 391 fTypeName = name; 392 fTargetNamespace = uri; 393 fFinalSet = finalSet; 394 fAnnotations = annotations; 395 396 fVariety = VARIETY_LIST; 397 fItemType = (XSSimpleTypeDecl)itemType; 398 fValidationDV = DV_LIST; 399 fFacetsDefined = FACET_WHITESPACE; 400 fFixedFacet = FACET_WHITESPACE; 401 fWhiteSpace = WS_COLLAPSE; 402 403 caclFundamentalFacets(); 405 fIsImmutable = isImmutable; 406 407 fBuiltInKind = XSConstants.LIST_DT; 409 } 410 411 protected XSSimpleTypeDecl(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes, 413 XSObjectList annotations) { 414 fBase = fAnySimpleType; 415 fTypeName = name; 416 fTargetNamespace = uri; 417 fFinalSet = finalSet; 418 fAnnotations = annotations; 419 420 fVariety = VARIETY_UNION; 421 fMemberTypes = memberTypes; 422 fValidationDV = DV_UNION; 423 fFacetsDefined = FACET_WHITESPACE; 428 fWhiteSpace = WS_COLLAPSE; 429 430 caclFundamentalFacets(); 432 fIsImmutable = false; 435 436 fBuiltInKind = XSConstants.UNAVAILABLE_DT; 438 } 439 440 protected XSSimpleTypeDecl setRestrictionValues(XSSimpleTypeDecl base, String name, String uri, short finalSet, 442 XSObjectList annotations) { 443 if(fIsImmutable) return null; 445 fBase = base; 446 fTypeName = name; 447 fTargetNamespace = uri; 448 fFinalSet = finalSet; 449 fAnnotations = annotations; 450 451 fVariety = fBase.fVariety; 452 fValidationDV = fBase.fValidationDV; 453 switch (fVariety) { 454 case VARIETY_ATOMIC: 455 break; 456 case VARIETY_LIST: 457 fItemType = fBase.fItemType; 458 break; 459 case VARIETY_UNION: 460 fMemberTypes = fBase.fMemberTypes; 461 break; 462 } 463 464 fLength = fBase.fLength; 467 fMinLength = fBase.fMinLength; 468 fMaxLength = fBase.fMaxLength; 469 fPattern = fBase.fPattern; 470 fPatternStr = fBase.fPatternStr; 471 fEnumeration = fBase.fEnumeration; 472 fEnumerationType = fBase.fEnumerationType; 473 fEnumerationItemType = fBase.fEnumerationItemType; 474 fWhiteSpace = fBase.fWhiteSpace; 475 fMaxExclusive = fBase.fMaxExclusive; 476 fMaxInclusive = fBase.fMaxInclusive; 477 fMinExclusive = fBase.fMinExclusive; 478 fMinInclusive = fBase.fMinInclusive; 479 fTotalDigits = fBase.fTotalDigits; 480 fFractionDigits = fBase.fFractionDigits; 481 fPatternType = fBase.fPatternType; 482 fFixedFacet = fBase.fFixedFacet; 483 fFacetsDefined = fBase.fFacetsDefined; 484 485 caclFundamentalFacets(); 487 488 fBuiltInKind = base.fBuiltInKind; 490 491 return this; 492 } 493 494 protected XSSimpleTypeDecl setListValues(String name, String uri, short finalSet, XSSimpleTypeDecl itemType, 496 XSObjectList annotations) { 497 if(fIsImmutable) return null; 499 fBase = fAnySimpleType; 500 fTypeName = name; 501 fTargetNamespace = uri; 502 fFinalSet = finalSet; 503 fAnnotations = annotations; 504 505 fVariety = VARIETY_LIST; 506 fItemType = (XSSimpleTypeDecl)itemType; 507 fValidationDV = DV_LIST; 508 fFacetsDefined = FACET_WHITESPACE; 509 fFixedFacet = FACET_WHITESPACE; 510 fWhiteSpace = WS_COLLAPSE; 511 512 caclFundamentalFacets(); 514 515 fBuiltInKind = XSConstants.LIST_DT; 517 518 return this; 519 } 520 521 protected XSSimpleTypeDecl setUnionValues(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes, 523 XSObjectList annotations) { 524 if(fIsImmutable) return null; 526 fBase = fAnySimpleType; 527 fTypeName = name; 528 fTargetNamespace = uri; 529 fFinalSet = finalSet; 530 fAnnotations = annotations; 531 532 fVariety = VARIETY_UNION; 533 fMemberTypes = memberTypes; 534 fValidationDV = DV_UNION; 535 fFacetsDefined = FACET_WHITESPACE; 540 fWhiteSpace = WS_COLLAPSE; 541 542 caclFundamentalFacets(); 544 545 fBuiltInKind = XSConstants.UNAVAILABLE_DT; 547 548 return this; 549 } 550 551 public short getType () { 552 return XSConstants.TYPE_DEFINITION; 553 } 554 555 public short getTypeCategory () { 556 return SIMPLE_TYPE; 557 } 558 559 public String getName() { 560 return getAnonymous()?null:fTypeName; 561 } 562 563 public String getTypeName() { 564 return fTypeName; 565 } 566 567 public String getNamespace() { 568 return fTargetNamespace; 569 } 570 571 public short getFinal(){ 572 return fFinalSet; 573 } 574 575 public boolean isFinal(short derivation) { 576 return (fFinalSet & derivation) != 0; 577 } 578 579 public XSTypeDefinition getBaseType(){ 580 return fBase; 581 } 582 583 public boolean getAnonymous() { 584 return fAnonymous || (fTypeName == null); 585 } 586 587 public short getVariety(){ 588 return fValidationDV == DV_ANYSIMPLETYPE ? VARIETY_ABSENT : fVariety; 590 } 591 592 public boolean isIDType(){ 593 switch (fVariety) { 594 case VARIETY_ATOMIC: 595 return fValidationDV == DV_ID; 596 case VARIETY_LIST: 597 return fItemType.isIDType(); 598 case VARIETY_UNION: 599 for (int i = 0; i < fMemberTypes.length; i++) { 600 if (fMemberTypes[i].isIDType()) 601 return true; 602 } 603 } 604 return false; 605 } 606 607 public short getWhitespace() throws DatatypeException{ 608 if (fVariety == VARIETY_UNION) { 609 throw new DatatypeException("dt-whitespace", new Object []{fTypeName}); 610 } 611 return fWhiteSpace; 612 } 613 614 public short getPrimitiveKind() { 615 if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) { 616 if (fValidationDV == DV_ID || fValidationDV == DV_IDREF || fValidationDV == DV_ENTITY) { 617 return DV_STRING; 618 } 619 else if (fValidationDV == DV_INTEGER) { 620 return DV_DECIMAL; 621 } 622 else if (Constants.SCHEMA_1_1_SUPPORT && (fValidationDV == DV_YEARMONTHDURATION || fValidationDV == DV_DAYTIMEDURATION)) { 623 return DV_DURATION; 624 } 625 else { 626 return fValidationDV; 627 } 628 } 629 else { 630 return (short)0; 632 } 633 } 634 635 640 public short getBuiltInKind() { 641 return this.fBuiltInKind; 642 } 643 644 649 public XSSimpleTypeDefinition getPrimitiveType() { 650 if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) { 651 XSSimpleTypeDecl pri = this; 652 while (pri.fBase != fAnySimpleType) 654 pri = pri.fBase; 655 return pri; 656 } 657 else { 658 return null; 660 } 661 } 662 663 668 public XSSimpleTypeDefinition getItemType() { 669 if (fVariety == VARIETY_LIST) { 670 return fItemType; 671 } 672 else { 673 return null; 675 } 676 } 677 678 683 public XSObjectList getMemberTypes() { 684 if (fVariety == VARIETY_UNION) { 685 return new XSObjectListImpl(fMemberTypes, fMemberTypes.length); 686 } 687 else { 688 return XSObjectListImpl.EMPTY_LIST; 689 } 690 } 691 692 695 public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, ValidationContext context) 696 throws InvalidDatatypeFacetException { 697 applyFacets(facets, presentFacet, fixedFacet, SPECIAL_PATTERN_NONE, context); 698 } 699 700 703 void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet) { 704 705 try { 706 applyFacets(facets, presentFacet, fixedFacet, SPECIAL_PATTERN_NONE, fDummyContext); 707 } catch (InvalidDatatypeFacetException e) { 708 throw new RuntimeException ("internal error"); 710 } 711 fIsImmutable = true; 713 } 714 715 718 void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet, short patternType) { 719 720 try { 721 applyFacets(facets, presentFacet, fixedFacet, patternType, fDummyContext); 722 } catch (InvalidDatatypeFacetException e) { 723 throw new RuntimeException ("internal error"); 725 } 726 fIsImmutable = true; 728 } 729 730 733 void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short patternType, ValidationContext context) 734 throws InvalidDatatypeFacetException { 735 736 if(fIsImmutable) return; 738 ValidatedInfo tempInfo = new ValidatedInfo(); 739 740 747 fFacetsDefined = 0; 748 fFixedFacet = 0; 749 750 int result = 0 ; 751 752 short allowedFacet = fDVs[fValidationDV].getAllowedFacets(); 754 755 if ((presentFacet & FACET_LENGTH) != 0) { 757 if ((allowedFacet & FACET_LENGTH) == 0) { 758 reportError("cos-applicable-facets", new Object []{"length", fTypeName}); 759 } else { 760 fLength = facets.length; 761 lengthAnnotation = facets.lengthAnnotation; 762 fFacetsDefined |= FACET_LENGTH; 763 if ((fixedFacet & FACET_LENGTH) != 0) 764 fFixedFacet |= FACET_LENGTH; 765 } 766 } 767 if ((presentFacet & FACET_MINLENGTH) != 0) { 769 if ((allowedFacet & FACET_MINLENGTH) == 0) { 770 reportError("cos-applicable-facets", new Object []{"minLength", fTypeName}); 771 } else { 772 fMinLength = facets.minLength; 773 minLengthAnnotation = facets.minLengthAnnotation; 774 fFacetsDefined |= FACET_MINLENGTH; 775 if ((fixedFacet & FACET_MINLENGTH) != 0) 776 fFixedFacet |= FACET_MINLENGTH; 777 } 778 } 779 if ((presentFacet & FACET_MAXLENGTH) != 0) { 781 if ((allowedFacet & FACET_MAXLENGTH) == 0) { 782 reportError("cos-applicable-facets", new Object []{"maxLength", fTypeName}); 783 } else { 784 fMaxLength = facets.maxLength; 785 maxLengthAnnotation = facets.maxLengthAnnotation; 786 fFacetsDefined |= FACET_MAXLENGTH; 787 if ((fixedFacet & FACET_MAXLENGTH) != 0) 788 fFixedFacet |= FACET_MAXLENGTH; 789 } 790 } 791 if ((presentFacet & FACET_PATTERN) != 0) { 793 if ((allowedFacet & FACET_PATTERN) == 0) { 794 reportError("cos-applicable-facets", new Object []{"pattern", fTypeName}); 795 } else { 796 patternAnnotations = facets.patternAnnotations; 797 RegularExpression regex = null; 798 try { 799 regex = new RegularExpression(facets.pattern, "X"); 800 } catch (Exception e) { 801 reportError("InvalidRegex", new Object []{facets.pattern, e.getLocalizedMessage()}); 802 } 803 if (regex != null) { 804 fPattern = new Vector (); 805 fPattern.addElement(regex); 806 fPatternStr = new Vector (); 807 fPatternStr.addElement(facets.pattern); 808 fFacetsDefined |= FACET_PATTERN; 809 if ((fixedFacet & FACET_PATTERN) != 0) 810 fFixedFacet |= FACET_PATTERN; 811 } 812 } 813 } 814 815 if ((presentFacet & FACET_ENUMERATION) != 0) { 817 if ((allowedFacet & FACET_ENUMERATION) == 0) { 818 reportError("cos-applicable-facets", new Object []{"enumeration", fTypeName}); 819 } else { 820 fEnumeration = new Vector (); 821 Vector enumVals = facets.enumeration; 822 fEnumerationType = new short[enumVals.size()]; 823 fEnumerationItemType = new ShortList[enumVals.size()]; 824 Vector enumNSDecls = facets.enumNSDecls; 825 ValidationContextImpl ctx = new ValidationContextImpl(context); 826 enumerationAnnotations = facets.enumAnnotations; 827 for (int i = 0; i < enumVals.size(); i++) { 828 if (enumNSDecls != null) 829 ctx.setNSContext((NamespaceContext)enumNSDecls.elementAt(i)); 830 try { 831 ValidatedInfo info = this.fBase.validateWithInfo((String )enumVals.elementAt(i), ctx, tempInfo); 832 fEnumeration.addElement(info.actualValue); 834 fEnumerationType[i] = info.actualValueType; 835 fEnumerationItemType[i] = info.itemValueTypes; 836 } catch (InvalidDatatypeValueException ide) { 837 reportError("enumeration-valid-restriction", new Object []{enumVals.elementAt(i), this.getBaseType().getName()}); 838 } 839 } 840 fFacetsDefined |= FACET_ENUMERATION; 841 if ((fixedFacet & FACET_ENUMERATION) != 0) 842 fFixedFacet |= FACET_ENUMERATION; 843 } 844 } 845 if ((presentFacet & FACET_WHITESPACE) != 0) { 847 if ((allowedFacet & FACET_WHITESPACE) == 0) { 848 reportError("cos-applicable-facets", new Object []{"whiteSpace", fTypeName}); 849 } else { 850 fWhiteSpace = facets.whiteSpace; 851 whiteSpaceAnnotation = facets.whiteSpaceAnnotation; 852 fFacetsDefined |= FACET_WHITESPACE; 853 if ((fixedFacet & FACET_WHITESPACE) != 0) 854 fFixedFacet |= FACET_WHITESPACE; 855 } 856 } 857 858 if ((presentFacet & FACET_MAXINCLUSIVE) != 0) { 860 if ((allowedFacet & FACET_MAXINCLUSIVE) == 0) { 861 reportError("cos-applicable-facets", new Object []{"maxInclusive", fTypeName}); 862 } else { 863 maxInclusiveAnnotation = facets.maxInclusiveAnnotation; 864 try { 865 fMaxInclusive = fBase.getActualValue(facets.maxInclusive, context, tempInfo, true); 866 fFacetsDefined |= FACET_MAXINCLUSIVE; 867 if ((fixedFacet & FACET_MAXINCLUSIVE) != 0) 868 fFixedFacet |= FACET_MAXINCLUSIVE; 869 } catch (InvalidDatatypeValueException ide) { 870 reportError(ide.getKey(), ide.getArgs()); 871 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxInclusive, 872 "maxInclusive", fBase.getName()}); 873 } 874 875 if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 877 if ((fBase.fFixedFacet & FACET_MAXINCLUSIVE) != 0) { 878 if (fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMaxInclusive) != 0) 879 reportError( "FixedFacetValue", new Object []{"maxInclusive", fMaxInclusive, fBase.fMaxInclusive, fTypeName}); 880 } 881 } 882 try { 884 fBase.validate(context, tempInfo); 885 } catch (InvalidDatatypeValueException ide) { 886 reportError(ide.getKey(), ide.getArgs()); 887 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxInclusive, 888 "maxInclusive", fBase.getName()}); 889 } 890 } 891 } 892 893 boolean needCheckBase = true; 895 if ((presentFacet & FACET_MAXEXCLUSIVE) != 0) { 896 if ((allowedFacet & FACET_MAXEXCLUSIVE) == 0) { 897 reportError("cos-applicable-facets", new Object []{"maxExclusive", fTypeName}); 898 } else { 899 maxExclusiveAnnotation = facets.maxExclusiveAnnotation; 900 try { 901 fMaxExclusive = fBase.getActualValue(facets.maxExclusive, context, tempInfo, true); 902 fFacetsDefined |= FACET_MAXEXCLUSIVE; 903 if ((fixedFacet & FACET_MAXEXCLUSIVE) != 0) 904 fFixedFacet |= FACET_MAXEXCLUSIVE; 905 } catch (InvalidDatatypeValueException ide) { 906 reportError(ide.getKey(), ide.getArgs()); 907 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxExclusive, 908 "maxExclusive", fBase.getName()}); 909 } 910 911 if (((fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) { 913 result = fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMaxExclusive); 914 if ((fBase.fFixedFacet & FACET_MAXEXCLUSIVE) != 0 && result != 0) { 915 reportError( "FixedFacetValue", new Object []{"maxExclusive", facets.maxExclusive, fBase.fMaxExclusive, fTypeName}); 916 } 917 if (result == 0) { 918 needCheckBase = false; 919 } 920 } 921 if (needCheckBase) { 923 try { 924 fBase.validate(context, tempInfo); 925 } catch (InvalidDatatypeValueException ide) { 926 reportError(ide.getKey(), ide.getArgs()); 927 reportError("FacetValueFromBase", new Object []{fTypeName, facets.maxExclusive, 928 "maxExclusive", fBase.getName()}); 929 } 930 } 931 else if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 934 if (fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMaxInclusive) > 0) { 935 reportError( "maxExclusive-valid-restriction.2", new Object []{facets.maxExclusive, fBase.fMaxInclusive}); 936 } 937 } 938 } 939 } 940 needCheckBase = true; 942 if ((presentFacet & FACET_MINEXCLUSIVE) != 0) { 943 if ((allowedFacet & FACET_MINEXCLUSIVE) == 0) { 944 reportError("cos-applicable-facets", new Object []{"minExclusive", fTypeName}); 945 } else { 946 minExclusiveAnnotation = facets.minExclusiveAnnotation; 947 try { 948 fMinExclusive = fBase.getActualValue(facets.minExclusive, context, tempInfo, true); 949 fFacetsDefined |= FACET_MINEXCLUSIVE; 950 if ((fixedFacet & FACET_MINEXCLUSIVE) != 0) 951 fFixedFacet |= FACET_MINEXCLUSIVE; 952 } catch (InvalidDatatypeValueException ide) { 953 reportError(ide.getKey(), ide.getArgs()); 954 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minExclusive, 955 "minExclusive", fBase.getName()}); 956 } 957 958 if (((fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 960 result = fDVs[fValidationDV].compare(fMinExclusive, fBase.fMinExclusive); 961 if ((fBase.fFixedFacet & FACET_MINEXCLUSIVE) != 0 && result != 0) { 962 reportError( "FixedFacetValue", new Object []{"minExclusive", facets.minExclusive, fBase.fMinExclusive, fTypeName}); 963 } 964 if (result == 0) { 965 needCheckBase = false; 966 } 967 } 968 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.minExclusive, 975 "minExclusive", fBase.getName()}); 976 } 977 } 978 else if (((fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 981 if (fDVs[fValidationDV].compare(fMinExclusive, fBase.fMinInclusive) < 0) { 982 reportError( "minExclusive-valid-restriction.3", new Object []{facets.minExclusive, fBase.fMinInclusive}); 983 } 984 } 985 } 986 } 987 if ((presentFacet & FACET_MININCLUSIVE) != 0) { 989 if ((allowedFacet & FACET_MININCLUSIVE) == 0) { 990 reportError("cos-applicable-facets", new Object []{"minInclusive", fTypeName}); 991 } else { 992 minInclusiveAnnotation = facets.minInclusiveAnnotation; 993 try { 994 fMinInclusive = fBase.getActualValue(facets.minInclusive, context, tempInfo, true); 995 fFacetsDefined |= FACET_MININCLUSIVE; 996 if ((fixedFacet & FACET_MININCLUSIVE) != 0) 997 fFixedFacet |= FACET_MININCLUSIVE; 998 } catch (InvalidDatatypeValueException ide) { 999 reportError(ide.getKey(), ide.getArgs()); 1000 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minInclusive, 1001 "minInclusive", fBase.getName()}); 1002 } 1003 1004 if (((fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1006 if ((fBase.fFixedFacet & FACET_MININCLUSIVE) != 0) { 1007 if (fDVs[fValidationDV].compare(fMinInclusive, fBase.fMinInclusive) != 0) 1008 reportError( "FixedFacetValue", new Object []{"minInclusive", facets.minInclusive, fBase.fMinInclusive, fTypeName}); 1009 } 1010 } 1011 try { 1013 fBase.validate(context, tempInfo); 1014 } catch (InvalidDatatypeValueException ide) { 1015 reportError(ide.getKey(), ide.getArgs()); 1016 reportError("FacetValueFromBase", new Object []{fTypeName, facets.minInclusive, 1017 "minInclusive", fBase.getName()}); 1018 } 1019 } 1020 } 1021 1022 if ((presentFacet & FACET_TOTALDIGITS) != 0) { 1024 if ((allowedFacet & FACET_TOTALDIGITS) == 0) { 1025 reportError("cos-applicable-facets", new Object []{"totalDigits", fTypeName}); 1026 } else { 1027 totalDigitsAnnotation = facets.totalDigitsAnnotation; 1028 fTotalDigits = facets.totalDigits; 1029 fFacetsDefined |= FACET_TOTALDIGITS; 1030 if ((fixedFacet & FACET_TOTALDIGITS) != 0) 1031 fFixedFacet |= FACET_TOTALDIGITS; 1032 } 1033 } 1034 if ((presentFacet & FACET_FRACTIONDIGITS) != 0) { 1036 if ((allowedFacet & FACET_FRACTIONDIGITS) == 0) { 1037 reportError("cos-applicable-facets", new Object []{"fractionDigits", fTypeName}); 1038 } else { 1039 fFractionDigits = facets.fractionDigits; 1040 fractionDigitsAnnotation = facets.fractionDigitsAnnotation; 1041 fFacetsDefined |= FACET_FRACTIONDIGITS; 1042 if ((fixedFacet & FACET_FRACTIONDIGITS) != 0) 1043 fFixedFacet |= FACET_FRACTIONDIGITS; 1044 } 1045 } 1046 1047 if (patternType != SPECIAL_PATTERN_NONE) { 1049 fPatternType = patternType; 1050 } 1051 1052 if(fFacetsDefined != 0) { 1054 1055 if((fFacetsDefined & FACET_LENGTH) != 0 ){ 1057 if ((fFacetsDefined & FACET_MINLENGTH) != 0) { 1058 if ((fFacetsDefined & FACET_MAXLENGTH) != 0) { 1059 reportError("length-minLength-maxLength.a", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMinLength), Integer.toString(fMaxLength)}); 1061 } 1062 else { 1063 reportError("length-minLength-maxLength.b", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMinLength)}); 1065 } 1066 } 1067 else if ((fFacetsDefined & FACET_MAXLENGTH) != 0) { 1068 reportError("length-minLength-maxLength.c", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fMaxLength)}); 1070 } 1071 } 1072 1073 if(((fFacetsDefined & FACET_MINLENGTH ) != 0 ) && ((fFacetsDefined & FACET_MAXLENGTH) != 0)) 1075 { 1076 if(fMinLength > fMaxLength) 1077 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fMinLength), Integer.toString(fMaxLength), fTypeName}); 1078 } 1079 1080 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1082 reportError( "maxInclusive-maxExclusive", new Object []{fMaxInclusive, fMaxExclusive, fTypeName}); 1083 } 1084 1085 if (((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1087 reportError("minInclusive-minExclusive", new Object []{fMinInclusive, fMinExclusive, fTypeName}); 1088 } 1089 1090 if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1092 result = fDVs[fValidationDV].compare(fMinInclusive, fMaxInclusive); 1093 if (result != -1 && result != 0) 1094 reportError("minInclusive-less-than-equal-to-maxInclusive", new Object []{fMinInclusive, fMaxInclusive, fTypeName}); 1095 } 1096 1097 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 1099 result = fDVs[fValidationDV].compare(fMinExclusive, fMaxExclusive); 1100 if (result != -1 && result != 0) 1101 reportError( "minExclusive-less-than-equal-to-maxExclusive", new Object []{fMinExclusive, fMaxExclusive, fTypeName}); 1102 } 1103 1104 if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) { 1106 if (fDVs[fValidationDV].compare(fMinExclusive, fMaxInclusive) != -1) 1107 reportError( "minExclusive-less-than-maxInclusive", new Object []{fMinExclusive, fMaxInclusive, fTypeName}); 1108 } 1109 1110 if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1112 if (fDVs[fValidationDV].compare(fMinInclusive, fMaxExclusive) != -1) 1113 reportError( "minInclusive-less-than-maxExclusive", new Object []{fMinInclusive, fMaxExclusive, fTypeName}); 1114 } 1115 1116 if (((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) && 1118 ((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1119 if (fFractionDigits > fTotalDigits) 1120 reportError( "fractionDigits-totalDigits", new Object []{Integer.toString(fFractionDigits), Integer.toString(fTotalDigits), fTypeName}); 1121 } 1122 1123 if((fFacetsDefined & FACET_LENGTH) != 0 ){ 1126 if ((fBase.fFacetsDefined & FACET_MINLENGTH) != 0 && 1127 fLength < fBase.fMinLength) { 1128 reportError("length-minLength-maxLength.d", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fBase.fMinLength)}); 1130 } 1131 if ((fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 && 1132 fLength > fBase.fMaxLength) { 1133 reportError("length-minLength-maxLength.e", new Object []{fTypeName, Integer.toString(fLength), Integer.toString(fBase.fMaxLength)}); 1135 } 1136 if ( (fBase.fFacetsDefined & FACET_LENGTH) != 0 ) { 1137 if ( fLength != fBase.fLength ) 1139 reportError( "length-valid-restriction", new Object []{Integer.toString(fLength), Integer.toString(fBase.fLength), fTypeName}); 1140 } 1141 } 1142 1143 else if((fBase.fFacetsDefined & FACET_LENGTH) != 0 ){ 1145 if ((fFacetsDefined & FACET_MINLENGTH) != 0 && 1146 fBase.fLength < fMinLength) { 1147 reportError("length-minLength-maxLength.d", new Object []{fTypeName, Integer.toString(fBase.fLength), Integer.toString(fMinLength)}); 1149 } 1150 if ((fFacetsDefined & FACET_MAXLENGTH) != 0 && 1151 fBase.fLength > fMaxLength) { 1152 reportError("length-minLength-maxLength.e", new Object []{this, Integer.toString(fBase.fLength), Integer.toString(fMaxLength)}); 1154 } 1155 } 1156 1157 if ( ((fFacetsDefined & FACET_MINLENGTH ) != 0 ) ) { 1159 if ( (fBase.fFacetsDefined & FACET_MAXLENGTH ) != 0 ) { 1160 if ( fMinLength > fBase.fMaxLength ) { 1161 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fMinLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1162 } 1163 } 1164 else if ( (fBase.fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1165 if ( (fBase.fFixedFacet & FACET_MINLENGTH) != 0 && fMinLength != fBase.fMinLength ) { 1166 reportError( "FixedFacetValue", new Object []{"minLength", Integer.toString(fMinLength), Integer.toString(fBase.fMinLength), fTypeName}); 1167 } 1168 1169 if ( fMinLength < fBase.fMinLength ) { 1171 reportError( "minLength-valid-restriction", new Object []{Integer.toString(fMinLength), Integer.toString(fBase.fMinLength), fTypeName}); 1172 } 1173 } 1174 } 1175 1176 1177 if ( ((fFacetsDefined & FACET_MAXLENGTH ) != 0 ) && ((fBase.fFacetsDefined & FACET_MINLENGTH ) != 0 )) { 1179 if ( fMaxLength < fBase.fMinLength) { 1180 reportError("minLength-less-than-equal-to-maxLength", new Object []{Integer.toString(fBase.fMinLength), Integer.toString(fMaxLength)}); 1181 } 1182 } 1183 1184 if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1186 if ( (fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 ){ 1187 if(( (fBase.fFixedFacet & FACET_MAXLENGTH) != 0 )&& fMaxLength != fBase.fMaxLength ) { 1188 reportError( "FixedFacetValue", new Object []{"maxLength", Integer.toString(fMaxLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1189 } 1190 if ( fMaxLength > fBase.fMaxLength ) { 1191 reportError( "maxLength-valid-restriction", new Object []{Integer.toString(fMaxLength), Integer.toString(fBase.fMaxLength), fTypeName}); 1192 } 1193 } 1194 } 1195 1196 1328 if (((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1330 if ((( fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1331 if ((fBase.fFixedFacet & FACET_TOTALDIGITS) != 0 && fTotalDigits != fBase.fTotalDigits) { 1332 reportError("FixedFacetValue", new Object []{"totalDigits", Integer.toString(fTotalDigits), Integer.toString(fBase.fTotalDigits), fTypeName}); 1333 } 1334 if (fTotalDigits > fBase.fTotalDigits) { 1335 reportError( "totalDigits-valid-restriction", new Object []{Integer.toString(fTotalDigits), Integer.toString(fBase.fTotalDigits), fTypeName}); 1336 } 1337 } 1338 } 1339 1340 if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) { 1342 if ((fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0) { 1343 if (fFractionDigits > fBase.fTotalDigits) 1344 reportError( "fractionDigits-totalDigits", new Object []{Integer.toString(fFractionDigits), Integer.toString(fTotalDigits), fTypeName}); 1345 } 1346 } 1347 1348 if (((fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1351 if ((( fBase.fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1352 if ((fBase.fFixedFacet & FACET_FRACTIONDIGITS) != 0 && fFractionDigits != fBase.fFractionDigits) { 1353 reportError("FixedFacetValue", new Object []{"fractionDigits", Integer.toString(fFractionDigits), Integer.toString(fBase.fFractionDigits), fTypeName}); 1354 } 1355 if (fFractionDigits > fBase.fFractionDigits) { 1356 reportError( "fractionDigits-valid-restriction", new Object []{Integer.toString(fFractionDigits), Integer.toString(fBase.fFractionDigits), fTypeName}); 1357 } 1358 } 1359 } 1360 1361 1365 if ( (fFacetsDefined & FACET_WHITESPACE) != 0 && (fBase.fFacetsDefined & FACET_WHITESPACE) != 0 ){ 1366 if ( (fBase.fFixedFacet & FACET_WHITESPACE) != 0 && fWhiteSpace != fBase.fWhiteSpace ) { 1367 reportError( "FixedFacetValue", new Object []{"whiteSpace", whiteSpaceValue(fWhiteSpace), whiteSpaceValue(fBase.fWhiteSpace), fTypeName}); 1368 } 1369 1370 if ( fWhiteSpace == WS_PRESERVE && fBase.fWhiteSpace == WS_COLLAPSE ){ 1371 reportError( "whiteSpace-valid-restriction.1", new Object []{fTypeName, "preserve"}); 1372 } 1373 if ( fWhiteSpace == WS_REPLACE && fBase.fWhiteSpace == WS_COLLAPSE ){ 1374 reportError( "whiteSpace-valid-restriction.1", new Object []{fTypeName, "replace"}); 1375 } 1376 if ( fWhiteSpace == WS_PRESERVE && fBase.fWhiteSpace == WS_REPLACE ){ 1377 reportError( "whiteSpace-valid-restriction.2", new Object []{fTypeName}); 1378 } 1379 } 1380 } 1382 1384 if ( (fFacetsDefined & FACET_LENGTH) == 0 && (fBase.fFacetsDefined & FACET_LENGTH) != 0 ) { 1386 fFacetsDefined |= FACET_LENGTH; 1387 fLength = fBase.fLength; 1388 lengthAnnotation = fBase.lengthAnnotation; 1389 } 1390 if ( (fFacetsDefined & FACET_MINLENGTH) == 0 && (fBase.fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1392 fFacetsDefined |= FACET_MINLENGTH; 1393 fMinLength = fBase.fMinLength; 1394 minLengthAnnotation = fBase.minLengthAnnotation; 1395 } 1396 if ((fFacetsDefined & FACET_MAXLENGTH) == 0 && (fBase.fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1398 fFacetsDefined |= FACET_MAXLENGTH; 1399 fMaxLength = fBase.fMaxLength; 1400 maxLengthAnnotation = fBase.maxLengthAnnotation; 1401 } 1402 if ( (fBase.fFacetsDefined & FACET_PATTERN) != 0 ) { 1404 if ((fFacetsDefined & FACET_PATTERN) == 0) { 1405 fPattern = fBase.fPattern; 1406 fPatternStr = fBase.fPatternStr; 1407 fFacetsDefined |= FACET_PATTERN; 1408 } 1409 else { 1410 for (int i = fBase.fPattern.size()-1; i >= 0; i--) { 1411 fPattern.addElement(fBase.fPattern.elementAt(i)); 1412 fPatternStr.addElement(fBase.fPatternStr.elementAt(i)); 1413 } 1414 if (fBase.patternAnnotations != null){ 1415 for (int i = fBase.patternAnnotations.getLength()-1;i>=0;i--){ 1416 patternAnnotations.add(fBase.patternAnnotations.item(i)); 1417 } 1418 } 1419 } 1420 } 1421 if ( (fFacetsDefined & FACET_WHITESPACE) == 0 && (fBase.fFacetsDefined & FACET_WHITESPACE) != 0 ) { 1423 fFacetsDefined |= FACET_WHITESPACE; 1424 fWhiteSpace = fBase.fWhiteSpace; 1425 whiteSpaceAnnotation = fBase.whiteSpaceAnnotation; 1426 } 1427 if ((fFacetsDefined & FACET_ENUMERATION) == 0 && (fBase.fFacetsDefined & FACET_ENUMERATION) != 0) { 1429 fFacetsDefined |= FACET_ENUMERATION; 1430 fEnumeration = fBase.fEnumeration; 1431 enumerationAnnotations = fBase.enumerationAnnotations; 1432 } 1433 if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && 1435 !((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1436 fFacetsDefined |= FACET_MAXEXCLUSIVE; 1437 fMaxExclusive = fBase.fMaxExclusive; 1438 maxExclusiveAnnotation = fBase.maxExclusiveAnnotation; 1439 } 1440 if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && 1442 !((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) { 1443 fFacetsDefined |= FACET_MAXINCLUSIVE; 1444 fMaxInclusive = fBase.fMaxInclusive; 1445 maxInclusiveAnnotation = fBase.maxInclusiveAnnotation; 1446 } 1447 if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && 1449 !((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1450 fFacetsDefined |= FACET_MINEXCLUSIVE; 1451 fMinExclusive = fBase.fMinExclusive; 1452 minExclusiveAnnotation = fBase.minExclusiveAnnotation; 1453 } 1454 if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0) && 1456 !((fFacetsDefined & FACET_MINEXCLUSIVE) != 0) && !((fFacetsDefined & FACET_MININCLUSIVE) != 0)) { 1457 fFacetsDefined |= FACET_MININCLUSIVE; 1458 fMinInclusive = fBase.fMinInclusive; 1459 minInclusiveAnnotation = fBase.minInclusiveAnnotation; 1460 } 1461 if ((( fBase.fFacetsDefined & FACET_TOTALDIGITS) != 0) && 1463 !((fFacetsDefined & FACET_TOTALDIGITS) != 0)) { 1464 fFacetsDefined |= FACET_TOTALDIGITS; 1465 fTotalDigits = fBase.fTotalDigits; 1466 totalDigitsAnnotation = fBase.totalDigitsAnnotation; 1467 } 1468 if ((( fBase.fFacetsDefined & FACET_FRACTIONDIGITS) != 0) 1470 && !((fFacetsDefined & FACET_FRACTIONDIGITS) != 0)) { 1471 fFacetsDefined |= FACET_FRACTIONDIGITS; 1472 fFractionDigits = fBase.fFractionDigits; 1473 fractionDigitsAnnotation = fBase.fractionDigitsAnnotation; 1474 } 1475 if ((fPatternType == SPECIAL_PATTERN_NONE ) && (fBase.fPatternType != SPECIAL_PATTERN_NONE)) { 1477 fPatternType = fBase.fPatternType ; 1478 } 1479 1480 fFixedFacet |= fBase.fFixedFacet; 1482 1483 caclFundamentalFacets(); 1485 1486 } 1488 1491 public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1492 1493 if (context == null) 1494 context = fEmptyContext; 1495 1496 if (validatedInfo == null) 1497 validatedInfo = new ValidatedInfo(); 1498 else 1499 validatedInfo.memberType = null; 1500 1501 boolean needNormalize = context==null||context.needToNormalize(); 1503 Object ob = getActualValue(content, context, validatedInfo, needNormalize); 1504 1505 validate(context, validatedInfo); 1506 1507 return ob; 1508 1509 } 1510 1511 1514 public ValidatedInfo validateWithInfo(String content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1515 1516 if (context == null) 1517 context = fEmptyContext; 1518 1519 if (validatedInfo == null) 1520 validatedInfo = new ValidatedInfo(); 1521 else 1522 validatedInfo.memberType = null; 1523 1524 boolean needNormalize = context==null||context.needToNormalize(); 1526 getActualValue(content, context, validatedInfo, needNormalize); 1527 1528 validate(context, validatedInfo); 1529 1530 return validatedInfo; 1531 1532 } 1533 1534 1537 public Object validate(Object content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1538 1539 if (context == null) 1540 context = fEmptyContext; 1541 1542 if (validatedInfo == null) 1543 validatedInfo = new ValidatedInfo(); 1544 else 1545 validatedInfo.memberType = null; 1546 1547 boolean needNormalize = context==null||context.needToNormalize(); 1549 Object ob = getActualValue(content, context, validatedInfo, needNormalize); 1550 1551 validate(context, validatedInfo); 1552 1553 return ob; 1554 1555 } 1556 1557 1563 public void validate(ValidationContext context, ValidatedInfo validatedInfo) 1564 throws InvalidDatatypeValueException { 1565 1566 if (context == null) 1567 context = fEmptyContext; 1568 1569 if (context.needFacetChecking() && 1571 (fFacetsDefined != 0 && fFacetsDefined != FACET_WHITESPACE)) { 1572 checkFacets(validatedInfo); 1573 } 1574 1575 if (context.needExtraChecking()) { 1577 checkExtraRules(context, validatedInfo); 1578 } 1579 1580 } 1581 1582 private void checkFacets(ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1583 1584 Object ob = validatedInfo.actualValue; 1585 String content = validatedInfo.normalizedValue; 1586 short type = validatedInfo.actualValueType; 1587 ShortList itemType = validatedInfo.itemValueTypes; 1588 1589 if (fValidationDV != DV_QNAME && fValidationDV != DV_NOTATION) { 1591 int length = fDVs[fValidationDV].getDataLength(ob); 1592 1593 if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) { 1595 if ( length > fMaxLength ) { 1596 throw new InvalidDatatypeValueException("cvc-maxLength-valid", 1597 new Object []{content, Integer.toString(length), Integer.toString(fMaxLength), fTypeName}); 1598 } 1599 } 1600 1601 if ( (fFacetsDefined & FACET_MINLENGTH) != 0 ) { 1603 if ( length < fMinLength ) { 1604 throw new InvalidDatatypeValueException("cvc-minLength-valid", 1605 new Object []{content, Integer.toString(length), Integer.toString(fMinLength), fTypeName}); 1606 } 1607 } 1608 1609 if ( (fFacetsDefined & FACET_LENGTH) != 0 ) { 1611 if ( length != fLength ) { 1612 throw new InvalidDatatypeValueException("cvc-length-valid", 1613 new Object []{content, Integer.toString(length), Integer.toString(fLength), fTypeName}); 1614 } 1615 } 1616 } 1617 1618 if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) { 1620 boolean present = false; 1621 final int enumSize = fEnumeration.size(); 1622 final short primitiveType1 = convertToPrimitiveKind(type); 1623 for (int i = 0; i < enumSize; i++) { 1624 final short primitiveType2 = convertToPrimitiveKind(fEnumerationType[i]); 1625 if ((primitiveType1 == primitiveType2 || 1626 primitiveType1 == XSConstants.ANYSIMPLETYPE_DT && primitiveType2 == XSConstants.STRING_DT || 1627 primitiveType1 == XSConstants.STRING_DT && primitiveType2 == XSConstants.ANYSIMPLETYPE_DT) 1628 && fEnumeration.elementAt(i).equals(ob)) { 1629 if (primitiveType1 == XSConstants.LIST_DT || primitiveType1 == XSConstants.LISTOFUNION_DT) { 1630 ShortList enumItemType = fEnumerationItemType[i]; 1631 final int typeList1Length = itemType != null ? itemType.getLength() : 0; 1632 final int typeList2Length = enumItemType != null ? enumItemType.getLength() : 0; 1633 if (typeList1Length == typeList2Length) { 1634 int j; 1635 for (j = 0; j < typeList1Length; ++j) { 1636 final short primitiveItem1 = convertToPrimitiveKind(itemType.item(j)); 1637 final short primitiveItem2 = convertToPrimitiveKind(enumItemType.item(j)); 1638 if (primitiveItem1 != primitiveItem2) { 1639 if (primitiveItem1 == XSConstants.ANYSIMPLETYPE_DT && primitiveItem2 == XSConstants.STRING_DT || 1640 primitiveItem1 == XSConstants.STRING_DT && primitiveItem2 == XSConstants.ANYSIMPLETYPE_DT) { 1641 continue; 1642 } 1643 break; 1644 } 1645 } 1646 if (j == typeList1Length) { 1647 present = true; 1648 break; 1649 } 1650 } 1651 } 1652 else { 1653 present = true; 1654 break; 1655 } 1656 } 1657 } 1658 if(!present){ 1659 throw new InvalidDatatypeValueException("cvc-enumeration-valid", 1660 new Object [] {content, fEnumeration.toString()}); 1661 } 1662 } 1663 1664 if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) { 1666 int scale = fDVs[fValidationDV].getFractionDigits(ob); 1667 if (scale > fFractionDigits) { 1668 throw new InvalidDatatypeValueException("cvc-fractionDigits-valid", 1669 new Object [] {content, Integer.toString(scale), Integer.toString(fFractionDigits)}); 1670 } 1671 } 1672 1673 if ((fFacetsDefined & FACET_TOTALDIGITS)!=0) { 1675 int totalDigits = fDVs[fValidationDV].getTotalDigits(ob); 1676 if (totalDigits > fTotalDigits) { 1677 throw new InvalidDatatypeValueException("cvc-totalDigits-valid", 1678 new Object [] {content, Integer.toString(totalDigits), Integer.toString(fTotalDigits)}); 1679 } 1680 } 1681 1682 int compare; 1683 1684 if ( (fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) { 1686 compare = fDVs[fValidationDV].compare(ob, fMaxInclusive); 1687 if (compare != -1 && compare != 0) { 1688 throw new InvalidDatatypeValueException("cvc-maxInclusive-valid", 1689 new Object [] {content, fMaxInclusive, fTypeName}); 1690 } 1691 } 1692 1693 if ( (fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 ) { 1695 compare = fDVs[fValidationDV].compare(ob, fMaxExclusive ); 1696 if (compare != -1) { 1697 throw new InvalidDatatypeValueException("cvc-maxExclusive-valid", 1698 new Object [] {content, fMaxExclusive, fTypeName}); 1699 } 1700 } 1701 1702 if ( (fFacetsDefined & FACET_MININCLUSIVE) != 0 ) { 1704 compare = fDVs[fValidationDV].compare(ob, fMinInclusive); 1705 if (compare != 1 && compare != 0) { 1706 throw new InvalidDatatypeValueException("cvc-minInclusive-valid", 1707 new Object [] {content, fMinInclusive, fTypeName}); 1708 } 1709 } 1710 1711 if ( (fFacetsDefined & FACET_MINEXCLUSIVE) != 0 ) { 1713 compare = fDVs[fValidationDV].compare(ob, fMinExclusive); 1714 if (compare != 1) { 1715 throw new InvalidDatatypeValueException("cvc-minExclusive-valid", 1716 new Object [] {content, fMinExclusive, fTypeName}); 1717 } 1718 } 1719 1720 } 1721 1722 private void checkExtraRules(ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException { 1723 1724 Object ob = validatedInfo.actualValue; 1725 1726 if (fVariety == VARIETY_ATOMIC) { 1727 1728 fDVs[fValidationDV].checkExtraRules(ob, context); 1729 1730 } else if (fVariety == VARIETY_LIST) { 1731 1732 ListDV.ListData values = (ListDV.ListData)ob; 1733 int len = values.getLength(); 1734 if (fItemType.fVariety == VARIETY_UNION) { 1735 XSSimpleTypeDecl[] memberTypes = (XSSimpleTypeDecl[])validatedInfo.memberTypes; 1736 XSSimpleType memberType = validatedInfo.memberType; 1737 for (int i = len-1; i >= 0; i--) { 1738 validatedInfo.actualValue = values.item(i); 1739 validatedInfo.memberType = memberTypes[i]; 1740 fItemType.checkExtraRules(context, validatedInfo); 1741 } 1742 validatedInfo.memberType = memberType; 1743 } else { for (int i = len-1; i >= 0; i--) { 1745 validatedInfo.actualValue = values.item(i); 1746 fItemType.checkExtraRules(context, validatedInfo); 1747 } 1748 } 1749 validatedInfo.actualValue = values; 1750 1751 } else { 1753 ((XSSimpleTypeDecl)validatedInfo.memberType).checkExtraRules(context, validatedInfo); 1754 1755 } 1756 1757 } 1759 private Object getActualValue(Object content, ValidationContext context, 1761 ValidatedInfo validatedInfo, boolean needNormalize) 1762 throws InvalidDatatypeValueException{ 1763 1764 String nvalue; 1765 if (needNormalize) { 1766 nvalue = normalize(content, fWhiteSpace); 1767 } else { 1768 nvalue = content.toString(); 1769 } 1770 if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) { 1771 RegularExpression regex; 1772 for (int idx = fPattern.size()-1; idx >= 0; idx--) { 1773 regex = (RegularExpression)fPattern.elementAt(idx); 1774 if (!regex.matches(nvalue)){ 1775 throw new InvalidDatatypeValueException("cvc-pattern-valid", 1776 new Object []{content, 1777 fPatternStr.elementAt(idx), 1778 1779 fTypeName}); 1780 } 1781 } 1782 } 1783 1784 if (fVariety == VARIETY_ATOMIC) { 1785 1786 if (fPatternType != SPECIAL_PATTERN_NONE) { 1788 1789 boolean seenErr = false; 1790 if (fPatternType == SPECIAL_PATTERN_NMTOKEN) { 1791 seenErr = !XMLChar.isValidNmtoken(nvalue); 1793 } 1794 else if (fPatternType == SPECIAL_PATTERN_NAME) { 1795 seenErr = !XMLChar.isValidName(nvalue); 1797 } 1798 else if (fPatternType == SPECIAL_PATTERN_NCNAME) { 1799 seenErr = !XMLChar.isValidNCName(nvalue); 1801 } 1802 if (seenErr) { 1803 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", 1804 new Object []{nvalue, SPECIAL_PATTERN_STRING[fPatternType]}); 1805 } 1806 } 1807 1808 validatedInfo.normalizedValue = nvalue; 1809 Object avalue = fDVs[fValidationDV].getActualValue(nvalue, context); 1810 validatedInfo.actualValue = avalue; 1811 validatedInfo.actualValueType = fBuiltInKind; 1812 1813 return avalue; 1814 1815 } else if (fVariety == VARIETY_LIST) { 1816 1817 StringTokenizer parsedList = new StringTokenizer (nvalue, " "); 1818 int countOfTokens = parsedList.countTokens() ; 1819 Object [] avalue = new Object [countOfTokens]; 1820 boolean isUnion = fItemType.getVariety() == VARIETY_UNION; 1821 short[] itemTypes = new short[isUnion ? countOfTokens : 1]; 1822 if (!isUnion) 1823 itemTypes[0] = fItemType.fBuiltInKind; 1824 XSSimpleTypeDecl[] memberTypes = new XSSimpleTypeDecl[countOfTokens]; 1825 for(int i = 0 ; i < countOfTokens ; i ++){ 1826 avalue[i] = fItemType.getActualValue(parsedList.nextToken(), context, validatedInfo, false); 1833 if (context.needFacetChecking() && 1834 (fItemType.fFacetsDefined != 0 && fItemType.fFacetsDefined != FACET_WHITESPACE)) { 1835 fItemType.checkFacets(validatedInfo); 1836 } 1837 memberTypes[i] = (XSSimpleTypeDecl)validatedInfo.memberType; 1838 if (isUnion) 1839 itemTypes[i] = memberTypes[i].fBuiltInKind; 1840 } 1841 1842 ListDV.ListData v = new ListDV.ListData(avalue); 1843 validatedInfo.actualValue = v; 1844 validatedInfo.actualValueType = isUnion ? XSConstants.LISTOFUNION_DT : XSConstants.LIST_DT; 1845 validatedInfo.memberType = null; 1846 validatedInfo.memberTypes = memberTypes; 1847 validatedInfo.itemValueTypes = new ShortListImpl(itemTypes, itemTypes.length); 1848 validatedInfo.normalizedValue = nvalue; 1849 1850 return v; 1851 1852 } else { for(int i = 0 ; i < fMemberTypes.length; i++) { 1854 try { 1855 Object aValue = fMemberTypes[i].getActualValue(content, context, validatedInfo, true); 1862 if (context.needFacetChecking() && 1863 (fMemberTypes[i].fFacetsDefined != 0 && fMemberTypes[i].fFacetsDefined != FACET_WHITESPACE)) { 1864 fMemberTypes[i].checkFacets(validatedInfo); 1865 } 1866 validatedInfo.memberType = fMemberTypes[i]; 1867 return aValue; 1868 } catch(InvalidDatatypeValueException invalidValue) { 1869 } 1870 } 1871 StringBuffer typesBuffer = new StringBuffer (); 1872 XSSimpleTypeDecl decl; 1873 for(int i = 0;i < fMemberTypes.length; i++) { 1874 if(i != 0) 1875 typesBuffer.append(" | "); 1876 decl = fMemberTypes[i]; 1877 if(decl.fTargetNamespace != null) { 1878 typesBuffer.append('{'); 1879 typesBuffer.append(decl.fTargetNamespace); 1880 typesBuffer.append('}'); 1881 } 1882 typesBuffer.append(decl.fTypeName); 1883 if(decl.fEnumeration != null) { 1884 Vector v = decl.fEnumeration; 1885 typesBuffer.append(" : ["); 1886 for(int j = 0;j < v.size(); j++) { 1887 if(j != 0) 1888 typesBuffer.append(','); 1889 typesBuffer.append(v.elementAt(j)); 1890 } 1891 typesBuffer.append(']'); 1892 } 1893 } 1894 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", 1895 new Object []{content, fTypeName, typesBuffer.toString()}); 1896 } 1897 1898 } 1900 public boolean isEqual(Object value1, Object value2) { 1901 if (value1 == null) { 1902 return false; 1903 } 1904 return value1.equals(value2); 1905 } 1907 public boolean isIdentical (Object value1, Object value2) { 1909 if (value1 == null) { 1910 return false; 1911 } 1912 return fDVs[fValidationDV].isIdentical(value1, value2); 1913 } 1915 public static String normalize(String content, short ws) { 1917 int len = content == null ? 0 : content.length(); 1918 if (len == 0 || ws == WS_PRESERVE) 1919 return content; 1920 1921 StringBuffer sb = new StringBuffer (); 1922 if (ws == WS_REPLACE) { 1923 char ch; 1924 for (int i = 0; i < len; i++) { 1926 ch = content.charAt(i); 1927 if (ch != 0x9 && ch != 0xa && ch != 0xd) 1928 sb.append(ch); 1929 else 1930 sb.append((char)0x20); 1931 } 1932 } else { 1933 char ch; 1934 int i; 1935 boolean isLeading = true; 1936 for (i = 0; i < len; i++) { 1938 ch = content.charAt(i); 1939 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { 1941 sb.append(ch); 1942 isLeading = false; 1943 } 1944 else { 1945 for (; i < len-1; i++) { 1947 ch = content.charAt(i+1); 1948 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) 1949 break; 1950 } 1951 if (i < len - 1 && !isLeading) 1953 sb.append((char)0x20); 1954 } 1955 } 1956 } 1957 1958 return sb.toString(); 1959 } 1960 1961 protected String normalize(Object content, short ws) { 1963 if (content == null) 1964 return null; 1965 1966 if ( (fFacetsDefined & FACET_PATTERN ) == 0 ) { 1970 short norm_type = fDVNormalizeType[fValidationDV]; 1971 if (norm_type == NORMALIZE_NONE) { 1972 return content.toString(); 1973 } 1974 else if (norm_type == NORMALIZE_TRIM) { 1975 return content.toString().trim(); 1976 } 1977 } 1978 1979 if (!(content instanceof StringBuffer )) { 1980 String strContent = content.toString(); 1981 return normalize(strContent, ws); 1982 } 1983 1984 StringBuffer sb = (StringBuffer )content; 1985 int len = sb.length(); 1986 if (len == 0) 1987 return ""; 1988 if (ws == WS_PRESERVE) 1989 return sb.toString(); 1990 1991 if (ws == WS_REPLACE) { 1992 char ch; 1993 for (int i = 0; i < len; i++) { 1995 ch = sb.charAt(i); 1996 if (ch == 0x9 || ch == 0xa || ch == 0xd) 1997 sb.setCharAt(i, (char)0x20); 1998 } 1999 } else { 2000 char ch; 2001 int i, j = 0; 2002 boolean isLeading = true; 2003 for (i = 0; i < len; i++) { 2005 ch = sb.charAt(i); 2006 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { 2008 sb.setCharAt(j++, ch); 2009 isLeading = false; 2010 } 2011 else { 2012 for (; i < len-1; i++) { 2014 ch = sb.charAt(i+1); 2015 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) 2016 break; 2017 } 2018 if (i < len - 1 && !isLeading) 2020 sb.setCharAt(j++, (char)0x20); 2021 } 2022 } 2023 sb.setLength(j); 2024 } 2025 2026 return sb.toString(); 2027 } 2028 2029 void reportError(String key, Object [] args) throws InvalidDatatypeFacetException { 2030 throw new InvalidDatatypeFacetException(key, args); 2031 } 2032 2033 2034 private String whiteSpaceValue(short ws){ 2035 return WS_FACET_STRING[ws]; 2036 } 2037 2038 2041 public short getOrdered() { 2042 return fOrdered; 2043 } 2044 2045 2048 public boolean getBounded(){ 2049 return fBounded; 2050 } 2051 2052 2055 public boolean getFinite(){ 2056 return fFinite; 2057 } 2058 2059 2062 public boolean getNumeric(){ 2063 return fNumeric; 2064 } 2065 2066 2072 public boolean isDefinedFacet(short facetName) { 2073 if ((fFacetsDefined & facetName) != 0) 2074 return true; 2075 if (fPatternType != SPECIAL_PATTERN_NONE) 2076 return facetName == FACET_PATTERN; 2077 if (fValidationDV == DV_INTEGER) 2078 return facetName == FACET_PATTERN || facetName == FACET_FRACTIONDIGITS; 2079 return false; 2080 } 2081 2082 2086 public short getDefinedFacets() { 2087 if (fPatternType != SPECIAL_PATTERN_NONE) 2088 return (short)(fFacetsDefined | FACET_PATTERN); 2089 if (fValidationDV == DV_INTEGER) 2090 return (short)(fFacetsDefined | FACET_PATTERN | FACET_FRACTIONDIGITS); 2091 return fFacetsDefined; 2092 } 2093 2094 2100 public boolean isFixedFacet(short facetName) { 2101 if ((fFixedFacet & facetName) != 0) 2102 return true; 2103 if (fValidationDV == DV_INTEGER) 2104 return facetName == FACET_FRACTIONDIGITS; 2105 return false; 2106 } 2107 2108 2111 public short getFixedFacets() { 2112 if (fValidationDV == DV_INTEGER) 2113 return (short)(fFixedFacet | FACET_FRACTIONDIGITS); 2114 return fFixedFacet; 2115 } 2116 2117 2129 public String getLexicalFacetValue(short facetName) { 2130 switch (facetName) { 2131 case FACET_LENGTH: 2132 return (fLength == -1)?null:Integer.toString(fLength); 2133 case FACET_MINLENGTH: 2134 return (fMinLength == -1)?null:Integer.toString(fMinLength); 2135 case FACET_MAXLENGTH: 2136 return (fMaxLength == -1)?null:Integer.toString(fMaxLength); 2137 case FACET_WHITESPACE: 2138 return WS_FACET_STRING[fWhiteSpace]; 2139 case FACET_MAXINCLUSIVE: 2140 return (fMaxInclusive == null)?null:fMaxInclusive.toString(); 2141 case FACET_MAXEXCLUSIVE: 2142 return (fMaxExclusive == null)?null:fMaxExclusive.toString(); 2143 case FACET_MINEXCLUSIVE: 2144 return (fMinExclusive == null)?null:fMinExclusive.toString(); 2145 case FACET_MININCLUSIVE: 2146 return (fMinInclusive == null)?null:fMinInclusive.toString(); 2147 case FACET_TOTALDIGITS: 2148 if (fValidationDV == DV_INTEGER) 2149 return "0"; 2150 return (fTotalDigits == -1)?null:Integer.toString(fTotalDigits); 2151 case FACET_FRACTIONDIGITS: 2152 return (fFractionDigits == -1)?null:Integer.toString(fFractionDigits); 2153 } 2154 return null; 2155 } 2156 2157 2161 public StringList getLexicalEnumeration() { 2162 if (fLexicalEnumeration == null){ 2163 if (fEnumeration == null) 2164 return StringListImpl.EMPTY_LIST; 2165 int size = fEnumeration.size(); 2166 String [] strs = new String [size]; 2167 for (int i = 0; i < size; i++) 2168 strs[i] = fEnumeration.elementAt(i).toString(); 2169 fLexicalEnumeration = new StringListImpl(strs, size); 2170 } 2171 return fLexicalEnumeration; 2172 } 2173 2174 2178 public ObjectList getActualEnumeration() { 2179 if (fActualEnumeration == null) { 2180 fActualEnumeration = new ObjectList () { 2181 public int getLength() { 2182 return (fEnumeration != null) ? fEnumeration.size() : 0; 2183 } 2184 public boolean contains(Object item) { 2185 return (fEnumeration != null && fEnumeration.contains(item)); 2186 } 2187 public Object item(int index) { 2188 if (index < 0 || index >= getLength()) { 2189 return null; 2190 } 2191 return fEnumeration.elementAt(index); 2192 } 2193 }; 2194 } 2195 return fActualEnumeration; 2196 } 2197 2198 2202 public ObjectList getEnumerationItemTypeList() { 2203 if (fEnumerationItemTypeList == null) { 2204 if(fEnumerationItemType == null) 2205 return null; 2206 fEnumerationItemTypeList = new ObjectList () { 2207 public int getLength() { 2208 return (fEnumerationItemType != null) ? fEnumerationItemType.length : 0; 2209 } 2210 public boolean contains(Object item) { 2211 if(fEnumerationItemType == null || !(item instanceof ShortList)) 2212 return false; 2213 for(int i = 0;i < fEnumerationItemType.length; i++) 2214 if(fEnumerationItemType[i] == item) 2215 return true; 2216 return false; 2217 } 2218 public Object item(int index) { 2219 if (index < 0 || index >= getLength()) { 2220 return null; 2221 } 2222 return fEnumerationItemType[index]; 2223 } 2224 }; 2225 } 2226 return fEnumerationItemTypeList; 2227 } 2228 2229 public ShortList getEnumerationTypeList() { 2230 if (fEnumerationTypeList == null) { 2231 if (fEnumerationType == null) 2232 return null; 2233 fEnumerationTypeList = new ShortListImpl (fEnumerationType, fEnumerationType.length); 2234 } 2235 return fEnumerationTypeList; 2236 } 2237 2238 2242 public StringList getLexicalPattern() { 2243 if (fPatternType == SPECIAL_PATTERN_NONE && fValidationDV != DV_INTEGER && fPatternStr == null) 2244 return StringListImpl.EMPTY_LIST; 2245 if (fLexicalPattern == null){ 2246 int size = fPatternStr == null ? 0 : fPatternStr.size(); 2247 String [] strs; 2248 if (fPatternType == SPECIAL_PATTERN_NMTOKEN) { 2249 strs = new String [size+1]; 2250 strs[size] = "\\c+"; 2251 } 2252 else if (fPatternType == SPECIAL_PATTERN_NAME) { 2253 strs = new String [size+1]; 2254 strs[size] = "\\i\\c*"; 2255 } 2256 else if (fPatternType == SPECIAL_PATTERN_NCNAME) { 2257 strs = new String [size+2]; 2258 strs[size] = "\\i\\c*"; 2259 strs[size+1] = "[\\i-[:]][\\c-[:]]*"; 2260 } 2261 else if (fValidationDV == DV_INTEGER) { 2262 strs = new String [size+1]; 2263 strs[size] = "[\\-+]?[0-9]+"; 2264 } 2265 else { 2266 strs = new String [size]; 2267 } 2268 for (int i = 0; i < size; i++) 2269 strs[i] = (String )fPatternStr.elementAt(i); 2270 fLexicalPattern = new StringListImpl(strs, strs.length); 2271 } 2272 return fLexicalPattern; 2273 } 2274 2275 2279 public XSObjectList getAnnotations() { 2280 return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST; 2281 } 2282 2283 private void caclFundamentalFacets() { 2284 setOrdered(); 2285 setNumeric(); 2286 setBounded(); 2287 setCardinality(); 2288 } 2289 2290 private void setOrdered(){ 2291 2292 if(fVariety == VARIETY_ATOMIC){ 2294 this.fOrdered = fBase.fOrdered; 2295 } 2296 2297 else if(fVariety == VARIETY_LIST){ 2299 this.fOrdered = ORDERED_FALSE; 2300 } 2301 2302 else if(fVariety == VARIETY_UNION){ 2306 int length = fMemberTypes.length; 2307 if (length == 0) { 2309 this.fOrdered = ORDERED_PARTIAL; 2310 return; 2311 } 2312 short ancestorId = getPrimitiveDV(fMemberTypes[0].fValidationDV); 2314 boolean commonAnc = ancestorId != DV_ANYSIMPLETYPE; 2315 boolean allFalse = fMemberTypes[0].fOrdered == ORDERED_FALSE; 2316 for (int i = 1; i < fMemberTypes.length && (commonAnc || allFalse); i++) { 2319 if (commonAnc) 2320 commonAnc = ancestorId == getPrimitiveDV(fMemberTypes[i].fValidationDV); 2321 if (allFalse) 2322 allFalse = fMemberTypes[i].fOrdered == ORDERED_FALSE; 2323 } 2324 if (commonAnc) { 2325 this.fOrdered = fMemberTypes[0].fOrdered; 2328 } else if (allFalse) { 2329 this.fOrdered = ORDERED_FALSE; 2330 } else { 2331 this.fOrdered = ORDERED_PARTIAL; 2332 } 2333 } 2334 2335 } 2337 private void setNumeric(){ 2338 if(fVariety == VARIETY_ATOMIC){ 2339 this.fNumeric = fBase.fNumeric; 2340 } 2341 else if(fVariety == VARIETY_LIST){ 2342 this.fNumeric = false; 2343 } 2344 else if(fVariety == VARIETY_UNION){ 2345 XSSimpleType[] memberTypes = fMemberTypes; 2346 for(int i = 0 ; i < memberTypes.length ; i++){ 2347 if(!memberTypes[i].getNumeric() ){ 2348 this.fNumeric = false; 2349 return; 2350 } 2351 } 2352 this.fNumeric = true; 2353 } 2354 2355 } 2357 private void setBounded(){ 2358 if(fVariety == VARIETY_ATOMIC){ 2359 if( (((this.fFacetsDefined & FACET_MININCLUSIVE) != 0) || ((this.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) 2360 && (((this.fFacetsDefined & FACET_MAXINCLUSIVE) != 0) || ((this.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) ){ 2361 this.fBounded = true; 2362 } 2363 else{ 2364 this.fBounded = false; 2365 } 2366 } 2367 else if(fVariety == VARIETY_LIST){ 2368 if( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ( ((this.fFacetsDefined & FACET_MINLENGTH) != 0 ) 2369 && ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 )) ){ 2370 this.fBounded = true; 2371 } 2372 else{ 2373 this.fBounded = false; 2374 } 2375 2376 } 2377 else if(fVariety == VARIETY_UNION){ 2378 2379 XSSimpleTypeDecl [] memberTypes = this.fMemberTypes; 2380 short ancestorId = 0 ; 2381 2382 if(memberTypes.length > 0){ 2383 ancestorId = getPrimitiveDV(memberTypes[0].fValidationDV); 2384 } 2385 2386 for(int i = 0 ; i < memberTypes.length ; i++){ 2387 if(!memberTypes[i].getBounded() || (ancestorId != getPrimitiveDV(memberTypes[i].fValidationDV)) ){ 2388 this.fBounded = false; 2389 return; 2390 } 2391 } 2392 this.fBounded = true; 2393 } 2394 2395 } 2397 private boolean specialCardinalityCheck(){ 2398 if( (fBase.fValidationDV == XSSimpleTypeDecl.DV_DATE) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GYEARMONTH) 2399 || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GYEAR) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GMONTHDAY) 2400 || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GDAY) || (fBase.fValidationDV == XSSimpleTypeDecl.DV_GMONTH) ){ 2401 return true; 2402 } 2403 return false; 2404 2405 } 2407 private void setCardinality(){ 2408 if(fVariety == VARIETY_ATOMIC){ 2409 if(fBase.fFinite){ 2410 this.fFinite = true; 2411 } 2412 else { if ( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 ) 2414 || ((this.fFacetsDefined & FACET_TOTALDIGITS) != 0 ) ){ 2415 this.fFinite = true; 2416 } 2417 else if( (((this.fFacetsDefined & FACET_MININCLUSIVE) != 0 ) || ((this.fFacetsDefined & FACET_MINEXCLUSIVE) != 0 )) 2418 && (((this.fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) || ((this.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 )) ){ 2419 if( ((this.fFacetsDefined & FACET_FRACTIONDIGITS) != 0 ) || specialCardinalityCheck()){ 2420 this.fFinite = true; 2421 } 2422 else{ 2423 this.fFinite = false; 2424 } 2425 } 2426 else{ 2427 this.fFinite = false; 2428 } 2429 } 2430 } 2431 else if(fVariety == VARIETY_LIST){ 2432 if( ((this.fFacetsDefined & FACET_LENGTH) != 0 ) || ( ((this.fFacetsDefined & FACET_MINLENGTH) != 0 ) 2433 && ((this.fFacetsDefined & FACET_MAXLENGTH) != 0 )) ){ 2434 this.fFinite = true; 2435 } 2436 else{ 2437 this.fFinite = false; 2438 } 2439 2440 } 2441 else if(fVariety == VARIETY_UNION){ 2442 XSSimpleType [] memberTypes = fMemberTypes; 2443 for(int i = 0 ; i < memberTypes.length ; i++){ 2444 if(!(memberTypes[i].getFinite()) ){ 2445 this.fFinite = false; 2446 return; 2447 } 2448 } 2449 this.fFinite = true; 2450 } 2451 2452 } 2454 private short getPrimitiveDV(short validationDV){ 2455 2456 if (validationDV == DV_ID || validationDV == DV_IDREF || validationDV == DV_ENTITY){ 2457 return DV_STRING; 2458 } 2459 else if (validationDV == DV_INTEGER) { 2460 return DV_DECIMAL; 2461 } 2462 else if (Constants.SCHEMA_1_1_SUPPORT && (validationDV == DV_YEARMONTHDURATION || validationDV == DV_DAYTIMEDURATION)) { 2463 return DV_DURATION; 2464 } 2465 else { 2466 return validationDV; 2467 } 2468 2469 } 2471 public boolean derivedFromType(XSTypeDefinition ancestor, short derivation) { 2472 2474 if (ancestor == null) 2476 return false; 2477 if (ancestor.getBaseType() == ancestor) 2480 return true; 2481 XSTypeDefinition type = this; 2483 while (type != ancestor && type != fAnySimpleType) { type = type.getBaseType(); 2486 } 2487 2488 return type == ancestor; 2489 } 2490 2491 public boolean derivedFrom(String ancestorNS, String ancestorName, short derivation) { 2492 2494 if (ancestorName == null) 2496 return false; 2497 if (URI_SCHEMAFORSCHEMA.equals(ancestorNS) && 2499 ANY_TYPE.equals(ancestorName)) { 2500 return true; 2501 } 2502 2503 XSTypeDefinition type = this; 2505 while (!(ancestorName.equals(type.getName()) && 2506 ((ancestorNS == null && type.getNamespace() == null) || 2507 (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) && type != fAnySimpleType) { type = (XSTypeDefinition)type.getBaseType(); 2510 } 2511 2512 return type != fAnySimpleType; 2513 } 2514 2515 2529 public boolean isDOMDerivedFrom(String ancestorNS, String ancestorName, int derivationMethod) { 2530 2531 if (ancestorName == null) 2533 return false; 2534 2535 if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(ancestorNS) 2537 && SchemaSymbols.ATTVAL_ANYTYPE.equals(ancestorName) 2538 && (((derivationMethod & DERIVATION_RESTRICTION) != 0) 2539 || (derivationMethod == DERIVATION_ANY))) { 2540 return true; 2541 } 2542 2543 if ((derivationMethod & DERIVATION_RESTRICTION) != 0) { 2545 if (isDerivedByRestriction(ancestorNS, ancestorName, this)) { 2546 return true; 2547 } 2548 } 2549 2550 if ((derivationMethod & DERIVATION_LIST) != 0) { 2552 if (isDerivedByList(ancestorNS, ancestorName, this)) { 2553 return true; 2554 } 2555 } 2556 2557 if ((derivationMethod & DERIVATION_UNION) != 0) { 2559 if (isDerivedByUnion(ancestorNS, ancestorName, this)) { 2560 return true; 2561 } 2562 } 2563 2564 if (((derivationMethod & DERIVATION_EXTENSION) != 0) 2566 && (((derivationMethod & DERIVATION_RESTRICTION) == 0) 2567 && ((derivationMethod & DERIVATION_LIST) == 0) 2568 && ((derivationMethod & DERIVATION_UNION) == 0))) { 2569 return false; 2570 } 2571 2572 if (((derivationMethod & DERIVATION_EXTENSION) == 0) 2576 && (((derivationMethod & DERIVATION_RESTRICTION) == 0) 2577 && ((derivationMethod & DERIVATION_LIST) == 0) 2578 && ((derivationMethod & DERIVATION_UNION) == 0))) { 2579 return isDerivedByAny(ancestorNS, ancestorName, this); 2580 } 2581 2582 return false; 2583 } 2584 2585 2586 2599 private boolean isDerivedByAny(String ancestorNS, String ancestorName, 2600 XSTypeDefinition type) { 2601 2602 boolean derivedFrom = false; 2603 XSTypeDefinition oldType = null; 2604 while (type != null && type != oldType) { 2606 2607 if ((ancestorName.equals(type.getName())) 2609 && ((ancestorNS == null && type.getNamespace() == null) 2610 || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) { 2611 derivedFrom = true; 2612 break; 2613 } 2614 2615 if (isDerivedByRestriction(ancestorNS, ancestorName, type)) { 2617 return true; 2618 } else if (isDerivedByList(ancestorNS, ancestorName, type)) { 2619 return true; 2620 } else if (isDerivedByUnion(ancestorNS, ancestorName, type)) { 2621 return true; 2622 } 2623 oldType = type; 2624 if (((XSSimpleTypeDecl) type).getVariety() == VARIETY_ABSENT 2626 || ((XSSimpleTypeDecl) type).getVariety() == VARIETY_ATOMIC) { 2627 type = type.getBaseType(); 2628 } else if (((XSSimpleTypeDecl) type).getVariety() == VARIETY_UNION) { 2629 for (int i = 0; i < ((XSSimpleTypeDecl) type).getMemberTypes().getLength(); i++) { 2630 return isDerivedByAny(ancestorNS, ancestorName, 2631 (XSTypeDefinition) ((XSSimpleTypeDecl) type) 2632 .getMemberTypes().item(i)); 2633 } 2634 } else if (((XSSimpleTypeDecl) type).getVariety() == VARIETY_LIST) { 2635 type = ((XSSimpleTypeDecl) type).getItemType(); 2636 } 2637 } 2638 2639 return derivedFrom; 2640 } 2641 2642 2657 private boolean isDerivedByRestriction (String ancestorNS, String ancestorName, XSTypeDefinition type) { 2658 XSTypeDefinition oldType = null; 2659 while (type != null && type != oldType) { 2660 if ((ancestorName.equals(type.getName())) 2661 && ((ancestorNS != null && ancestorNS.equals(type.getNamespace())) 2662 || (type.getNamespace() == null && ancestorNS == null))) { 2663 2664 return true; 2665 } 2666 oldType = type; 2667 type = type.getBaseType(); 2668 } 2669 2670 return false; 2671 } 2672 2673 2686 private boolean isDerivedByList (String ancestorNS, String ancestorName, XSTypeDefinition type) { 2687 if (type !=null && ((XSSimpleTypeDefinition)type).getVariety() == VARIETY_LIST) { 2689 2690 XSTypeDefinition itemType = ((XSSimpleTypeDefinition)type).getItemType(); 2692 2693 if (itemType != null) { 2695 2696 if (isDerivedByRestriction(ancestorNS, ancestorName, itemType)) { 2698 return true; 2699 } 2700 } 2701 } 2702 return false; 2703 } 2704 2705 2718 private boolean isDerivedByUnion (String ancestorNS, String ancestorName, XSTypeDefinition type) { 2719 2720 if (type !=null && ((XSSimpleTypeDefinition)type).getVariety() == VARIETY_UNION) { 2722 2723 XSObjectList memberTypes = ((XSSimpleTypeDefinition)type).getMemberTypes(); 2725 2726 for (int i = 0; i < memberTypes.getLength(); i++) { 2727 if (memberTypes.item(i) != null) { 2729 if (isDerivedByRestriction(ancestorNS, ancestorName,(XSSimpleTypeDefinition)memberTypes.item(i))) { 2731 return true; 2732 } 2733 } 2734 } 2735 } 2736 return false; 2737 } 2738 2739 2740 static final XSSimpleTypeDecl fAnySimpleType = new XSSimpleTypeDecl(null, "anySimpleType", DV_ANYSIMPLETYPE, ORDERED_FALSE, false, true, false, true, XSConstants.ANYSIMPLETYPE_DT); 2741 2742 static final XSSimpleTypeDecl fAnyAtomicType = new XSSimpleTypeDecl(fAnySimpleType, "anyAtomicType", DV_ANYATOMICTYPE, ORDERED_FALSE, false, true, false, true, XSSimpleTypeDecl.ANYATOMICTYPE_DT); 2743 2744 2747 static final ValidationContext fDummyContext = new ValidationContext() { 2748 public boolean needFacetChecking() { 2749 return true; 2750 } 2751 2752 public boolean needExtraChecking() { 2753 return false; 2754 } 2755 public boolean needToNormalize() { 2756 return false; 2757 } 2758 public boolean useNamespaces() { 2759 return true; 2760 } 2761 2762 public boolean isEntityDeclared(String name) { 2763 return false; 2764 } 2765 2766 public boolean isEntityUnparsed(String name) { 2767 return false; 2768 } 2769 2770 public boolean isIdDeclared(String name) { 2771 return false; 2772 } 2773 2774 public void addId(String name) { 2775 } 2776 2777 public void addIdRef(String name) { 2778 } 2779 2780 public String getSymbol (String symbol) { 2781 return symbol.intern(); 2782 } 2783 2784 public String getURI(String prefix) { 2785 return null; 2786 } 2787 }; 2788 2789 private boolean fAnonymous = false; 2790 2791 2795 class ValidationContextImpl implements ValidationContext { 2796 ValidationContext fExternal; 2797 ValidationContextImpl(ValidationContext external) { 2798 fExternal = external; 2799 } 2800 2801 NamespaceContext fNSContext; 2802 void setNSContext(NamespaceContext nsContext) { 2803 fNSContext = nsContext; 2804 } 2805 2806 public boolean needFacetChecking() { 2807 return fExternal.needFacetChecking(); 2808 } 2809 2810 public boolean needExtraChecking() { 2811 return fExternal.needExtraChecking(); 2812 } 2813 public boolean needToNormalize() { 2814 return fExternal.needToNormalize(); 2815 } 2816 public boolean useNamespaces() { 2818 return true; 2819 } 2820 2821 public boolean isEntityDeclared (String name) { 2822 return fExternal.isEntityDeclared(name); 2823 } 2824 2825 public boolean isEntityUnparsed (String name) { 2826 return fExternal.isEntityUnparsed(name); 2827 } 2828 2829 public boolean isIdDeclared (String name) { 2830 return fExternal.isIdDeclared(name); 2831 } 2832 2833 public void addId(String name) { 2834 fExternal.addId(name); 2835 } 2836 2837 public void addIdRef(String name) { 2838 fExternal.addIdRef(name); 2839 } 2840 2841 public String getSymbol (String symbol) { 2842 return fExternal.getSymbol(symbol); 2843 } 2844 2845 public String getURI(String prefix) { 2846 if (fNSContext == null) 2847 return fExternal.getURI(prefix); 2848 else 2849 return fNSContext.getURI(prefix); 2850 } 2851 } 2852 2853 public void reset(){ 2854 2855 if (fIsImmutable) return; 2857 fItemType = null; 2858 fMemberTypes = null; 2859 2860 fTypeName = null; 2861 fTargetNamespace = null; 2862 fFinalSet = 0; 2863 fBase = null; 2864 fVariety = -1; 2865 fValidationDV = -1; 2866 2867 fFacetsDefined = 0; 2868 fFixedFacet = 0; 2869 2870 fWhiteSpace = 0; 2872 fLength = -1; 2873 fMinLength = -1; 2874 fMaxLength = -1; 2875 fTotalDigits = -1; 2876 fFractionDigits = -1; 2877 fPattern = null; 2878 fPatternStr = null; 2879 fEnumeration = null; 2880 fEnumerationType = null; 2881 fEnumerationItemType = null; 2882 fLexicalPattern = null; 2883 fLexicalEnumeration = null; 2884 fMaxInclusive = null; 2885 fMaxExclusive = null; 2886 fMinExclusive = null; 2887 fMinInclusive = null; 2888 lengthAnnotation = null; 2889 minLengthAnnotation = null; 2890 maxLengthAnnotation = null; 2891 whiteSpaceAnnotation = null; 2892 totalDigitsAnnotation = null; 2893 fractionDigitsAnnotation = null; 2894 patternAnnotations = null; 2895 enumerationAnnotations = null; 2896 maxInclusiveAnnotation = null; 2897 maxExclusiveAnnotation = null; 2898 minInclusiveAnnotation = null; 2899 minExclusiveAnnotation = null; 2900 2901 fPatternType = SPECIAL_PATTERN_NONE; 2902 fAnnotations = null; 2903 fFacets = null; 2904 2905 } 2907 2910 public XSNamespaceItem getNamespaceItem() { 2911 return null; 2913 } 2914 2915 2918 public String toString() { 2919 return this.fTargetNamespace+"," +this.fTypeName; 2920 } 2921 2922 2928 public XSObjectList getFacets() { 2929 if (fFacets == null && 2930 (fFacetsDefined != 0 || fValidationDV == DV_INTEGER)) { 2931 2932 XSFacetImpl[] facets = new XSFacetImpl[10]; 2933 int count = 0; 2934 if ((fFacetsDefined & FACET_WHITESPACE) != 0) { 2935 facets[count] = 2936 new XSFacetImpl( 2937 FACET_WHITESPACE, 2938 WS_FACET_STRING[fWhiteSpace], 2939 (fFixedFacet & FACET_WHITESPACE) != 0, 2940 whiteSpaceAnnotation); 2941 count++; 2942 } 2943 if (fLength != -1) { 2944 facets[count] = 2945 new XSFacetImpl( 2946 FACET_LENGTH, 2947 Integer.toString(fLength), 2948 (fFixedFacet & FACET_LENGTH) != 0, 2949 lengthAnnotation); 2950 count++; 2951 } 2952 if (fMinLength != -1) { 2953 facets[count] = 2954 new XSFacetImpl( 2955 FACET_MINLENGTH, 2956 Integer.toString(fMinLength), 2957 (fFixedFacet & FACET_MINLENGTH) != 0, 2958 minLengthAnnotation); 2959 count++; 2960 } 2961 if (fMaxLength != -1) { 2962 facets[count] = 2963 new XSFacetImpl( 2964 FACET_MAXLENGTH, 2965 Integer.toString(fMaxLength), 2966 (fFixedFacet & FACET_MAXLENGTH) != 0, 2967 maxLengthAnnotation); 2968 count++; 2969 } 2970 if (fTotalDigits != -1) { 2971 facets[count] = 2972 new XSFacetImpl( 2973 FACET_TOTALDIGITS, 2974 Integer.toString(fTotalDigits), 2975 (fFixedFacet & FACET_TOTALDIGITS) != 0, 2976 totalDigitsAnnotation); 2977 count++; 2978 } 2979 if (fValidationDV == DV_INTEGER) { 2980 facets[count] = 2981 new XSFacetImpl( 2982 FACET_FRACTIONDIGITS, 2983 "0", 2984 true, 2985 null); 2986 count++; 2987 } 2988 if (fFractionDigits != -1) { 2989 facets[count] = 2990 new XSFacetImpl( 2991 FACET_FRACTIONDIGITS, 2992 Integer.toString(fFractionDigits), 2993 (fFixedFacet & FACET_FRACTIONDIGITS) != 0, 2994 fractionDigitsAnnotation); 2995 count++; 2996 } 2997 if (fMaxInclusive != null) { 2998 facets[count] = 2999 new XSFacetImpl( 3000 FACET_MAXINCLUSIVE, 3001 fMaxInclusive.toString(), 3002 (fFixedFacet & FACET_MAXINCLUSIVE) != 0, 3003 maxInclusiveAnnotation); 3004 count++; 3005 } 3006 if (fMaxExclusive != null) { 3007 facets[count] = 3008 new XSFacetImpl( 3009 FACET_MAXEXCLUSIVE, 3010 fMaxExclusive.toString(), 3011 (fFixedFacet & FACET_MAXEXCLUSIVE) != 0, 3012 maxExclusiveAnnotation); 3013 count++; 3014 } 3015 if (fMinExclusive != null) { 3016 facets[count] = 3017 new XSFacetImpl( 3018 FACET_MINEXCLUSIVE, 3019 fMinExclusive.toString(), 3020 (fFixedFacet & FACET_MINEXCLUSIVE) != 0, 3021 minExclusiveAnnotation); 3022 count++; 3023 } 3024 if (fMinInclusive != null) { 3025 facets[count] = 3026 new XSFacetImpl( 3027 FACET_MININCLUSIVE, 3028 fMinInclusive.toString(), 3029 (fFixedFacet & FACET_MININCLUSIVE) != 0, 3030 minInclusiveAnnotation); 3031 count++; 3032 } 3033 fFacets = new XSObjectListImpl(facets, count); 3034 } 3035 return (fFacets != null) ? fFacets : XSObjectListImpl.EMPTY_LIST; 3036 } 3037 3038 3042 public XSObjectList getMultiValueFacets() { 3043 if (fMultiValueFacets == null && 3044 ((fFacetsDefined & FACET_ENUMERATION) != 0 || 3045 (fFacetsDefined & FACET_PATTERN) != 0 || 3046 fPatternType != SPECIAL_PATTERN_NONE || 3047 fValidationDV == DV_INTEGER)) { 3048 3049 XSMVFacetImpl[] facets = new XSMVFacetImpl[2]; 3050 int count = 0; 3051 if ((fFacetsDefined & FACET_PATTERN) != 0 || 3052 fPatternType != SPECIAL_PATTERN_NONE || 3053 fValidationDV == DV_INTEGER) { 3054 facets[count] = 3055 new XSMVFacetImpl( 3056 FACET_PATTERN, 3057 this.getLexicalPattern(), 3058 patternAnnotations); 3059 count++; 3060 } 3061 if (fEnumeration != null) { 3062 facets[count] = 3063 new XSMVFacetImpl( 3064 FACET_ENUMERATION, 3065 this.getLexicalEnumeration(), 3066 enumerationAnnotations); 3067 count++; 3068 } 3069 fMultiValueFacets = new XSObjectListImpl(facets, count); 3070 } 3071 return (fMultiValueFacets != null) ? 3072 fMultiValueFacets : XSObjectListImpl.EMPTY_LIST; 3073 } 3074 3075 public Object getMinInclusiveValue() { 3076 return fMinInclusive; 3077 } 3078 3079 public Object getMinExclusiveValue() { 3080 return fMinExclusive; 3081 } 3082 3083 public Object getMaxInclusiveValue() { 3084 return fMaxInclusive; 3085 } 3086 3087 public Object getMaxExclusiveValue() { 3088 return fMaxExclusive; 3089 } 3090 3091 public void setAnonymous(boolean anon) { 3092 fAnonymous = anon; 3093 } 3094 3095 private static final class XSFacetImpl implements XSFacet { 3096 final short kind; 3097 final String value; 3098 final boolean fixed; 3099 final XSAnnotation annotation; 3100 3101 public XSFacetImpl(short kind, String value, boolean fixed, XSAnnotation annotation) { 3102 this.kind = kind; 3103 this.value = value; 3104 this.fixed = fixed; 3105 this.annotation = annotation; 3106 } 3107 3110 public XSAnnotation getAnnotation() { 3111 return annotation; 3112 } 3113 3114 3117 public short getFacetKind() { 3118 return kind; 3119 } 3120 3121 3124 public String getLexicalFacetValue() { 3125 return value; 3126 } 3127 3128 3131 public boolean getFixed() { 3132 return fixed; 3133 } 3134 3135 3138 public String getName() { 3139 return null; 3140 } 3141 3142 3145 public String getNamespace() { 3146 return null; 3147 } 3148 3149 3152 public XSNamespaceItem getNamespaceItem() { 3153 return null; 3155 } 3156 3157 3160 public short getType() { 3161 return XSConstants.FACET; 3162 } 3163 3164 } 3165 3166 private static final class XSMVFacetImpl implements XSMultiValueFacet { 3167 final short kind; 3168 XSObjectList annotations; 3169 StringList values; 3170 3171 public XSMVFacetImpl(short kind, StringList values, XSObjectList annotations) { 3172 this.kind = kind; 3173 this.values = values; 3174 this.annotations = annotations; 3175 } 3176 3177 3178 3181 public short getFacetKind() { 3182 return kind; 3183 } 3184 3185 3186 3189 public XSObjectList getAnnotations() { 3190 return annotations; 3191 } 3192 3193 3196 public StringList getLexicalFacetValues() { 3197 return values; 3198 } 3199 3200 3203 public String getName() { 3204 return null; 3205 } 3206 3207 3210 public String getNamespace() { 3211 return null; 3212 } 3213 3214 3217 public XSNamespaceItem getNamespaceItem() { 3218 return null; 3220 } 3221 3222 3225 public short getType() { 3226 return XSConstants.MULTIVALUE_FACET; 3227 } 3228 } 3229 3230 public String getTypeNamespace() { 3231 return getNamespace(); 3232 } 3233 3234 public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) { 3235 return isDOMDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod); 3236 } 3237 3238 private short convertToPrimitiveKind(short valueType) { 3239 3240 if (valueType <= XSConstants.NOTATION_DT) { 3241 return valueType; 3242 } 3243 3244 if (valueType <= XSConstants.ENTITY_DT) { 3245 return XSConstants.STRING_DT; 3246 } 3247 3248 if (valueType <= XSConstants.POSITIVEINTEGER_DT) { 3249 return XSConstants.DECIMAL_DT; 3250 } 3251 3252 return valueType; 3253 } 3254 3255} 3257 | Popular Tags |