users@jaxb.java.net

Re: Generating custom method

From: Sekhar Vajjhala <sekhar.vajjhala_at_sun.com>
Date: Fri, 06 Jun 2003 07:18:38 -0400

Saurabh Arora wrote:
>
> Is it possible to generate custom method for a schema.

It is not possible to add a custom method. Association of
application specific behavior with generated code is something
we plan to address in the next version of the JAXB specification.

>
> Like for each multi value element i would like to add the method
> addXYS()
>
> For example
> ave a simple xsd as below,
>
> <xsd:element name="A" >
> <xsd:complexType >
> <xsd:attribute name="ID" type="xsd:string"
> use="required"/>
> <xs:element name="zip" type="xs:integer" minOccurs="0"
> maxOccurs="unbounded" />
> </xsd:complexType>
> </xsd:element>
>
> I endup getting classes like
>
> AType
>
> with method
>
> java.util.List getZips()
>
> Is it possible to add custom method( through custom extension) so that
> we get the function
>
> addzip(Zip zp1)
> {
> getZips().add(zp1);
> }
>
> It also gives the advantage for moving the responsibility to add Zip's
> to the JAXB code then user. Since just exposing getZips as List can lead
> to problem if the user expects adds a wrong entry.
> Ex
>
> getZips().add(new Object());
>

The next version of JAXB specification we plan to leverage
Generics being added in J2SE 1.5 platform. Generics would
provide type safety so such errors would be caught at
compile time rather than at run time.

> Is it possible to add such customization to the xsd.
>
> saurabh arora

Sekhar