1 57 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 58 59 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeFacetException; 60 import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory; 61 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets; 62 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 63 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 64 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 65 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 66 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl; 67 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeUseImpl; 68 import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl; 69 import com.sun.org.apache.xerces.internal.impl.xs.XSConstraints; 70 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl; 71 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 72 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl; 73 import com.sun.org.apache.xerces.internal.xs.XSAttributeUse; 74 import com.sun.org.apache.xerces.internal.xs.XSConstants; 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.xni.QName; 81 import org.w3c.dom.Element ; 82 83 100 101 class XSDComplexTypeTraverser extends XSDAbstractParticleTraverser { 102 103 private final static int GLOBAL_NUM = 11; 105 106 private String fName = null; 108 private String fTargetNamespace = null; 109 private short fDerivedBy = XSConstants.DERIVATION_RESTRICTION; 110 private short fFinal = XSConstants.DERIVATION_NONE; 111 private short fBlock = XSConstants.DERIVATION_NONE; 112 private short fContentType = XSComplexTypeDecl.CONTENTTYPE_EMPTY; 113 private XSTypeDefinition fBaseType = null; 114 private XSAttributeGroupDecl fAttrGrp = null; 115 private XSSimpleType fXSSimpleType = null; 116 private XSParticleDecl fParticle = null; 117 private boolean fIsAbstract = false; 118 private XSComplexTypeDecl fComplexTypeDecl = null; 119 private XSAnnotationImpl [] fAnnotations = null; 120 121 private XSParticleDecl fEmptyParticle = null; 122 123 private Object [] fGlobalStore = null; 125 private int fGlobalStorePos = 0; 126 127 XSDComplexTypeTraverser (XSDHandler handler, 128 XSAttributeChecker gAttrCheck) { 129 super(handler, gAttrCheck); 130 } 131 132 133 private static final boolean DEBUG=false; 134 135 private SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance(); 136 137 private class ComplexTypeRecoverableError extends Exception { 138 139 Object [] errorSubstText=null; 140 Element errorElem = null; 141 ComplexTypeRecoverableError() { 142 super(); 143 } 144 ComplexTypeRecoverableError(String msgKey, Object [] args, Element e) { 145 super(msgKey); 146 errorSubstText=args; 147 errorElem = e; 148 } 149 150 } 151 152 160 XSComplexTypeDecl traverseLocal(Element complexTypeNode, 161 XSDocumentInfo schemaDoc, 162 SchemaGrammar grammar) { 163 164 165 Object [] attrValues = fAttrChecker.checkAttributes(complexTypeNode, false, 166 schemaDoc); 167 String complexTypeName = genAnonTypeName(complexTypeNode); 168 contentBackup(); 169 XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode, 170 complexTypeName, attrValues, schemaDoc, grammar); 171 contentRestore(); 172 grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode)); 174 type.setIsAnonymous(); 175 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 176 177 return type; 178 } 179 180 188 XSComplexTypeDecl traverseGlobal (Element complexTypeNode, 189 XSDocumentInfo schemaDoc, 190 SchemaGrammar grammar) { 191 192 Object [] attrValues = fAttrChecker.checkAttributes(complexTypeNode, true, 193 schemaDoc); 194 String complexTypeName = (String ) attrValues[XSAttributeChecker.ATTIDX_NAME]; 195 contentBackup(); 196 XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode, 197 complexTypeName, attrValues, schemaDoc, grammar); 198 contentRestore(); 199 if (complexTypeName == null) { 200 reportSchemaError("s4s-att-must-appear", new Object []{SchemaSymbols.ELT_COMPLEXTYPE, SchemaSymbols.ATT_NAME}, complexTypeNode); 201 } else { 202 grammar.addGlobalTypeDecl(type); 203 } 204 grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode)); 206 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 207 208 return type; 209 } 210 211 212 private XSComplexTypeDecl traverseComplexTypeDecl(Element complexTypeDecl, 213 String complexTypeName, 214 Object [] attrValues, 215 XSDocumentInfo schemaDoc, 216 SchemaGrammar grammar) { 217 218 fComplexTypeDecl = new XSComplexTypeDecl(); 219 fAttrGrp = new XSAttributeGroupDecl(); 220 Boolean abstractAtt = (Boolean ) attrValues[XSAttributeChecker.ATTIDX_ABSTRACT]; 221 XInt blockAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_BLOCK]; 222 Boolean mixedAtt = (Boolean ) attrValues[XSAttributeChecker.ATTIDX_MIXED]; 223 XInt finalAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_FINAL]; 224 225 fName = complexTypeName; 226 fComplexTypeDecl.setName(fName); 227 fTargetNamespace = schemaDoc.fTargetNamespace; 228 229 fBlock = blockAtt == null ? schemaDoc.fBlockDefault : blockAtt.shortValue(); 230 fFinal = finalAtt == null ? schemaDoc.fFinalDefault : finalAtt.shortValue(); 231 fBlock &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION); 233 fFinal &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION); 234 235 if (abstractAtt != null && abstractAtt.booleanValue()) 236 fIsAbstract = true; 237 238 239 Element child = null; 240 241 try { 242 child = DOMUtil.getFirstChildElement(complexTypeDecl); 246 247 if (child != null) { 248 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 250 addAnnotation(traverseAnnotationDecl(child, attrValues, false, schemaDoc)); 251 child = DOMUtil.getNextSiblingElement(child); 252 } 253 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 254 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 255 new Object []{fName,SchemaSymbols.ELT_ANNOTATION}, 256 child); 257 } 258 } 259 if (child==null) { 263 267 fBaseType = SchemaGrammar.fAnyType; 269 processComplexContent(child, mixedAtt.booleanValue(), false, 270 schemaDoc, grammar); 271 } 272 else if (DOMUtil.getLocalName(child).equals 273 (SchemaSymbols.ELT_SIMPLECONTENT)) { 274 traverseSimpleContent(child, schemaDoc, grammar); 278 Element elemTmp = DOMUtil.getNextSiblingElement(child); 279 if (elemTmp != null) { 280 String siblingName = DOMUtil.getLocalName(elemTmp); 281 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 282 new Object []{fName,siblingName}, 283 elemTmp); 284 } 285 } 286 else if (DOMUtil.getLocalName(child).equals 287 (SchemaSymbols.ELT_COMPLEXCONTENT)) { 288 traverseComplexContent(child, mixedAtt.booleanValue(), 289 schemaDoc, grammar); 290 Element elemTmp = DOMUtil.getNextSiblingElement(child); 291 if (elemTmp != null) { 292 String siblingName = DOMUtil.getLocalName(elemTmp); 293 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 294 new Object []{fName,siblingName}, 295 elemTmp); 296 } 297 } 298 else { 299 305 fBaseType = SchemaGrammar.fAnyType; 307 processComplexContent(child, mixedAtt.booleanValue(), false, 308 schemaDoc, grammar); 309 } 310 311 } 312 catch (ComplexTypeRecoverableError e) { 313 handleComplexTypeError(e.getMessage(), e.errorSubstText, 314 e.errorElem); 315 } 316 317 if (DEBUG) { 318 System.out.println(fName); 319 } 320 fComplexTypeDecl.setValues(fName, fTargetNamespace, fBaseType, 321 fDerivedBy, fFinal, fBlock, fContentType, fIsAbstract, 322 fAttrGrp, fXSSimpleType, fParticle, new XSObjectListImpl(fAnnotations, 323 fAnnotations == null? 0 : fAnnotations.length)); 324 return fComplexTypeDecl; 325 } 326 327 328 private void traverseSimpleContent(Element simpleContentElement, 329 XSDocumentInfo schemaDoc, 330 SchemaGrammar grammar) 331 throws ComplexTypeRecoverableError { 332 333 334 Object [] simpleContentAttrValues = fAttrChecker.checkAttributes(simpleContentElement, false, 335 schemaDoc); 336 337 fContentType = XSComplexTypeDecl.CONTENTTYPE_SIMPLE; 341 fParticle = null; 342 343 Element simpleContent = DOMUtil.getFirstChildElement(simpleContentElement); 344 if (simpleContent != null) { 345 if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) { 347 addAnnotation(traverseAnnotationDecl(simpleContent, simpleContentAttrValues, false, schemaDoc)); 348 simpleContent = DOMUtil.getNextSiblingElement(simpleContent); 349 } 350 } 351 352 if (simpleContent==null) { 354 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 355 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.2", 356 new Object []{fName,SchemaSymbols.ELT_SIMPLECONTENT}, 357 simpleContentElement); 358 } 359 360 String simpleContentName = DOMUtil.getLocalName(simpleContent); 364 if (simpleContentName.equals(SchemaSymbols.ELT_RESTRICTION)) 365 fDerivedBy = XSConstants.DERIVATION_RESTRICTION; 366 else if (simpleContentName.equals(SchemaSymbols.ELT_EXTENSION)) 367 fDerivedBy = XSConstants.DERIVATION_EXTENSION; 368 else { 369 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 370 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 371 new Object []{fName,simpleContentName}, 372 simpleContent); 373 } 374 Element elemTmp = DOMUtil.getNextSiblingElement(simpleContent); 375 if (elemTmp != null) { 376 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 377 String siblingName = DOMUtil.getLocalName(elemTmp); 378 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 379 new Object []{fName,siblingName}, 380 elemTmp); 381 } 382 383 Object [] derivationTypeAttrValues = fAttrChecker.checkAttributes(simpleContent, false, 384 schemaDoc); 385 QName baseTypeName = (QName) derivationTypeAttrValues[XSAttributeChecker.ATTIDX_BASE]; 386 387 388 if (baseTypeName==null) { 392 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 393 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 394 throw new ComplexTypeRecoverableError("s4s-att-must-appear", 395 new Object []{simpleContentName, "base"}, simpleContent); 396 } 397 398 XSTypeDefinition type = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc, 399 XSDHandler.TYPEDECL_TYPE, baseTypeName, 400 simpleContent); 401 if (type==null) { 402 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 403 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 404 throw new ComplexTypeRecoverableError(); 405 } 406 407 fBaseType = type; 408 409 XSSimpleType baseValidator = null; 410 XSComplexTypeDecl baseComplexType = null; 411 int baseFinalSet = 0; 412 413 if ((type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)) { 415 416 baseComplexType = (XSComplexTypeDecl)type; 417 baseFinalSet = baseComplexType.getFinal(); 418 if (baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { 420 baseValidator = (XSSimpleType)baseComplexType.getSimpleType(); 421 } 422 else if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION && 424 baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_MIXED && 425 ((XSParticleDecl)baseComplexType.getParticle()).emptiable()) { 426 } 427 else { 428 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 429 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 430 throw new ComplexTypeRecoverableError("src-ct.2.1", 431 new Object []{fName, baseComplexType.getName()}, simpleContent); 432 } 433 } 434 else { 435 baseValidator = (XSSimpleType)type; 436 if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) { 438 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 439 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 440 throw new ComplexTypeRecoverableError("src-ct.2.1", 441 new Object []{fName, baseValidator.getName()}, simpleContent); 442 } 443 baseFinalSet=baseValidator.getFinal(); 444 } 445 446 if ((baseFinalSet & fDerivedBy)!=0) { 450 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 451 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 452 String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ? 453 "cos-ct-extends.1.1" : "derivation-ok-restriction.1"; 454 throw new ComplexTypeRecoverableError(errorKey, 455 new Object []{fName, fBaseType.getName()}, simpleContent); 456 } 457 458 simpleContent = DOMUtil.getFirstChildElement(simpleContent); 462 if (simpleContent != null) { 463 465 if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) { 466 addAnnotation(traverseAnnotationDecl(simpleContent, derivationTypeAttrValues, false, schemaDoc)); 467 simpleContent = DOMUtil.getNextSiblingElement(simpleContent); 468 } 469 470 if (simpleContent !=null && 471 DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)){ 472 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 473 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 474 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 475 new Object []{fName,SchemaSymbols.ELT_ANNOTATION}, 476 simpleContent); 477 } 478 } 479 480 if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) { 484 485 if (simpleContent !=null && 490 DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_SIMPLETYPE )) { 491 492 XSSimpleType dv = fSchemaHandler.fSimpleTypeTraverser.traverseLocal( 493 simpleContent, schemaDoc, grammar); 494 if (dv == null) { 495 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 496 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 497 throw new ComplexTypeRecoverableError(); 498 } 499 502 if (baseValidator != null && 503 !XSConstraints.checkSimpleDerivationOk(dv, baseValidator, 504 baseValidator.getFinal())) { 505 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 506 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 507 throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.2.2.1", 508 new Object []{fName, dv.getName(), baseValidator.getName()}, 509 simpleContent); 510 } 511 baseValidator = dv; 512 simpleContent = DOMUtil.getNextSiblingElement(simpleContent); 513 } 514 515 if (baseValidator == null) { 518 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 519 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 520 throw new ComplexTypeRecoverableError("src-ct.2.2", 521 new Object []{fName}, simpleContent); 522 } 523 524 Element attrNode = null; 528 XSFacets facetData = null; 529 short presentFacets = 0 ; 530 short fixedFacets = 0 ; 531 532 if (simpleContent!=null) { 533 FacetInfo fi = traverseFacets(simpleContent, baseValidator, schemaDoc); 534 attrNode = fi.nodeAfterFacets; 535 facetData = fi.facetdata; 536 presentFacets = fi.fPresentFacets; 537 fixedFacets = fi.fFixedFacets; 538 } 539 540 fXSSimpleType = schemaFactory.createTypeRestriction(null,schemaDoc.fTargetNamespace,(short)0,baseValidator,null); 541 try{ 542 fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport); 543 fXSSimpleType.applyFacets(facetData, presentFacets, fixedFacets, fValidationState); 544 }catch(InvalidDatatypeFacetException ex){ 545 reportSchemaError(ex.getKey(), ex.getArgs(), simpleContent); 546 } 547 548 if (attrNode != null) { 552 if (!isAttrOrAttrGroup(attrNode)) { 553 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 554 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 555 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 556 new Object []{fName,DOMUtil.getLocalName(attrNode)}, 557 attrNode); 558 } 559 Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp, 560 schemaDoc,grammar,fComplexTypeDecl); 561 if (node!=null) { 562 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 563 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 564 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 565 new Object []{fName,DOMUtil.getLocalName(node)}, 566 node); 567 } 568 } 569 570 try { 571 mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, false, simpleContentElement); 572 } catch (ComplexTypeRecoverableError e) { 573 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 574 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 575 throw e; 576 } 577 fAttrGrp.removeProhibitedAttrs(); 579 580 Object [] errArgs=fAttrGrp.validRestrictionOf(fName, baseComplexType.getAttrGrp()); 581 if (errArgs != null) { 582 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 583 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 584 throw new ComplexTypeRecoverableError((String )errArgs[errArgs.length-1], 585 errArgs, attrNode); 586 } 587 588 } 589 else { 593 fXSSimpleType = baseValidator; 594 if (simpleContent != null) { 595 Element attrNode = simpleContent; 599 if (!isAttrOrAttrGroup(attrNode)) { 600 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 601 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 602 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 603 new Object []{fName,DOMUtil.getLocalName(attrNode)}, 604 attrNode); 605 } 606 Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp, 607 schemaDoc,grammar,fComplexTypeDecl); 608 609 if (node!=null) { 610 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 611 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 612 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 613 new Object []{fName,DOMUtil.getLocalName(node)}, 614 node); 615 } 616 fAttrGrp.removeProhibitedAttrs(); 618 } 619 620 if (baseComplexType != null) { 621 try { 622 mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, true, simpleContentElement); 623 } catch (ComplexTypeRecoverableError e) { 624 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 625 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 626 throw e; 627 } 628 } 629 } 630 fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc); 633 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 634 } 635 636 private void traverseComplexContent(Element complexContentElement, 637 boolean mixedOnType, XSDocumentInfo schemaDoc, 638 SchemaGrammar grammar) 639 throws ComplexTypeRecoverableError { 640 641 642 Object [] complexContentAttrValues = fAttrChecker.checkAttributes(complexContentElement, false, 643 schemaDoc); 644 645 646 boolean mixedContent = mixedOnType; 650 Boolean mixedAtt = (Boolean ) complexContentAttrValues[XSAttributeChecker.ATTIDX_MIXED]; 651 if (mixedAtt != null) { 652 mixedContent = mixedAtt.booleanValue(); 653 } 654 655 656 fXSSimpleType = null; 661 662 Element complexContent = DOMUtil.getFirstChildElement(complexContentElement); 663 if (complexContent != null) { 664 if (DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)) { 666 addAnnotation(traverseAnnotationDecl(complexContent, complexContentAttrValues, false, schemaDoc)); 667 complexContent = DOMUtil.getNextSiblingElement(complexContent); 668 } 669 } 670 671 if (complexContent==null) { 673 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 674 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.2", 675 new Object []{fName,SchemaSymbols.ELT_COMPLEXCONTENT}, 676 complexContentElement); 677 } 678 679 String complexContentName = DOMUtil.getLocalName(complexContent); 683 if (complexContentName.equals(SchemaSymbols.ELT_RESTRICTION)) 684 fDerivedBy = XSConstants.DERIVATION_RESTRICTION; 685 else if (complexContentName.equals(SchemaSymbols.ELT_EXTENSION)) 686 fDerivedBy = XSConstants.DERIVATION_EXTENSION; 687 else { 688 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 689 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 690 new Object []{fName, complexContentName}, complexContent); 691 } 692 Element elemTmp = DOMUtil.getNextSiblingElement(complexContent); 693 if (elemTmp != null) { 694 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 695 String siblingName = DOMUtil.getLocalName(elemTmp); 696 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 697 new Object []{fName, siblingName}, elemTmp); 698 } 699 700 Object [] derivationTypeAttrValues = fAttrChecker.checkAttributes(complexContent, false, 701 schemaDoc); 702 QName baseTypeName = (QName) derivationTypeAttrValues[XSAttributeChecker.ATTIDX_BASE]; 703 704 705 if (baseTypeName==null) { 709 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 710 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 711 throw new ComplexTypeRecoverableError("s4s-att-must-appear", 712 new Object []{complexContentName, "base"}, complexContent); 713 } 714 715 XSTypeDefinition type = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc, 716 XSDHandler.TYPEDECL_TYPE, 717 baseTypeName, 718 complexContent); 719 720 if (type==null) { 721 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 722 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 723 throw new ComplexTypeRecoverableError(); 724 } 725 726 if (! (type instanceof XSComplexTypeDecl)) { 727 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 728 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 729 throw new ComplexTypeRecoverableError("src-ct.1", 730 new Object []{fName, type.getName()}, complexContent); 731 } 732 XSComplexTypeDecl baseType = (XSComplexTypeDecl)type; 733 fBaseType = baseType; 734 735 if ((baseType.getFinal() & fDerivedBy)!=0) { 739 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 740 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 741 String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ? 742 "cos-ct-extends.1.1" : "derivation-ok-restriction.1"; 743 throw new ComplexTypeRecoverableError(errorKey, 744 new Object []{fName, fBaseType.getName()}, complexContent); 745 } 746 747 complexContent = DOMUtil.getFirstChildElement(complexContent); 751 752 if (complexContent != null) { 753 if (DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)) { 755 addAnnotation(traverseAnnotationDecl(complexContent, derivationTypeAttrValues, false, schemaDoc)); 756 complexContent = DOMUtil.getNextSiblingElement(complexContent); 757 } 758 if (complexContent !=null && 759 DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)){ 760 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 761 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 762 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 763 new Object []{fName,SchemaSymbols.ELT_ANNOTATION}, complexContent); 764 } 765 } 766 try { 771 processComplexContent(complexContent, mixedContent, true, schemaDoc, 772 grammar); 773 } catch (ComplexTypeRecoverableError e) { 774 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 775 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 776 throw e; 777 } 778 779 XSParticleDecl baseContent = (XSParticleDecl)baseType.getParticle(); 783 if (fDerivedBy==XSConstants.DERIVATION_RESTRICTION) { 784 785 787 791 792 if (fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED && 793 baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) { 794 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 795 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 796 throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.4.1.2", 797 new Object []{fName, baseType.getName()}, 798 complexContent); 799 } 800 801 try { 802 mergeAttributes(baseType.getAttrGrp(), fAttrGrp, fName, false, complexContent); 803 } catch (ComplexTypeRecoverableError e) { 804 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 805 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 806 throw e; 807 } 808 fAttrGrp.removeProhibitedAttrs(); 810 811 if (baseType != SchemaGrammar.fAnyType) { 812 Object [] errArgs = fAttrGrp.validRestrictionOf(fName, baseType.getAttrGrp()); 813 if (errArgs != null) { 814 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 815 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 816 throw new ComplexTypeRecoverableError((String )errArgs[errArgs.length-1], 817 errArgs, complexContent); 818 } 819 } 820 } 821 else { 822 823 825 if (fParticle == null) { 827 fContentType = baseType.getContentType(); 828 fXSSimpleType = (XSSimpleType)baseType.getSimpleType(); 829 fParticle = baseContent; 830 } 831 else if (baseType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_EMPTY) { 832 } 833 else { 834 if (fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT && 838 baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { 839 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 840 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 841 throw new ComplexTypeRecoverableError("cos-ct-extends.1.4.3.2.2.1.a", 842 new Object []{fName}, complexContent); 843 } 844 else if (fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED && 845 baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) { 846 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 847 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 848 throw new ComplexTypeRecoverableError("cos-ct-extends.1.4.3.2.2.1.b", 849 new Object []{fName}, complexContent); 850 } 851 852 if (fParticle.fType == XSParticleDecl.PARTICLE_MODELGROUP && 854 ((XSModelGroupImpl)fParticle.fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL || 855 ((XSParticleDecl)baseType.getParticle()).fType == XSParticleDecl.PARTICLE_MODELGROUP && 856 ((XSModelGroupImpl)(((XSParticleDecl)baseType.getParticle())).fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL) { 857 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 858 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 859 throw new ComplexTypeRecoverableError("cos-all-limited.1.2", 860 new Object []{}, complexContent); 861 } 862 XSModelGroupImpl group = new XSModelGroupImpl(); 864 group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 865 group.fParticleCount = 2; 866 group.fParticles = new XSParticleDecl[2]; 867 group.fParticles[0] = (XSParticleDecl)baseType.getParticle(); 868 group.fParticles[1] = fParticle; 869 XSParticleDecl particle = new XSParticleDecl(); 871 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 872 particle.fValue = group; 873 874 fParticle = particle; 875 } 876 877 fAttrGrp.removeProhibitedAttrs(); 879 try { 880 mergeAttributes(baseType.getAttrGrp(), fAttrGrp, fName, true, complexContent); 881 } catch (ComplexTypeRecoverableError e) { 882 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 883 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 884 throw e; 885 } 886 887 } 888 889 fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc); 891 fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc); 892 893 } 895 896 private void mergeAttributes(XSAttributeGroupDecl fromAttrGrp, 900 XSAttributeGroupDecl toAttrGrp, 901 String typeName, 902 boolean extension, 903 Element elem) 904 throws ComplexTypeRecoverableError { 905 906 XSObjectList attrUseS = fromAttrGrp.getAttributeUses(); 907 XSAttributeUseImpl duplicateAttrUse = null, oneAttrUse = null; 908 int attrCount = attrUseS.getLength(); 909 for (int i=0; i<attrCount; i++) { 910 oneAttrUse = (XSAttributeUseImpl)attrUseS.item(i); 911 XSAttributeUse existingAttrUse = toAttrGrp.getAttributeUse(oneAttrUse.fAttrDecl.getNamespace(), 912 oneAttrUse.fAttrDecl.getName()); 913 if (existingAttrUse == null) { 914 915 String idName = toAttrGrp.addAttributeUse(oneAttrUse); 916 if (idName != null) { 917 throw new ComplexTypeRecoverableError("ct-props-correct.5", 918 new Object []{typeName, idName, oneAttrUse.fAttrDecl.getName()}, 919 elem); 920 } 921 } 922 else { 923 if (extension) { 924 throw new ComplexTypeRecoverableError("ct-props-correct.4", 925 new Object []{typeName, oneAttrUse.fAttrDecl.getName()}, 926 elem); 927 } 928 } 929 } 930 if (extension) { 932 if (toAttrGrp.fAttributeWC==null) { 933 toAttrGrp.fAttributeWC = fromAttrGrp.fAttributeWC; 934 } 935 else if (fromAttrGrp.fAttributeWC != null) { 936 toAttrGrp.fAttributeWC = toAttrGrp.fAttributeWC.performUnionWith(fromAttrGrp.fAttributeWC, toAttrGrp.fAttributeWC.fProcessContents); 937 } 938 939 } 940 } 941 942 private void processComplexContent(Element complexContentChild, 943 boolean isMixed, boolean isDerivation, 944 XSDocumentInfo schemaDoc, SchemaGrammar grammar) 945 throws ComplexTypeRecoverableError { 946 947 Element attrNode = null; 948 XSParticleDecl particle = null; 949 950 boolean emptyParticle = false; 952 if (complexContentChild != null) { 953 958 959 String childName = DOMUtil.getLocalName(complexContentChild); 960 961 if (childName.equals(SchemaSymbols.ELT_GROUP)) { 962 963 particle = fSchemaHandler.fGroupTraverser.traverseLocal(complexContentChild, 964 schemaDoc, grammar); 965 attrNode = DOMUtil.getNextSiblingElement(complexContentChild); 966 } 967 else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { 968 particle = traverseSequence(complexContentChild,schemaDoc,grammar, 969 NOT_ALL_CONTEXT,fComplexTypeDecl); 970 if (particle != null) { 971 XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; 972 if (group.fParticleCount == 0) 973 emptyParticle = true; 974 } 975 attrNode = DOMUtil.getNextSiblingElement(complexContentChild); 976 } 977 else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { 978 particle = traverseChoice(complexContentChild,schemaDoc,grammar, 979 NOT_ALL_CONTEXT,fComplexTypeDecl); 980 if (particle != null && particle.fMinOccurs == 0) { 981 XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; 982 if (group.fParticleCount == 0) 983 emptyParticle = true; 984 } 985 attrNode = DOMUtil.getNextSiblingElement(complexContentChild); 986 } 987 else if (childName.equals(SchemaSymbols.ELT_ALL)) { 988 particle = traverseAll(complexContentChild,schemaDoc,grammar, 989 PROCESSING_ALL_GP,fComplexTypeDecl); 990 if (particle != null) { 991 XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; 992 if (group.fParticleCount == 0) 993 emptyParticle = true; 994 } 995 attrNode = DOMUtil.getNextSiblingElement(complexContentChild); 996 } 997 else { 998 attrNode = complexContentChild; 1000 } 1001 } 1002 1003 if (emptyParticle) { 1007 Element child = DOMUtil.getFirstChildElement(complexContentChild); 1009 if (child != null) { 1011 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 1012 child = DOMUtil.getNextSiblingElement(child); 1013 } 1014 } 1015 if (child == null) 1017 particle = null; 1018 } 1021 1022 if (particle == null && isMixed) { 1023 if (fEmptyParticle == null) { 1024 XSModelGroupImpl group = new XSModelGroupImpl(); 1025 group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 1026 group.fParticleCount = 0; 1027 group.fParticles = null; 1028 fEmptyParticle = new XSParticleDecl(); 1029 fEmptyParticle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 1030 fEmptyParticle.fValue = group; 1031 } 1032 particle = fEmptyParticle; 1033 } 1034 fParticle = particle; 1035 1036 if (fParticle == null) 1040 fContentType = XSComplexTypeDecl.CONTENTTYPE_EMPTY; 1041 else if (isMixed) 1042 fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; 1043 else 1044 fContentType = XSComplexTypeDecl.CONTENTTYPE_ELEMENT; 1045 1046 1047 if (attrNode != null) { 1051 if (!isAttrOrAttrGroup(attrNode)) { 1052 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 1053 new Object []{fName,DOMUtil.getLocalName(attrNode)}, 1054 attrNode); 1055 } 1056 Element node = 1057 traverseAttrsAndAttrGrps(attrNode,fAttrGrp,schemaDoc,grammar,fComplexTypeDecl); 1058 if (node!=null) { 1059 throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", 1060 new Object []{fName,DOMUtil.getLocalName(node)}, 1061 node); 1062 } 1063 if (!isDerivation) { 1066 fAttrGrp.removeProhibitedAttrs(); 1067 } 1068 } 1069 1070 1071 1072 } 1074 1075 private boolean isAttrOrAttrGroup(Element e) { 1076 String elementName = DOMUtil.getLocalName(e); 1077 1078 if (elementName.equals(SchemaSymbols.ELT_ATTRIBUTE) || 1079 elementName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) || 1080 elementName.equals(SchemaSymbols.ELT_ANYATTRIBUTE)) 1081 return true; 1082 else 1083 return false; 1084 } 1085 1086 private void traverseSimpleContentDecl(Element simpleContentDecl) { 1087 } 1088 1089 private void traverseComplexContentDecl(Element complexContentDecl, 1090 boolean mixedOnComplexTypeDecl) { 1091 } 1092 1093 1096 private String genAnonTypeName(Element complexTypeDecl) { 1097 1098 String typeName; 1103 Element node = DOMUtil.getParent(complexTypeDecl); 1104 typeName="#AnonType_"; 1105 while (node != null && (node != DOMUtil.getRoot(DOMUtil.getDocument(node)))) { 1106 typeName = typeName+node.getAttribute(SchemaSymbols.ATT_NAME); 1107 node = DOMUtil.getParent(node); 1108 } 1109 return typeName; 1110 } 1111 1112 1113 private void handleComplexTypeError(String messageId,Object [] args, 1114 Element e) { 1115 1116 if (messageId!=null) { 1117 reportSchemaError(messageId, args, e); 1118 } 1119 1120 fBaseType = SchemaGrammar.fAnyType; 1125 fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; 1126 fParticle = getErrorContent(); 1127 fAttrGrp.fAttributeWC = getErrorWildcard(); 1130 1131 return; 1132 1133 } 1134 1135 private XSParticleDecl getErrorContent() { 1136 XSParticleDecl particle = new XSParticleDecl(); 1137 particle.fType = XSParticleDecl.PARTICLE_WILDCARD; 1138 particle.fValue = getErrorWildcard(); 1139 particle.fMinOccurs = 0; 1140 particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED; 1141 XSModelGroupImpl group = new XSModelGroupImpl(); 1142 group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 1143 group.fParticleCount = 1; 1144 group.fParticles = new XSParticleDecl[1]; 1145 group.fParticles[0] = particle; 1146 XSParticleDecl errorContent = new XSParticleDecl(); 1147 errorContent.fType = XSParticleDecl.PARTICLE_MODELGROUP; 1148 errorContent.fValue = group; 1149 1150 return errorContent; 1151 } 1152 1153 private XSWildcardDecl getErrorWildcard() { 1154 XSWildcardDecl errorWildcard = new XSWildcardDecl(); 1155 errorWildcard.fProcessContents = XSWildcardDecl.PC_SKIP; 1156 return errorWildcard; 1157 } 1158 1159 private void contentBackup() { 1160 if(fGlobalStore == null) { 1161 fGlobalStore = new Object [GLOBAL_NUM]; 1162 fGlobalStorePos = 0; 1163 } 1164 if(fGlobalStorePos == fGlobalStore.length) { 1165 Object [] newArray = new Object [fGlobalStorePos+GLOBAL_NUM]; 1166 System.arraycopy(fGlobalStore, 0, newArray, 0, fGlobalStorePos); 1167 fGlobalStore = newArray; 1168 } 1169 fGlobalStore[fGlobalStorePos++] = fComplexTypeDecl; 1170 fGlobalStore[fGlobalStorePos++] = fIsAbstract?Boolean.TRUE:Boolean.FALSE; 1171 fGlobalStore[fGlobalStorePos++] = fName ; 1172 fGlobalStore[fGlobalStorePos++] = fTargetNamespace; 1173 fGlobalStore[fGlobalStorePos++] = new Integer ((fDerivedBy << 16) + fFinal); 1175 fGlobalStore[fGlobalStorePos++] = new Integer ((fBlock << 16) + fContentType); 1176 fGlobalStore[fGlobalStorePos++] = fBaseType; 1177 fGlobalStore[fGlobalStorePos++] = fAttrGrp; 1178 fGlobalStore[fGlobalStorePos++] = fParticle; 1179 fGlobalStore[fGlobalStorePos++] = fXSSimpleType; 1180 fGlobalStore[fGlobalStorePos++] = fAnnotations; 1181 } 1182 1183 private void contentRestore() { 1184 fAnnotations = (XSAnnotationImpl [])fGlobalStore[--fGlobalStorePos]; 1185 fXSSimpleType = (XSSimpleType)fGlobalStore[--fGlobalStorePos]; 1186 fParticle = (XSParticleDecl)fGlobalStore[--fGlobalStorePos]; 1187 fAttrGrp = (XSAttributeGroupDecl)fGlobalStore[--fGlobalStorePos]; 1188 fBaseType = (XSTypeDefinition)fGlobalStore[--fGlobalStorePos]; 1189 int i = ((Integer )(fGlobalStore[--fGlobalStorePos])).intValue(); 1190 fBlock = (short)(i >> 16); 1191 fContentType = (short)i; 1192 i = ((Integer )(fGlobalStore[--fGlobalStorePos])).intValue(); 1193 fDerivedBy = (short)(i >> 16); 1194 fFinal = (short)i; 1195 fTargetNamespace = (String )fGlobalStore[--fGlobalStorePos]; 1196 fName = (String )fGlobalStore[--fGlobalStorePos]; 1197 fIsAbstract = ((Boolean )fGlobalStore[--fGlobalStorePos]).booleanValue(); 1198 fComplexTypeDecl = (XSComplexTypeDecl)fGlobalStore[--fGlobalStorePos]; 1199 } 1200 1201 private void addAnnotation(XSAnnotationImpl annotation) { 1202 if(annotation == null) 1203 return; 1204 if(fAnnotations == null) { 1209 fAnnotations = new XSAnnotationImpl[1]; 1210 } else { 1211 XSAnnotationImpl [] tempArray = new XSAnnotationImpl[fAnnotations.length + 1]; 1212 System.arraycopy(fAnnotations, 0, tempArray, 0, fAnnotations.length); 1213 fAnnotations = tempArray; 1214 } 1215 fAnnotations[fAnnotations.length-1] = annotation; 1216 } 1217} 1218 | Popular Tags |