users@jaxb.java.net

Re: Enumeration with int values from schema

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Thu, 3 Jan 2008 09:45:34 +0100

ok, sanity check:

- what JAXB version are you using ?
- how are you compiling it ?

In my case:

I am using the latest jaxb (2.1), and using an ant task to compile it:
https://footprint.dev.java.net/source/browse/*checkout*/footprint/trunk/footprint-core/build.xml?content-type=text%2Fplain&rev=355

hope that helps :) ........ Happy New Year.........

On Jan 3, 2008 9:00 AM, Pierre Buyle <pierre.buyle_at_irislink.com> wrote:
>
> Hi,
>
> I do use xsd:int as base type:
> Here is my sample XSD without the JAXB annotations required to generate a
> typesafe enum (since int values are not valid Java identifiers).
> <xsd:simpleType>
> <xsd:restriction base="xsd:int">
> <xsd:enumeration value="-2" />
> <xsd:enumeration value="-1" />
> <xsd:enumeration value="0" />
> <xsd:enumeration value="1" />
> <xsd:enumeration value="2" />
> </xsd:restriction>
> </xsd:simpleType>
>
>
>
>
> Felipe Gaucho wrote:
> >
> > you missed the base type:
> >
> > <xsd:simpleType name="post.process.mode">
> > <xsd:restriction base='xsd:string'> <<<<<<<<<< HERE, you must write
> > base='xsd:int'
> > <xsd:enumeration value="NONE" />
> > <xsd:enumeration value="RENAME" />
> > <xsd:enumeration value="MOVE" />
> > </xsd:restriction>
> > </xsd:simpleType>
> >
> >
> > On Jan 2, 2008 5:13 PM, Pierre Buyle <pierre.buyle_at_irislink.com> wrote:
> >>
> >> Hi,
> >>
> >> I'm generating typesafe Enum from an xsd:restriction with xsd:int as
> >> baseType. It works when using the jxb:typesafeEnumClass and
> >> jxb:typesafeEnumMember appinfo annotations. However, the value() method
> >> for
> >> the generated enum does not return int (or Integer) values but String.
> >> This
> >> is fine for most case but it prevents enumeration members to have any
> >> meaningful values.
> >>
> >> For instance, with the following schema
> >> <xsd:simpleType>
> >> <xsd:annotation>
> >> <xsd:appinfo>
> >> <jxb:typesafeEnumClass name="priority">
> >> <jxb:typesafeEnumMember name="VERY_LOW" value="-2" />
> >> <jxb:typesafeEnumMember name="LOW" value="-1" />
> >> <jxb:typesafeEnumMember name="NORMAL" value="0" />
> >> <jxb:typesafeEnumMember name="HIGH" value="1" />
> >> <jxb:typesafeEnumMember name="VERY_HIGH" value="2" />
> >> </jxb:typesafeEnumClass>
> >> </xsd:appinfo>
> >> </xsd:annotation>
> >> <xsd:restriction base="xsd:int">
> >> <xsd:enumeration value="-2" />
> >> <xsd:enumeration value="-1" />
> >> <xsd:enumeration value="0" />
> >> <xsd:enumeration value="1" />
> >> <xsd:enumeration value="2" />
> >> </xsd:restriction>
> >> </xsd:simpleType>
> >>
> >> The following code is generated
> >> public enum Priority {
> >> @XmlEnumValue("-2")
> >> VERY_LOW("-2"),
> >> @XmlEnumValue("-1")
> >> LOW("-1"),
> >> @XmlEnumValue("0")
> >> NORMAL("0"),
> >> @XmlEnumValue("1")
> >> HIGH("1"),
> >> @XmlEnumValue("2")
> >> VERY_HIGH("2");
> >> private final String value;
> >>
> >> Priority(String v) {
> >> value = v;
> >> }
> >>
> >> public String value() {
> >> return value;
> >> }
> >>
> >> public static MTaskData.Priority fromValue(String v) {
> >> for (MTaskData.Priority c: MTaskData.Priority.values()) {
> >> if (c.value.equals(v)) {
> >> return c;
> >> }
> >> }
> >> throw new IllegalArgumentException(v);
> >> }
> >> }
> >>
> >> Is there a way to have the value() method to return instances of the Java
> >> class for the xsd:restriction baseType ?
> >
>
> --
> View this message in context: http://www.nabble.com/Enumeration-with-int-values-from-schema-tp14580931p14593194.html
>
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>