Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4017

SchemaCollection.addCrossImports handles only XmlSchemaSequence instead of all XmlSchemaGroupParticle

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.4
    • 2.4.6, 2.5.2
    • JAXB Databinding
    • None
    • Novice

    Description

      This issues seems to be the same as: http://cxf.547215.n5.nabble.com/validation-error-td5101800.html

      In my context, it happends only when my WebMethod interface holds an Exception

      It looks like org.apache.cxf.common.xmlschema.SchemaCollection.addCrossImportsType has been written for XmlSchemaSequence only, while it could be called on any XmlSchemaGroupParticle.

      Then, I adapted the code in SchemaCollection.addCrossImportsType to the three specializations of XmlSchemaGroupParticle and it seems to work properly.

          private static final XmlSchemaChoice EMPTY_CHOICE = new XmlSchemaChoice();
          private static final XmlSchemaAll EMPTY_ALL = new XmlSchemaAll();
      
      ...
      
      private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
              // the base type might cross schemas.
              if (schemaType instanceof XmlSchemaComplexType) {
                  XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
                  XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
                  addCrossImports(schema, complexType.getContentModel());
                  addCrossImportsAttributeList(schema, complexType.getAttributes());
                  // could it be a choice or something else?
                  
                  // HACK QFS
                  if (complexType.getParticle() instanceof XmlSchemaChoice) {
                  	XmlSchemaChoice choice = null;
      
      				// XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
                      {
                          XmlSchemaParticle particle = complexType.getParticle();
                          XmlSchemaChoice localChoice = null;
      
                          if (particle == null) {
                              // the code that uses this wants to iterate. An empty one is more useful than
                              // a null pointer, and certainly an exception.
                          	localChoice = EMPTY_CHOICE;
                          } else {
                              try {
                              	localChoice = (XmlSchemaChoice) particle;
                              } catch (ClassCastException cce) {
                              	XmlSchemaUtils.unsupportedConstruct("NON_CHOICE_PARTICLE", complexType);
                              }
                          }
      
                          choice = localChoice;
                      }
                      
                      //addCrossImportsSequence(schema, sequence);
                      {
                          for (XmlSchemaObject seqMember : choice.getItems()) {
                              if (seqMember instanceof XmlSchemaElement) {
                                  addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
                              }
                          }
                      }
                  } else if (complexType.getParticle() instanceof XmlSchemaAll) {
                  	XmlSchemaAll all = null;
      
      				// XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
                      {
                          XmlSchemaParticle particle = complexType.getParticle();
                          XmlSchemaAll localAll = null;
      
                          if (particle == null) {
                              // the code that uses this wants to iterate. An empty one is more useful than
                              // a null pointer, and certainly an exception.
                          	localAll = EMPTY_ALL;
                          } else {
                              try {
                              	localAll = (XmlSchemaAll) particle;
                              } catch (ClassCastException cce) {
                              	XmlSchemaUtils.unsupportedConstruct("NON_ALL_PARTICLE", complexType);
                              }
                          }
      
                          all = localAll;
                      }
                      
                      //addCrossImportsSequence(schema, sequence);
                      {
                          for (XmlSchemaObject seqMember : all.getItems()) {
                              if (seqMember instanceof XmlSchemaElement) {
                                  addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
                              }
                          }
                      }
                  } else {
                      XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
                      addCrossImportsSequence(schema, sequence);
                  }
                  // END QFS HACK
              }
          }
      

      Benoit Lacelle
      ActivePivot Consultant @ Quartetfs

      Attachments

        Activity

          People

            dkulp Daniel Kulp
            benoitl Benoit Lacelle
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: