users@jaxb.java.net

Re: Generating custom method

From: Sekhar Vajjhala <sekhar.vajjhala_at_sun.com>
Date: Fri, 06 Jun 2003 12:09:52 -0600

My previous comments indicated features that would be available only
in the next version of the JAXB specification. But here are some
more alternatives that you can use with the JAXB 1.0.1 release.

1. A collection type can be bound to an indexed property (thereby
   providing type safety) instead of a List property. Indexed property is
   described in Section 4.5.2.1 of the specification. To bind to an
   indexed property you can set the collectionType attribute
   to "indexed". The collectionType can be set either on the
   <globalBindings> or on the <property> customizations. For e.g.

       <property collectionType="indexed"/>
    or <globalBindings collectionType="indexed"/>

2. Another alternative is to use the implClass customization. Here, you
   can subclass a schema derived implementation class to which you can add
   application specific functionality (in this case that would be
   the method addZip ). See
   http://java.sun.com/xml/jaxb/extendingJaxbGeneratedClasses.html for
   more details. As pointed in a different email thread,
   this describes a two-step compilation that's no longer necessary in
   JAXB 1.0.1. E.g., if you unzip
   http://java.sun.com/xml/jaxb/subclass-workaround.zip and delete these
   two lines from subclass-workaround-inline/build.xml:

   41,42d42
     < <xslt in="address.xsd" out="addressPrime.xsd" style="stripImplClass.xsl"/>
     < <xjc schema="addressPrime.xsd" target="."/>

   it should work.

On Fri, 6 Jun 2003 02:37:52 -0600, Saurabh Arora <sarora_at_novell.com> wrote:

>Is it possible to generate custom method for a schema.
>
>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());
>
>
>Is it possible to add such customization to the xsd.
>

Sekhar Vajjhala