Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332782

Summary: minOccurs not generated on element when inside xsd:all
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
MOXy - Fix
none
MOXy - Test Cases
none
MOXy - Fix none

Description Blaise Doughan CLA 2010-12-16 13:37:26 EST
From:
http://stackoverflow.com/questions/4460158/generating-schema-with-default-minoccurs-using-moxy/4464124#4464124

The following schema should be created:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="root">
    <xs:sequence>
      <xs:element name="duration" type="xs:int" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Instead of:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:complexType name="root">
      <xsd:all>
         <xsd:element name="duration" type="xsd:int"/>
      </xsd:all>
   </xsd:complexType>
</xsd:schema>

For the following code:

package minoccurs;

import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.bind.annotation.XmlType;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.persistence.Version;

public class Demo {

    @XmlType(propOrder = {})
    public static class Root {

        private Integer duration; 

        public Integer getDuration() {
            return duration;
        }

        public void setDuration(Integer duration) {
            this.duration = duration;
        }

    }

    public static class MySchemaOutputResolver extends SchemaOutputResolver {

        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            StreamResult result = new StreamResult(System.out);
            result.setSystemId(suggestedFileName);
            return result;
        }

    }

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Root.class);
        System.out.println(jc);
        System.out.println(Version.getVersionString());
        jc.generateSchema(new MySchemaOutputResolver());
    }
}
Comment 1 Blaise Doughan CLA 2010-12-17 15:51:22 EST
Created attachment 185459 [details]
MOXy - Fix
Comment 2 Blaise Doughan CLA 2010-12-20 10:40:01 EST
Created attachment 185554 [details]
MOXy - Test Cases
Comment 3 Blaise Doughan CLA 2010-12-20 10:42:26 EST
Created attachment 185555 [details]
MOXy - Fix
Comment 4 Blaise Doughan CLA 2010-12-20 11:02:31 EST
Correction to bug statement.  The following is what should be generated:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="root">
    <xs:all>
      <xs:element name="duration" type="xs:int" minOccurs="0"/>
    </xs:all>
  </xs:complexType>
</xs:schema>




Fix checked into trunk at rev:  8728

Code reviewed by: David McCann

Removed check that explicitly prevented minOccurs=0 from being written on elements declared within an all block.
Comment 5 Blaise Doughan CLA 2011-01-10 13:53:00 EST
Fixed as per above comments.
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:20:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink