Documentation for required says:
If
required()istrue, then Javabean property is mapped to an XML schema element declaration withminOccurs="1".maxOccursis"1"for a single valued property and"unbounded"for a multivalued property.If
required()isfalse, then the Javabean property is mapped to XML Schema element declaration withminOccurs="0".maxOccursis"1"for a single valued property and"unbounded"for a multivalued property.
Documentation for nillable says:
If
nillable()istrue, then the JavaBean property is mapped to a XML Schemanillableelement declaration.
Code for
xs:complexType:
public class WSData {
    //...
    @XmlElement(required = true, nillable = false)
    public void setMonth(XmlMonthType month) {
        this.month = month;
    }
    public void setUserLogin(String userLogin) {
        this.userLogin = userLogin;
    }
}
Code for xs:simpleType:
@XmlType
@XmlEnum(Integer.class)
public enum XmlMonthType {
    @XmlEnumValue("1")
    JANUARY,
    @XmlEnumValue("2")
    FEBRUARY,
    @XmlEnumValue("3")
    MARCH,
    /* ... months 4 ~9 ... */
    @XmlEnumValue("10")
    OCTOBER,
    @XmlEnumValue("11")
    NOVEMBER,
    @XmlEnumValue("12")
    DECEMBER;
}
Generated XML Schema:
<xs:complexType name="wsData">
  <xs:sequence>
    <xs:element name="month" type="xs:string"/>
    <xs:element minOccurs="0" name="userLogin" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:simpleType name="xmlMonthType">
  <xs:restriction base="xs:int">
    <xs:enumeration value="1"/>
    <xs:enumeration value="2"/>
    <xs:enumeration value="3"/>
    <!-- ... months 4 ~9 ... -->
    <xs:enumeration value="10"/>
    <xs:enumeration value="11"/>
    <xs:enumeration value="12"/>
  </xs:restriction>
</xs:simpleType>
The facts:
- The default value for minOccurs is 1. So, month is required (must exist);
 - The month has a restriction. So, month can only have a value defined by one of the 12 defined enumerations;
 - The default value for nillable is false. So, month can't have empty values;
 - The XML Schema is generated correctly.
 
The problems:
- It is accepting month's abcense (mustn't exist);
 - It is accepting any values for month, like 13 (except when isn't parseable to Integer);
 - It is accepting empty values;
 
I wasn't expecting these problems, am I missing something?
If that behavior is correct, what is the purpose of required, nillable and xs:restriction?