Enums not generated by JAXB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liorchaga
    New Member
    • Mar 2008
    • 2

    Enums not generated by JAXB

    I'm using JAXB to generate classes from an XML schema.
    I have two simpleTypes with String restrictions to specific enumeration values as follows:

    Code:
    <xs:simpleType name="RestDaysHandlingMode">
    	<xs:restriction base="xs:string">
    		<xs:enumeration value="Forward"></xs:enumeration>
    		<xs:enumeration value="ForwardUnlessMonthChange"></xs:enumeration>
    		<xs:enumeration value="NoShift"></xs:enumeration>
    	</xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="YearMonthMethod">
        	<xs:restriction base="xs:string">
        		<xs:enumeration value="30_360"></xs:enumeration>
        		<xs:enumeration value="Actual_360"></xs:enumeration>
        		<xs:enumeration value="Actual_365"></xs:enumeration>
        		<xs:enumeration value="Actual_Actual"></xs:enumeration>
        	</xs:restriction>
    </xs:simpleType>
    Although no essencial differences are apparent, the JAXB generates an enum from the first one:

    Code:
    @XmlEnum
    public enum RestDaysHandlingMode {
    
        @XmlEnumValue("Forward")
        FORWARD("Forward"),
        @XmlEnumValue("ForwardUnlessMonthChange")
        FORWARD_UNLESS_MONTH_CHANGE("ForwardUnlessMonthChange"),
        @XmlEnumValue("NoShift")
        NO_SHIFT("NoShift");
        private final String value;
    
        RestDaysHandlingMode(String v) {
            value = v;
        }
    
        public String value() {
            return value;
        }
    
        public static RestDaysHandlingMode fromValue(String v) {
            for (RestDaysHandlingMode c: RestDaysHandlingMode.values()) {
                if (c.value.equals(v)) {
                    return c;
                }
            }
            throw new IllegalArgumentException(v);
        }
    
    }

    whereas the second type is handled as a simple string (the following is taken from a class that is generated by JAXB and contains an element of the second type):
    Code:
        /**
         * Gets the value of the yearMonthMethod property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getYearMonthMethod() {
            return yearMonthMethod;
        }
    Any ideas?
  • liorchaga
    New Member
    • Mar 2008
    • 2

    #2
    No help needed, the problem was solved. It's because of this line:
    Code:
    <xs:enumeration value="30_360"></xs:enumeration>
    an identifier that starts with a digit cannot be generated, and so the type is generated as a String.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by liorchaga
      No help needed, the problem was solved. It's because of this line:
      Code:
      <xs:enumeration value="30_360"></xs:enumeration>
      an identifier that starts with a digit cannot be generated, and so the type is generated as a String.
      Good work. Good luck with the rest of it.

      Comment

      Working...