users@jaxb2-commons.java.net

Re: Generate enum?

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Sun, 18 Dec 2011 22:27:50 +0100

Hi,


> We have some places where we do something like:
>      <xs:element name="Status">
>        <xs:simpleType>
>          <xs:restriction base="xs:string">
>            <xs:enumeration value="APPROVED" />
>            <xs:enumeration value="UNDECIDED" />
>            <xs:enumeration value="REJECTED" />
>          </xs:restriction>
>        </xs:simpleType>
>      </xs:element>
>
> Is there any way to have a java enum or interface or class generated
> for those constants?

I think the inheritance plugin must be able to do this.

http://confluence.highsource.org/display/J2B/Inheritance+plugin

See
* https://svn.java.net/svn/jaxb2-commons~svn/basics/trunk/tests/issues/src/main/resources/binding.xjb
* https://svn.java.net/svn/jaxb2-commons~svn/basics/trunk/tests/issues/src/main/resources/schema.xsd

                <jaxb:bindings node="xsd:element[@name='issueJIIB38']">
                        <jaxb:class/>
                        <inheritance:implements>java.lang.Cloneable</inheritance:implements>
                </jaxb:bindings>

        <xs:simpleType name="issueJIIB38Type">
                <xs:restriction base="xs:string">
                        <xs:enumeration value="a"/>
                        <xs:enumeration value="b"/>
                        <xs:enumeration value="c"/>
                        <xs:enumeration value="d"/>
                </xs:restriction>
        </xs:simpleType>

        <xs:element name="issueJIIB38" type="issueJIIB38Type"/>

I'm not sure if it is enough, please file an issue if yo miss something.

Bye,
/lexi