1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 59 60 import java.util.Vector ; 61 62 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 63 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets; 64 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 65 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState; 66 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 67 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 68 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 69 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl; 70 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeUseImpl; 71 import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl; 72 import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl; 73 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 74 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl; 75 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 76 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 77 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; 78 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 79 import com.sun.org.apache.xerces.internal.util.DOMUtil; 80 import com.sun.org.apache.xerces.internal.util.NamespaceSupport; 81 import com.sun.org.apache.xerces.internal.util.SymbolTable; 82 import com.sun.org.apache.xerces.internal.xni.QName; 83 import org.w3c.dom.Element ; 84 import org.w3c.dom.Node ; 85 import org.w3c.dom.Text ; 86 87 98 abstract class XSDAbstractTraverser { 99 100 protected static final String NO_NAME = "(no name)"; 101 102 110 protected static final int NOT_ALL_CONTEXT = 0; 111 protected static final int PROCESSING_ALL_EL = 1; 112 protected static final int GROUP_REF_WITH_ALL = 2; 113 protected static final int CHILD_OF_GROUP = 4; 114 protected static final int PROCESSING_ALL_GP = 8; 115 116 protected XSDHandler fSchemaHandler = null; 118 protected SymbolTable fSymbolTable = null; 119 protected XSAttributeChecker fAttrChecker = null; 120 121 ValidationState fValidationState = new ValidationState(); 123 124 XSDAbstractTraverser (XSDHandler handler, 125 XSAttributeChecker attrChecker) { 126 fSchemaHandler = handler; 127 fAttrChecker = attrChecker; 128 } 129 130 void reset(SymbolTable symbolTable) { 131 fSymbolTable = symbolTable; 132 fValidationState.setExtraChecking(false); 133 fValidationState.setSymbolTable(symbolTable); 134 } 135 136 XSAnnotationImpl traverseAnnotationDecl(Element annotationDecl, Object [] parentAttrs, 141 boolean isGlobal, XSDocumentInfo schemaDoc) { 142 Object [] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc); 144 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 145 146 String contents = null; 147 for (Element child = DOMUtil.getFirstChildElement(annotationDecl); 148 child != null; 149 child = DOMUtil.getNextSiblingElement(child)) { 150 String name = DOMUtil.getLocalName(child); 151 152 if (!((name.equals(SchemaSymbols.ELT_APPINFO)) || 155 (name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) { 156 reportSchemaError("src-annotation", new Object []{name}, child); 157 } else { Node textContent = child.getFirstChild(); 159 if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) { 160 contents = ((Text )textContent).getData(); 161 } 162 } 163 164 attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc); 168 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 169 } 170 if (contents == null) return null; 173 174 SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace); 176 Vector annotationLocalAttrs = (Vector )parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA]; 178 if(annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) { 180 StringBuffer localStrBuffer = new StringBuffer (64); 181 localStrBuffer.append(" "); 182 int i=0; 184 while(i<annotationLocalAttrs.size()) { 185 String rawname = (String )annotationLocalAttrs.elementAt(i++); 186 int colonIndex = rawname.indexOf(':'); 187 String prefix, localpart; 188 if (colonIndex == -1) { 189 prefix = ""; 190 localpart = rawname; 191 } 192 else { 193 prefix = rawname.substring(0,colonIndex); 194 localpart = rawname.substring(colonIndex+1); 195 } 196 String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern()); 197 if (!annotationDecl.getAttributeNS(uri, localpart).equals("")) { 198 i++; continue; 200 } 201 localStrBuffer.append(rawname) 202 .append("=\""); 203 String value = (String )annotationLocalAttrs.elementAt(i++); 204 value = processAttValue(value); 206 localStrBuffer.append(value) 207 .append("\" "); 208 } 209 StringBuffer contentBuffer = new StringBuffer (contents.length() + localStrBuffer.length()); 211 int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION); 212 if(annotationTokenEnd == -1) return null; 214 annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length(); 215 contentBuffer.append(contents.substring(0,annotationTokenEnd)); 216 contentBuffer.append(localStrBuffer.toString()); 217 contentBuffer.append(contents.substring(annotationTokenEnd, contents.length())); 218 return new XSAnnotationImpl(contentBuffer.toString(), grammar); 219 } else { 220 return new XSAnnotationImpl(contents, grammar); 221 } 222 223 } 224 225 private static final XSSimpleType fQNameDV = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); 227 private StringBuffer fPattern = new StringBuffer (); 229 private final XSFacets xsFacets = new XSFacets(); 230 231 class FacetInfo { 232 XSFacets facetdata; 233 Element nodeAfterFacets; 234 short fPresentFacets; 235 short fFixedFacets; 236 } 237 238 FacetInfo traverseFacets(Element content, 239 XSSimpleType baseValidator, 240 XSDocumentInfo schemaDoc) { 241 242 short facetsPresent = 0 ; 243 short facetsFixed = 0; String facet; 245 boolean hasQName = containsQName(baseValidator); 246 Vector enumData = null; 247 XSObjectListImpl enumAnnotations = null; 248 XSObjectListImpl patternAnnotations = null; 249 Vector enumNSDecls = hasQName ? new Vector () : null; 250 int currentFacet = 0; 251 xsFacets.reset(); 252 while (content != null) { 253 Object [] attrs = null; 255 facet = DOMUtil.getLocalName(content); 256 if (facet.equals(SchemaSymbols.ELT_ENUMERATION)) { 257 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc, hasQName); 258 String enumVal = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 259 NamespaceSupport nsDecls = (NamespaceSupport)attrs[XSAttributeChecker.ATTIDX_ENUMNSDECLS]; 260 261 if (baseValidator.getVariety() == XSSimpleType.VARIETY_ATOMIC && 264 baseValidator.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) { 265 schemaDoc.fValidationContext.setNamespaceSupport(nsDecls); 267 try{ 268 QName temp = (QName)fQNameDV.validate(enumVal, schemaDoc.fValidationContext, null); 269 fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.NOTATION_TYPE, temp, content); 272 }catch(InvalidDatatypeValueException ex){ 273 reportSchemaError(ex.getKey(), ex.getArgs(), content); 274 } 275 schemaDoc.fValidationContext.setNamespaceSupport(schemaDoc.fNamespaceSupport); 277 } 278 if (enumData == null){ 279 enumData = new Vector (); 280 enumAnnotations = new XSObjectListImpl(); 281 } 282 enumData.addElement(enumVal); 283 enumAnnotations.add(null); 284 if (hasQName) 285 enumNSDecls.addElement(nsDecls); 286 Element child = DOMUtil.getFirstChildElement( content ); 287 288 if (child != null) { 289 291 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 292 enumAnnotations.add(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc)); 293 child = DOMUtil.getNextSiblingElement(child); 294 } 295 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 296 reportSchemaError("s4s-elt-must-match.1", new Object []{"enumeration", "(annotation?)", DOMUtil.getLocalName(child)}, child); 297 } 298 } 299 } 300 else if (facet.equals(SchemaSymbols.ELT_PATTERN)) { 301 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc); 302 if (fPattern.length() == 0) { 303 fPattern.append((String )attrs[XSAttributeChecker.ATTIDX_VALUE]); 304 } else { 305 fPattern.append("|"); 309 fPattern.append((String )attrs[XSAttributeChecker.ATTIDX_VALUE]); 310 } 311 Element child = DOMUtil.getFirstChildElement( content ); 312 if (child != null) { 313 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 315 if (patternAnnotations == null){ 316 patternAnnotations = new XSObjectListImpl(); 317 } 318 patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc)); 319 child = DOMUtil.getNextSiblingElement(child); 320 } 321 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 322 reportSchemaError("s4s-elt-must-match.1", new Object []{"pattern", "(annotation?)", DOMUtil.getLocalName(child)}, child); 323 } 324 } 325 326 } 327 else { 328 if (facet.equals(SchemaSymbols.ELT_MINLENGTH)) { 329 currentFacet = XSSimpleType.FACET_MINLENGTH; 330 } 331 else if (facet.equals(SchemaSymbols.ELT_MAXLENGTH)) { 332 currentFacet = XSSimpleType.FACET_MAXLENGTH; 333 } 334 else if (facet.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) { 335 currentFacet = XSSimpleType.FACET_MAXEXCLUSIVE; 336 } 337 else if (facet.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) { 338 currentFacet = XSSimpleType.FACET_MAXINCLUSIVE; 339 } 340 else if (facet.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) { 341 currentFacet = XSSimpleType.FACET_MINEXCLUSIVE; 342 } 343 else if (facet.equals(SchemaSymbols.ELT_MININCLUSIVE)) { 344 currentFacet = XSSimpleType.FACET_MININCLUSIVE; 345 } 346 else if (facet.equals(SchemaSymbols.ELT_TOTALDIGITS)) { 347 currentFacet = XSSimpleType.FACET_TOTALDIGITS; 348 } 349 else if (facet.equals(SchemaSymbols.ELT_FRACTIONDIGITS)) { 350 currentFacet = XSSimpleType.FACET_FRACTIONDIGITS; 351 } 352 else if (facet.equals(SchemaSymbols.ELT_WHITESPACE)) { 353 currentFacet = XSSimpleType.FACET_WHITESPACE; 354 } 355 else if (facet.equals(SchemaSymbols.ELT_LENGTH)) { 356 currentFacet = XSSimpleType.FACET_LENGTH; 357 } 358 else { 359 break; } 361 362 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc); 363 364 if ((facetsPresent & currentFacet) != 0) { 366 reportSchemaError("src-single-facet-value", new Object []{facet}, content); 367 } else if (attrs[XSAttributeChecker.ATTIDX_VALUE] != null) { 368 facetsPresent |= currentFacet; 369 if (((Boolean )attrs[XSAttributeChecker.ATTIDX_FIXED]).booleanValue()) { 371 facetsFixed |= currentFacet; 372 } 373 switch (currentFacet) { 374 case XSSimpleType.FACET_MINLENGTH: 375 xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 376 break; 377 case XSSimpleType.FACET_MAXLENGTH: 378 xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 379 break; 380 case XSSimpleType.FACET_MAXEXCLUSIVE: 381 xsFacets.maxExclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 382 break; 383 case XSSimpleType.FACET_MAXINCLUSIVE: 384 xsFacets.maxInclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 385 break; 386 case XSSimpleType.FACET_MINEXCLUSIVE: 387 xsFacets.minExclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 388 break; 389 case XSSimpleType.FACET_MININCLUSIVE: 390 xsFacets.minInclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 391 break; 392 case XSSimpleType.FACET_TOTALDIGITS: 393 xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 394 break; 395 case XSSimpleType.FACET_FRACTIONDIGITS: 396 xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 397 break; 398 case XSSimpleType.FACET_WHITESPACE: 399 xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue(); 400 break; 401 case XSSimpleType.FACET_LENGTH: 402 xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 403 break; 404 } 405 } 406 407 Element child = DOMUtil.getFirstChildElement( content ); 408 if (child != null) { 409 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 411 XSAnnotationImpl annotation = traverseAnnotationDecl(child, attrs, false, schemaDoc); 412 switch (currentFacet) { 413 case XSSimpleType.FACET_MINLENGTH: 414 xsFacets.minLengthAnnotation = annotation; 415 break; 416 case XSSimpleType.FACET_MAXLENGTH: 417 xsFacets.maxLengthAnnotation = annotation; 418 break; 419 case XSSimpleType.FACET_MAXEXCLUSIVE: 420 xsFacets.maxExclusiveAnnotation = annotation; 421 break; 422 case XSSimpleType.FACET_MAXINCLUSIVE: 423 xsFacets.maxInclusiveAnnotation = annotation; 424 break; 425 case XSSimpleType.FACET_MINEXCLUSIVE: 426 xsFacets.minExclusiveAnnotation = annotation; 427 break; 428 case XSSimpleType.FACET_MININCLUSIVE: 429 xsFacets.minInclusiveAnnotation = annotation; 430 break; 431 case XSSimpleType.FACET_TOTALDIGITS: 432 xsFacets.totalDigitsAnnotation = annotation; 433 break; 434 case XSSimpleType.FACET_FRACTIONDIGITS: 435 xsFacets.fractionDigitsAnnotation = annotation; 436 break; 437 case XSSimpleType.FACET_WHITESPACE: 438 xsFacets.whiteSpaceAnnotation = annotation; 439 break; 440 case XSSimpleType.FACET_LENGTH: 441 xsFacets.lengthAnnotation = annotation; 442 break; 443 } 444 445 446 child = DOMUtil.getNextSiblingElement(child); 447 } 448 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 449 reportSchemaError("s4s-elt-must-match.1", new Object []{facet, "(annotation?)", DOMUtil.getLocalName(child)}, child); 450 } 451 } 452 } 453 fAttrChecker.returnAttrArray (attrs, schemaDoc); 454 content = DOMUtil.getNextSiblingElement(content); 455 } 456 if (enumData !=null) { 457 facetsPresent |= XSSimpleType.FACET_ENUMERATION; 458 xsFacets.enumeration = enumData; 459 xsFacets.enumNSDecls = enumNSDecls; 460 xsFacets.enumAnnotations = enumAnnotations; 461 } 462 if (fPattern.length() != 0) { 463 facetsPresent |= XSSimpleType.FACET_PATTERN; 464 xsFacets.pattern = fPattern.toString(); 465 xsFacets.patternAnnotations = patternAnnotations; 466 } 467 468 fPattern.setLength(0); 469 470 FacetInfo fi = new FacetInfo(); 471 fi.facetdata = xsFacets; 472 fi.nodeAfterFacets = content; 473 fi.fPresentFacets = facetsPresent; 474 fi.fFixedFacets = facetsFixed; 475 return fi; 476 } 477 478 479 private boolean containsQName(XSSimpleType type) { 481 if (type.getVariety() == XSSimpleType.VARIETY_ATOMIC) { 482 short primitive = type.getPrimitiveKind(); 483 return (primitive == XSSimpleType.PRIMITIVE_QNAME || 484 primitive == XSSimpleType.PRIMITIVE_NOTATION); 485 } 486 else if (type.getVariety() == XSSimpleType.VARIETY_LIST) { 487 return containsQName((XSSimpleType)type.getItemType()); 488 } 489 else if (type.getVariety() == XSSimpleType.VARIETY_UNION) { 490 XSObjectList members = type.getMemberTypes(); 491 for (int i = 0; i < members.getLength(); i++) { 492 if (containsQName((XSSimpleType)members.item(i))) 493 return true; 494 } 495 } 496 return false; 497 } 498 499 Element traverseAttrsAndAttrGrps(Element firstAttr, XSAttributeGroupDecl attrGrp, 505 XSDocumentInfo schemaDoc, SchemaGrammar grammar, 506 XSComplexTypeDecl enclosingCT) { 507 508 Element child=null; 509 XSAttributeGroupDecl tempAttrGrp = null; 510 XSAttributeUseImpl tempAttrUse = null; 511 String childName; 512 513 for (child=firstAttr; child!=null; child=DOMUtil.getNextSiblingElement(child)) { 514 childName = DOMUtil.getLocalName(child); 515 if (childName.equals(SchemaSymbols.ELT_ATTRIBUTE)) { 516 tempAttrUse = fSchemaHandler.fAttributeTraverser.traverseLocal(child, 517 schemaDoc, 518 grammar, 519 enclosingCT); 520 if (tempAttrUse == null) break; 521 if (attrGrp.getAttributeUse(tempAttrUse.fAttrDecl.getNamespace(), 522 tempAttrUse.fAttrDecl.getName())==null) { 523 String idName = attrGrp.addAttributeUse(tempAttrUse); 524 if (idName != null) { 525 String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5"; 526 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 527 reportSchemaError(code, new Object []{name, tempAttrUse.fAttrDecl.getName(), idName}, child); 528 } 529 } 530 else { 531 String code = (enclosingCT == null) ? "ag-props-correct.2" : "ct-props-correct.4"; 533 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 534 reportSchemaError(code, new Object []{name, tempAttrUse.fAttrDecl.getName()}, child); 535 } 536 } 537 else if (childName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 538 tempAttrGrp = fSchemaHandler.fAttributeGroupTraverser.traverseLocal( 540 child, schemaDoc, grammar); 541 if(tempAttrGrp == null ) break; 542 XSObjectList attrUseS = tempAttrGrp.getAttributeUses(); 543 XSAttributeUseImpl existingAttrUse = null, oneAttrUse; 544 int attrCount = attrUseS.getLength(); 545 for (int i=0; i<attrCount; i++) { 546 oneAttrUse = (XSAttributeUseImpl)attrUseS.item(i); 547 if (existingAttrUse == attrGrp.getAttributeUse(oneAttrUse.fAttrDecl.getNamespace(), 548 oneAttrUse.fAttrDecl.getName())) { 549 String idName = attrGrp.addAttributeUse(oneAttrUse); 550 if (idName != null) { 551 String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5"; 552 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 553 reportSchemaError(code, new Object []{name, oneAttrUse.fAttrDecl.getName(), idName}, child); 554 } 555 } 556 else { 557 String code = (enclosingCT == null) ? "ag-props-correct.2" : "ct-props-correct.4"; 559 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 560 reportSchemaError(code, new Object []{name, oneAttrUse.fAttrDecl.getName()}, child); 561 } 562 } 563 564 if (tempAttrGrp.fAttributeWC != null) { 565 if (attrGrp.fAttributeWC == null) { 566 attrGrp.fAttributeWC = tempAttrGrp.fAttributeWC; 567 } 568 else { 570 attrGrp.fAttributeWC = attrGrp.fAttributeWC. 571 performIntersectionWith(tempAttrGrp.fAttributeWC, attrGrp.fAttributeWC.fProcessContents); 572 if (attrGrp.fAttributeWC == null) { 573 String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4"; 574 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 575 reportSchemaError(code, new Object []{name}, child); 576 } 577 } 578 } 579 } 580 else 581 break; 582 } 584 if (child != null) { 585 childName = DOMUtil.getLocalName(child); 586 if (childName.equals(SchemaSymbols.ELT_ANYATTRIBUTE)) { 587 XSWildcardDecl tempAttrWC = fSchemaHandler.fWildCardTraverser. 588 traverseAnyAttribute(child, schemaDoc, grammar); 589 if (attrGrp.fAttributeWC == null) { 590 attrGrp.fAttributeWC = tempAttrWC; 591 } 592 else { 594 attrGrp.fAttributeWC = tempAttrWC. 595 performIntersectionWith(attrGrp.fAttributeWC, tempAttrWC.fProcessContents); 596 if (attrGrp.fAttributeWC == null) { 597 String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4"; 598 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 599 reportSchemaError(code, new Object []{name}, child); 600 } 601 } 602 child = DOMUtil.getNextSiblingElement(child); 603 } 604 } 605 606 return child; 608 609 } 610 611 void reportSchemaError (String key, Object [] args, Element ele) { 612 fSchemaHandler.reportSchemaError(key, args, ele); 613 } 614 615 619 void checkNotationType(String refName, XSTypeDefinition typeDecl, Element elem) { 620 if (typeDecl.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE && 621 ((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC && 622 ((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) { 623 if ((((XSSimpleType)typeDecl).getDefinedFacets() & XSSimpleType.FACET_ENUMERATION) == 0) { 624 reportSchemaError("enumeration-required-notation", new Object []{typeDecl.getName(), refName, DOMUtil.getLocalName(elem)}, elem); 625 } 626 } 627 } 628 629 protected XSParticleDecl checkOccurrences(XSParticleDecl particle, 631 String particleName, Element parent, 632 int allContextFlags, 633 long defaultVals) { 634 635 int min = particle.fMinOccurs; 636 int max = particle.fMaxOccurs; 637 boolean defaultMin = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MINOCCURS)) != 0; 638 boolean defaultMax = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MAXOCCURS)) != 0; 639 640 boolean processingAllEl = ((allContextFlags & PROCESSING_ALL_EL) != 0); 641 boolean processingAllGP = ((allContextFlags & PROCESSING_ALL_GP) != 0); 642 boolean groupRefWithAll = ((allContextFlags & GROUP_REF_WITH_ALL) != 0); 643 boolean isGroupChild = ((allContextFlags & CHILD_OF_GROUP) != 0); 644 645 if (isGroupChild) { 648 if (!defaultMin) { 649 Object [] args = new Object []{particleName, "minOccurs"}; 650 reportSchemaError("s4s-att-not-allowed", args, parent); 651 min = 1; 652 } 653 if (!defaultMax) { 654 Object [] args = new Object []{particleName, "maxOccurs"}; 655 reportSchemaError("s4s-att-not-allowed", args, parent); 656 max = 1; 657 } 658 } 659 660 if (min == 0 && max== 0) { 662 particle.fType = XSParticleDecl.PARTICLE_EMPTY; 663 return null; 664 } 665 666 if (processingAllEl) { 672 if (max != 1) { 673 reportSchemaError("cos-all-limited.2", new Object []{new Integer (max), 674 ((XSElementDecl)particle.fValue).getName()}, parent); 675 max = 1; 676 if (min > 1) 677 min = 1; 678 } 679 } 680 else if (processingAllGP || groupRefWithAll) { 681 if (max != 1) { 682 reportSchemaError("cos-all-limited.1.2", null, parent); 683 if (min > 1) 684 min = 1; 685 max = 1; 686 } 687 } 688 689 particle.fMaxOccurs = min; 690 particle.fMaxOccurs = max; 691 692 return particle; 693 } 694 695 private static String processAttValue(String original) { 697 StringBuffer newVal = new StringBuffer (original.length()); 699 for(int i=0; i<original.length(); i++) { 700 char currChar = original.charAt(i); 701 if(currChar == '"') { 702 newVal.append("""); 703 } else if (currChar == '>') { 704 newVal.append(">"); 705 } else if (currChar == '&') { 706 newVal.append("&"); 707 } else { 708 newVal.append(currChar); 709 } 710 } 711 return newVal.toString(); 712 } 713 } 714 | Popular Tags |