users@jaxb.java.net

Re: help with custom bindings

From: Joe Fialli <joseph.fialli_at_sun.com>
Date: Fri, 31 Jan 2003 14:03:18 -0500

Marc Dumontier wrote:
> Hi,
>
> I was wondering if there's a way to do the following.
> I'd like to add a set of property = value constants in the following piece
> of schema
>
> for example, i'd like to have in the interface or some other object linked
> it it
> static int NOT_SPECIFIED = 0;
> static int CONSTITUTIVE = 23;
>
> the numbers are meaningful and can't be changed unfortunately. I can
> autogenerate code myself to do this if there's a way to embed the number in
> the enumeration tag. JAXB doesn't seem to like any other attributes in the
> xs:enumeration tag such as id.


I am not sure what you need is for the constant values, but the
typesafe enum design pattern does allow for efficient comparison.

http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums

We have received requests to extend the typesafe enum pattern to associate
integer values with enumerators, for usage in switch statements. This
functionality definitely deserves future consideration.

There is one way to achieve the functionality you are requesting with
JAXB today (if you can update your schema.)
Schema derived constants are generated for fixed attributes in the schema
with the following customization enabled.
Setting <jaxb:globalBindings fixedAttributeAsConstantProperty="true ">specifies
that all fixed attributes should be bound to Java constants. By default, fixed
attributes are mapped to either a simple or collection property.

With the above customization, the following schema fragment:
   <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>

Maps to this Java representation.
static final String COUNTRY= USA ;

-Joe Fialli, Sun Microsystems
>
> any help would be greaty appreciated
> thanks
> MD
>
> <xs:complexType name="BIND-cellstage_phase1">
> <xs:simpleContent>
> <xs:extension base="xs:integer">
> <xs:attribute name="value" use="required">
> <xs:simpleType>
> <xs:restriction
> base="xs:string">
> <xs:enumeration
> value="not-specified"/>
> <xs:enumeration
> value="constitutive"/>
> <xs:enumeration
> value="interphase"/>
> <xs:enumeration
> value="division"/>
> <xs:enumeration
> value="g1"/>
> <xs:enumeration
> value="s"/>
> <xs:enumeration
> value="g2"/>
> <xs:enumeration
> value="mitosis"/>
> <xs:enumeration
> value="prophase"/>
> <xs:enumeration
> value="prometaphase"/>
> <xs:enumeration
> value="metaphase"/>
> <xs:enumeration
> value="anaphase"/>
> <xs:enumeration
> value="telophase"/>
> <xs:enumeration
> value="cytokinesis"/>
> <xs:enumeration
> value="meiosis"/>
> <xs:enumeration
> value="prophase1"/>
> <xs:enumeration
> value="leptotene"/>
> <xs:enumeration
> value="zygotene"/>
> <xs:enumeration
> value="pachytene"/>
> <xs:enumeration
> value="diplotene"/>
> <xs:enumeration
> value="diakinesis"/>
> <xs:enumeration
> value="metaphase1"/>
> <xs:enumeration
> value="anaphase1"/>
> <xs:enumeration
> value="telophase1"/>
> <xs:enumeration
> value="meiotic-cytokinesis"/>
> <xs:enumeration
> value="prophase2"/>
> <xs:enumeration
> value="metaphase2"/>
> <xs:enumeration
> value="anaphase2"/>
> <xs:enumeration
> value="telophase2"/>
> <xs:enumeration
> value="meiotic-cytokinesis2"/>
> <xs:enumeration
> value="other"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>


--