1 16 17 package org.apache.xerces.impl.xs.traversers; 18 19 import java.util.Vector ; 20 21 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 22 import org.apache.xerces.impl.dv.XSFacets; 23 import org.apache.xerces.impl.dv.XSSimpleType; 24 import org.apache.xerces.impl.validation.ValidationState; 25 import org.apache.xerces.impl.xs.SchemaGrammar; 26 import org.apache.xerces.impl.xs.SchemaSymbols; 27 import org.apache.xerces.impl.xs.XSAnnotationImpl; 28 import org.apache.xerces.impl.xs.XSAttributeGroupDecl; 29 import org.apache.xerces.impl.xs.XSAttributeUseImpl; 30 import org.apache.xerces.impl.xs.XSComplexTypeDecl; 31 import org.apache.xerces.impl.xs.XSElementDecl; 32 import org.apache.xerces.impl.xs.XSParticleDecl; 33 import org.apache.xerces.impl.xs.XSWildcardDecl; 34 import org.apache.xerces.xs.XSObjectList; 35 import org.apache.xerces.xs.XSTypeDefinition; 36 import org.apache.xerces.impl.xs.util.XInt; 37 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 38 import org.apache.xerces.util.DOMUtil; 39 import org.apache.xerces.util.NamespaceSupport; 40 import org.apache.xerces.util.SymbolTable; 41 import org.apache.xerces.xni.QName; 42 import org.w3c.dom.Element ; 43 import org.w3c.dom.Node ; 44 import org.w3c.dom.Text ; 45 46 59 abstract class XSDAbstractTraverser { 60 61 protected static final String NO_NAME = "(no name)"; 62 63 71 protected static final int NOT_ALL_CONTEXT = 0; 72 protected static final int PROCESSING_ALL_EL = 1; 73 protected static final int GROUP_REF_WITH_ALL = 2; 74 protected static final int CHILD_OF_GROUP = 4; 75 protected static final int PROCESSING_ALL_GP = 8; 76 77 protected XSDHandler fSchemaHandler = null; 79 protected SymbolTable fSymbolTable = null; 80 protected XSAttributeChecker fAttrChecker = null; 81 protected boolean fValidateAnnotations = false; 82 83 ValidationState fValidationState = new ValidationState(); 85 86 XSDAbstractTraverser (XSDHandler handler, 87 XSAttributeChecker attrChecker) { 88 fSchemaHandler = handler; 89 fAttrChecker = attrChecker; 90 } 91 92 void reset(SymbolTable symbolTable, boolean validateAnnotations) { 93 fSymbolTable = symbolTable; 94 fValidateAnnotations = validateAnnotations; 95 fValidationState.setExtraChecking(false); 96 fValidationState.setSymbolTable(symbolTable); 97 } 98 99 XSAnnotationImpl traverseAnnotationDecl(Element annotationDecl, Object [] parentAttrs, 104 boolean isGlobal, XSDocumentInfo schemaDoc) { 105 Object [] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc); 107 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 108 109 String contents = null; 110 Element child = DOMUtil.getFirstChildElement(annotationDecl); 111 if (child != null) { 112 do { 113 String name = DOMUtil.getLocalName(child); 114 115 if (!((name.equals(SchemaSymbols.ELT_APPINFO)) || 118 (name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) { 119 reportSchemaError("src-annotation", new Object []{name}, child); 120 } else { Node textContent = child.getFirstChild(); 122 if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) { 123 contents = ((Text )textContent).getData(); 124 } 125 } 126 127 attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc); 131 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 132 133 child = DOMUtil.getNextSiblingElement(child); 134 } 135 while (child != null); 136 } 137 else { 144 Node textContent = annotationDecl.getFirstChild(); 145 if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) { 146 contents = ((Text )textContent).getData(); 147 } 148 } 149 if (contents == null) return null; 152 153 SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace); 155 Vector annotationLocalAttrs = (Vector )parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA]; 157 if(annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) { 159 StringBuffer localStrBuffer = new StringBuffer (64); 160 localStrBuffer.append(" "); 161 int i = 0; 163 while (i < annotationLocalAttrs.size()) { 164 String rawname = (String )annotationLocalAttrs.elementAt(i++); 165 int colonIndex = rawname.indexOf(':'); 166 String prefix, localpart; 167 if (colonIndex == -1) { 168 prefix = ""; 169 localpart = rawname; 170 } 171 else { 172 prefix = rawname.substring(0,colonIndex); 173 localpart = rawname.substring(colonIndex+1); 174 } 175 String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern()); 176 if (!annotationDecl.getAttributeNS(uri, localpart).equals("")) { 177 i++; continue; 179 } 180 localStrBuffer.append(rawname) 181 .append("=\""); 182 String value = (String )annotationLocalAttrs.elementAt(i++); 183 value = processAttValue(value); 185 localStrBuffer.append(value) 186 .append("\" "); 187 } 188 StringBuffer contentBuffer = new StringBuffer (contents.length() + localStrBuffer.length()); 190 int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION); 191 if(annotationTokenEnd == -1) return null; 193 annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length(); 194 contentBuffer.append(contents.substring(0,annotationTokenEnd)); 195 contentBuffer.append(localStrBuffer.toString()); 196 contentBuffer.append(contents.substring(annotationTokenEnd, contents.length())); 197 final String annotation = contentBuffer.toString(); 198 if (fValidateAnnotations) { 199 schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationDecl)); 200 } 201 return new XSAnnotationImpl(annotation, grammar); 202 } else { 203 if (fValidateAnnotations) { 204 schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationDecl)); 205 } 206 return new XSAnnotationImpl(contents, grammar); 207 } 208 209 } 210 211 XSAnnotationImpl traverseSyntheticAnnotation(Element annotationParent, String initialContent, 212 Object [] parentAttrs, boolean isGlobal, XSDocumentInfo schemaDoc) { 213 214 String contents = initialContent; 215 216 SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace); 218 Vector annotationLocalAttrs = (Vector )parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA]; 220 if (annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) { 222 StringBuffer localStrBuffer = new StringBuffer (64); 223 localStrBuffer.append(" "); 224 int i = 0; 226 while (i < annotationLocalAttrs.size()) { 227 String rawname = (String )annotationLocalAttrs.elementAt(i++); 228 int colonIndex = rawname.indexOf(':'); 229 String prefix, localpart; 230 if (colonIndex == -1) { 231 prefix = ""; 232 localpart = rawname; 233 } 234 else { 235 prefix = rawname.substring(0,colonIndex); 236 localpart = rawname.substring(colonIndex+1); 237 } 238 String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern()); 239 localStrBuffer.append(rawname) 240 .append("=\""); 241 String value = (String )annotationLocalAttrs.elementAt(i++); 242 value = processAttValue(value); 244 localStrBuffer.append(value) 245 .append("\" "); 246 } 247 StringBuffer contentBuffer = new StringBuffer (contents.length() + localStrBuffer.length()); 249 int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION); 250 if(annotationTokenEnd == -1) return null; 252 annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length(); 253 contentBuffer.append(contents.substring(0,annotationTokenEnd)); 254 contentBuffer.append(localStrBuffer.toString()); 255 contentBuffer.append(contents.substring(annotationTokenEnd, contents.length())); 256 final String annotation = contentBuffer.toString(); 257 if (fValidateAnnotations) { 258 schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationParent)); 259 } 260 return new XSAnnotationImpl(annotation, grammar); 261 } else { 262 if (fValidateAnnotations) { 263 schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationParent)); 264 } 265 return new XSAnnotationImpl(contents, grammar); 266 } 267 } 268 269 private static final XSSimpleType fQNameDV = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); 271 private StringBuffer fPattern = new StringBuffer (); 273 private final XSFacets xsFacets = new XSFacets(); 274 275 class FacetInfo { 276 XSFacets facetdata; 277 Element nodeAfterFacets; 278 short fPresentFacets; 279 short fFixedFacets; 280 } 281 282 FacetInfo traverseFacets(Element content, 283 XSSimpleType baseValidator, 284 XSDocumentInfo schemaDoc) { 285 286 short facetsPresent = 0 ; 287 short facetsFixed = 0; String facet; 289 boolean hasQName = containsQName(baseValidator); 290 Vector enumData = null; 291 XSObjectListImpl enumAnnotations = null; 292 XSObjectListImpl patternAnnotations = null; 293 Vector enumNSDecls = hasQName ? new Vector () : null; 294 int currentFacet = 0; 295 xsFacets.reset(); 296 while (content != null) { 297 Object [] attrs = null; 299 facet = DOMUtil.getLocalName(content); 300 if (facet.equals(SchemaSymbols.ELT_ENUMERATION)) { 301 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc, hasQName); 302 String enumVal = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 303 NamespaceSupport nsDecls = (NamespaceSupport)attrs[XSAttributeChecker.ATTIDX_ENUMNSDECLS]; 304 305 if (baseValidator.getVariety() == XSSimpleType.VARIETY_ATOMIC && 308 baseValidator.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) { 309 schemaDoc.fValidationContext.setNamespaceSupport(nsDecls); 311 try{ 312 QName temp = (QName)fQNameDV.validate(enumVal, schemaDoc.fValidationContext, null); 313 fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.NOTATION_TYPE, temp, content); 316 }catch(InvalidDatatypeValueException ex){ 317 reportSchemaError(ex.getKey(), ex.getArgs(), content); 318 } 319 schemaDoc.fValidationContext.setNamespaceSupport(schemaDoc.fNamespaceSupport); 321 } 322 if (enumData == null){ 323 enumData = new Vector (); 324 enumAnnotations = new XSObjectListImpl(); 325 } 326 enumData.addElement(enumVal); 327 enumAnnotations.add(null); 328 if (hasQName) 329 enumNSDecls.addElement(nsDecls); 330 Element child = DOMUtil.getFirstChildElement( content ); 331 332 if (child != null) { 333 335 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 336 enumAnnotations.add(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc)); 337 child = DOMUtil.getNextSiblingElement(child); 338 } 339 else { 340 String text = DOMUtil.getSyntheticAnnotation(content); 341 if (text != null) { 342 enumAnnotations.add(enumAnnotations.getLength()-1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc)); 343 } 344 } 345 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 346 reportSchemaError("s4s-elt-must-match.1", new Object []{"enumeration", "(annotation?)", DOMUtil.getLocalName(child)}, child); 347 } 348 } 349 else { 350 String text = DOMUtil.getSyntheticAnnotation(content); 351 if (text != null) { 352 enumAnnotations.add(enumAnnotations.getLength() - 1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc)); 353 } 354 } 355 } 356 else if (facet.equals(SchemaSymbols.ELT_PATTERN)) { 357 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc); 358 if (fPattern.length() == 0) { 359 fPattern.append((String )attrs[XSAttributeChecker.ATTIDX_VALUE]); 360 } else { 361 fPattern.append("|"); 365 fPattern.append((String )attrs[XSAttributeChecker.ATTIDX_VALUE]); 366 } 367 Element child = DOMUtil.getFirstChildElement( content ); 368 if (child != null) { 369 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 371 if (patternAnnotations == null){ 372 patternAnnotations = new XSObjectListImpl(); 373 } 374 patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc)); 375 child = DOMUtil.getNextSiblingElement(child); 376 } 377 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 378 reportSchemaError("s4s-elt-must-match.1", new Object []{"pattern", "(annotation?)", DOMUtil.getLocalName(child)}, child); 379 } 380 } 381 382 } 383 else { 384 if (facet.equals(SchemaSymbols.ELT_MINLENGTH)) { 385 currentFacet = XSSimpleType.FACET_MINLENGTH; 386 } 387 else if (facet.equals(SchemaSymbols.ELT_MAXLENGTH)) { 388 currentFacet = XSSimpleType.FACET_MAXLENGTH; 389 } 390 else if (facet.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) { 391 currentFacet = XSSimpleType.FACET_MAXEXCLUSIVE; 392 } 393 else if (facet.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) { 394 currentFacet = XSSimpleType.FACET_MAXINCLUSIVE; 395 } 396 else if (facet.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) { 397 currentFacet = XSSimpleType.FACET_MINEXCLUSIVE; 398 } 399 else if (facet.equals(SchemaSymbols.ELT_MININCLUSIVE)) { 400 currentFacet = XSSimpleType.FACET_MININCLUSIVE; 401 } 402 else if (facet.equals(SchemaSymbols.ELT_TOTALDIGITS)) { 403 currentFacet = XSSimpleType.FACET_TOTALDIGITS; 404 } 405 else if (facet.equals(SchemaSymbols.ELT_FRACTIONDIGITS)) { 406 currentFacet = XSSimpleType.FACET_FRACTIONDIGITS; 407 } 408 else if (facet.equals(SchemaSymbols.ELT_WHITESPACE)) { 409 currentFacet = XSSimpleType.FACET_WHITESPACE; 410 } 411 else if (facet.equals(SchemaSymbols.ELT_LENGTH)) { 412 currentFacet = XSSimpleType.FACET_LENGTH; 413 } 414 else { 415 break; } 417 418 attrs = fAttrChecker.checkAttributes(content, false, schemaDoc); 419 420 if ((facetsPresent & currentFacet) != 0) { 422 reportSchemaError("src-single-facet-value", new Object []{facet}, content); 423 } else if (attrs[XSAttributeChecker.ATTIDX_VALUE] != null) { 424 facetsPresent |= currentFacet; 425 if (((Boolean )attrs[XSAttributeChecker.ATTIDX_FIXED]).booleanValue()) { 427 facetsFixed |= currentFacet; 428 } 429 switch (currentFacet) { 430 case XSSimpleType.FACET_MINLENGTH: 431 xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 432 break; 433 case XSSimpleType.FACET_MAXLENGTH: 434 xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 435 break; 436 case XSSimpleType.FACET_MAXEXCLUSIVE: 437 xsFacets.maxExclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 438 break; 439 case XSSimpleType.FACET_MAXINCLUSIVE: 440 xsFacets.maxInclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 441 break; 442 case XSSimpleType.FACET_MINEXCLUSIVE: 443 xsFacets.minExclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 444 break; 445 case XSSimpleType.FACET_MININCLUSIVE: 446 xsFacets.minInclusive = (String )attrs[XSAttributeChecker.ATTIDX_VALUE]; 447 break; 448 case XSSimpleType.FACET_TOTALDIGITS: 449 xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 450 break; 451 case XSSimpleType.FACET_FRACTIONDIGITS: 452 xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 453 break; 454 case XSSimpleType.FACET_WHITESPACE: 455 xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue(); 456 break; 457 case XSSimpleType.FACET_LENGTH: 458 xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); 459 break; 460 } 461 } 462 463 Element child = DOMUtil.getFirstChildElement( content ); 464 if (child != null) { 465 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 467 XSAnnotationImpl annotation = traverseAnnotationDecl(child, attrs, false, schemaDoc); 468 switch (currentFacet) { 469 case XSSimpleType.FACET_MINLENGTH: 470 xsFacets.minLengthAnnotation = annotation; 471 break; 472 case XSSimpleType.FACET_MAXLENGTH: 473 xsFacets.maxLengthAnnotation = annotation; 474 break; 475 case XSSimpleType.FACET_MAXEXCLUSIVE: 476 xsFacets.maxExclusiveAnnotation = annotation; 477 break; 478 case XSSimpleType.FACET_MAXINCLUSIVE: 479 xsFacets.maxInclusiveAnnotation = annotation; 480 break; 481 case XSSimpleType.FACET_MINEXCLUSIVE: 482 xsFacets.minExclusiveAnnotation = annotation; 483 break; 484 case XSSimpleType.FACET_MININCLUSIVE: 485 xsFacets.minInclusiveAnnotation = annotation; 486 break; 487 case XSSimpleType.FACET_TOTALDIGITS: 488 xsFacets.totalDigitsAnnotation = annotation; 489 break; 490 case XSSimpleType.FACET_FRACTIONDIGITS: 491 xsFacets.fractionDigitsAnnotation = annotation; 492 break; 493 case XSSimpleType.FACET_WHITESPACE: 494 xsFacets.whiteSpaceAnnotation = annotation; 495 break; 496 case XSSimpleType.FACET_LENGTH: 497 xsFacets.lengthAnnotation = annotation; 498 break; 499 } 500 501 502 child = DOMUtil.getNextSiblingElement(child); 503 } 504 else { 505 String text = DOMUtil.getSyntheticAnnotation(content); 506 if (text != null) { 507 XSAnnotationImpl annotation = traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc); 508 switch (currentFacet) { 509 case XSSimpleType.FACET_MINLENGTH: 510 xsFacets.minLengthAnnotation = annotation; 511 break; 512 case XSSimpleType.FACET_MAXLENGTH: 513 xsFacets.maxLengthAnnotation = annotation; 514 break; 515 case XSSimpleType.FACET_MAXEXCLUSIVE: 516 xsFacets.maxExclusiveAnnotation = annotation; 517 break; 518 case XSSimpleType.FACET_MAXINCLUSIVE: 519 xsFacets.maxInclusiveAnnotation = annotation; 520 break; 521 case XSSimpleType.FACET_MINEXCLUSIVE: 522 xsFacets.minExclusiveAnnotation = annotation; 523 break; 524 case XSSimpleType.FACET_MININCLUSIVE: 525 xsFacets.minInclusiveAnnotation = annotation; 526 break; 527 case XSSimpleType.FACET_TOTALDIGITS: 528 xsFacets.totalDigitsAnnotation = annotation; 529 break; 530 case XSSimpleType.FACET_FRACTIONDIGITS: 531 xsFacets.fractionDigitsAnnotation = annotation; 532 break; 533 case XSSimpleType.FACET_WHITESPACE: 534 xsFacets.whiteSpaceAnnotation = annotation; 535 break; 536 case XSSimpleType.FACET_LENGTH: 537 xsFacets.lengthAnnotation = annotation; 538 break; 539 } 540 } 541 } 542 if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 543 reportSchemaError("s4s-elt-must-match.1", new Object []{facet, "(annotation?)", DOMUtil.getLocalName(child)}, child); 544 } 545 } 546 } 547 fAttrChecker.returnAttrArray (attrs, schemaDoc); 548 content = DOMUtil.getNextSiblingElement(content); 549 } 550 if (enumData !=null) { 551 facetsPresent |= XSSimpleType.FACET_ENUMERATION; 552 xsFacets.enumeration = enumData; 553 xsFacets.enumNSDecls = enumNSDecls; 554 xsFacets.enumAnnotations = enumAnnotations; 555 } 556 if (fPattern.length() != 0) { 557 facetsPresent |= XSSimpleType.FACET_PATTERN; 558 xsFacets.pattern = fPattern.toString(); 559 xsFacets.patternAnnotations = patternAnnotations; 560 } 561 562 fPattern.setLength(0); 563 564 FacetInfo fi = new FacetInfo(); 565 fi.facetdata = xsFacets; 566 fi.nodeAfterFacets = content; 567 fi.fPresentFacets = facetsPresent; 568 fi.fFixedFacets = facetsFixed; 569 return fi; 570 } 571 572 573 private boolean containsQName(XSSimpleType type) { 575 if (type.getVariety() == XSSimpleType.VARIETY_ATOMIC) { 576 short primitive = type.getPrimitiveKind(); 577 return (primitive == XSSimpleType.PRIMITIVE_QNAME || 578 primitive == XSSimpleType.PRIMITIVE_NOTATION); 579 } 580 else if (type.getVariety() == XSSimpleType.VARIETY_LIST) { 581 return containsQName((XSSimpleType)type.getItemType()); 582 } 583 else if (type.getVariety() == XSSimpleType.VARIETY_UNION) { 584 XSObjectList members = type.getMemberTypes(); 585 for (int i = 0; i < members.getLength(); i++) { 586 if (containsQName((XSSimpleType)members.item(i))) 587 return true; 588 } 589 } 590 return false; 591 } 592 593 Element traverseAttrsAndAttrGrps(Element firstAttr, XSAttributeGroupDecl attrGrp, 599 XSDocumentInfo schemaDoc, SchemaGrammar grammar, 600 XSComplexTypeDecl enclosingCT) { 601 602 Element child=null; 603 XSAttributeGroupDecl tempAttrGrp = null; 604 XSAttributeUseImpl tempAttrUse = null; 605 String childName; 606 607 for (child=firstAttr; child!=null; child=DOMUtil.getNextSiblingElement(child)) { 608 childName = DOMUtil.getLocalName(child); 609 if (childName.equals(SchemaSymbols.ELT_ATTRIBUTE)) { 610 tempAttrUse = fSchemaHandler.fAttributeTraverser.traverseLocal(child, 611 schemaDoc, 612 grammar, 613 enclosingCT); 614 if (tempAttrUse == null) break; 615 if (attrGrp.getAttributeUse(tempAttrUse.fAttrDecl.getNamespace(), 616 tempAttrUse.fAttrDecl.getName())==null) { 617 String idName = attrGrp.addAttributeUse(tempAttrUse); 618 if (idName != null) { 619 String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5"; 620 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 621 reportSchemaError(code, new Object []{name, tempAttrUse.fAttrDecl.getName(), idName}, child); 622 } 623 } 624 else { 625 String code = (enclosingCT == null) ? "ag-props-correct.2" : "ct-props-correct.4"; 627 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 628 reportSchemaError(code, new Object []{name, tempAttrUse.fAttrDecl.getName()}, child); 629 } 630 } 631 else if (childName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 632 tempAttrGrp = fSchemaHandler.fAttributeGroupTraverser.traverseLocal( 634 child, schemaDoc, grammar); 635 if(tempAttrGrp == null ) break; 636 XSObjectList attrUseS = tempAttrGrp.getAttributeUses(); 637 XSAttributeUseImpl existingAttrUse = null, oneAttrUse; 638 int attrCount = attrUseS.getLength(); 639 for (int i=0; i<attrCount; i++) { 640 oneAttrUse = (XSAttributeUseImpl)attrUseS.item(i); 641 if (existingAttrUse == attrGrp.getAttributeUse(oneAttrUse.fAttrDecl.getNamespace(), 642 oneAttrUse.fAttrDecl.getName())) { 643 String idName = attrGrp.addAttributeUse(oneAttrUse); 644 if (idName != null) { 645 String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5"; 646 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 647 reportSchemaError(code, new Object []{name, oneAttrUse.fAttrDecl.getName(), idName}, child); 648 } 649 } 650 else { 651 String code = (enclosingCT == null) ? "ag-props-correct.2" : "ct-props-correct.4"; 653 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 654 reportSchemaError(code, new Object []{name, oneAttrUse.fAttrDecl.getName()}, child); 655 } 656 } 657 658 if (tempAttrGrp.fAttributeWC != null) { 659 if (attrGrp.fAttributeWC == null) { 660 attrGrp.fAttributeWC = tempAttrGrp.fAttributeWC; 661 } 662 else { 664 attrGrp.fAttributeWC = attrGrp.fAttributeWC. 665 performIntersectionWith(tempAttrGrp.fAttributeWC, attrGrp.fAttributeWC.fProcessContents); 666 if (attrGrp.fAttributeWC == null) { 667 String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4"; 668 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 669 reportSchemaError(code, new Object []{name}, child); 670 } 671 } 672 } 673 } 674 else 675 break; 676 } 678 if (child != null) { 679 childName = DOMUtil.getLocalName(child); 680 if (childName.equals(SchemaSymbols.ELT_ANYATTRIBUTE)) { 681 XSWildcardDecl tempAttrWC = fSchemaHandler.fWildCardTraverser. 682 traverseAnyAttribute(child, schemaDoc, grammar); 683 if (attrGrp.fAttributeWC == null) { 684 attrGrp.fAttributeWC = tempAttrWC; 685 } 686 else { 688 attrGrp.fAttributeWC = tempAttrWC. 689 performIntersectionWith(attrGrp.fAttributeWC, tempAttrWC.fProcessContents); 690 if (attrGrp.fAttributeWC == null) { 691 String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4"; 692 String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName(); 693 reportSchemaError(code, new Object []{name}, child); 694 } 695 } 696 child = DOMUtil.getNextSiblingElement(child); 697 } 698 } 699 700 return child; 702 703 } 704 705 void reportSchemaError (String key, Object [] args, Element ele) { 706 fSchemaHandler.reportSchemaError(key, args, ele); 707 } 708 709 713 void checkNotationType(String refName, XSTypeDefinition typeDecl, Element elem) { 714 if (typeDecl.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE && 715 ((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC && 716 ((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) { 717 if ((((XSSimpleType)typeDecl).getDefinedFacets() & XSSimpleType.FACET_ENUMERATION) == 0) { 718 reportSchemaError("enumeration-required-notation", new Object []{typeDecl.getName(), refName, DOMUtil.getLocalName(elem)}, elem); 719 } 720 } 721 } 722 723 protected XSParticleDecl checkOccurrences(XSParticleDecl particle, 725 String particleName, Element parent, 726 int allContextFlags, 727 long defaultVals) { 728 729 int min = particle.fMinOccurs; 730 int max = particle.fMaxOccurs; 731 boolean defaultMin = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MINOCCURS)) != 0; 732 boolean defaultMax = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MAXOCCURS)) != 0; 733 734 boolean processingAllEl = ((allContextFlags & PROCESSING_ALL_EL) != 0); 735 boolean processingAllGP = ((allContextFlags & PROCESSING_ALL_GP) != 0); 736 boolean groupRefWithAll = ((allContextFlags & GROUP_REF_WITH_ALL) != 0); 737 boolean isGroupChild = ((allContextFlags & CHILD_OF_GROUP) != 0); 738 739 if (isGroupChild) { 742 if (!defaultMin) { 743 Object [] args = new Object []{particleName, "minOccurs"}; 744 reportSchemaError("s4s-att-not-allowed", args, parent); 745 min = 1; 746 } 747 if (!defaultMax) { 748 Object [] args = new Object []{particleName, "maxOccurs"}; 749 reportSchemaError("s4s-att-not-allowed", args, parent); 750 max = 1; 751 } 752 } 753 754 if (min == 0 && max== 0) { 756 particle.fType = XSParticleDecl.PARTICLE_EMPTY; 757 return null; 758 } 759 760 if (processingAllEl) { 766 if (max != 1) { 767 reportSchemaError("cos-all-limited.2", new Object []{new Integer (max), 768 ((XSElementDecl)particle.fValue).getName()}, parent); 769 max = 1; 770 if (min > 1) 771 min = 1; 772 } 773 } 774 else if (processingAllGP || groupRefWithAll) { 775 if (max != 1) { 776 reportSchemaError("cos-all-limited.1.2", null, parent); 777 if (min > 1) 778 min = 1; 779 max = 1; 780 } 781 } 782 783 particle.fMaxOccurs = min; 784 particle.fMaxOccurs = max; 785 786 return particle; 787 } 788 789 private static String processAttValue(String original) { 791 StringBuffer newVal = new StringBuffer (original.length()); 793 for(int i=0; i<original.length(); i++) { 794 char currChar = original.charAt(i); 795 if(currChar == '"') { 796 newVal.append("""); 797 } else if (currChar == '>') { 798 newVal.append(">"); 799 } else if (currChar == '&') { 800 newVal.append("&"); 801 } else { 802 newVal.append(currChar); 803 } 804 } 805 return newVal.toString(); 806 } 807 } 808 | Popular Tags |