users@jaxb.java.net

Re: JAXB2 commons-lang plugin suggestion

From: Hanson Char <hanson.char_at_gmail.com>
Date: Thu, 19 Apr 2007 15:05:16 -0700

This enhancement is now available in CVS. You can now specify a fully
qualified class name for the ToStringStyle parameter. Example:

    <xjc schema="po.xsd" package="primer.po" destdir="gen-src">
      <arg value="-Xcommons-lang" />
      <arg value="-Xcommons-lang:ToStringStyle=com.x.MyCustomToStringStyle" />
      <produces dir="gen-src/primer.po" includes="**/*.java" />
    </xjc>

The only requirement is that the subclass must have a no-arg constructor.

The generated code will be something like:

    import com.x.MyCustomToStringStyle;
...
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, new
MyCustomToStringStyle());
    }

Cheers,
Hanson Char

On 4/19/07, Hanson Char <hanson.char_at_gmail.com> wrote:
> I like the first option, allowing to specify the fully qualified
> class name of a ToStringStyle subtype.
>
> Hanson Char
>
> On 4/19/07, Kenny MacLeod <kennym_at_kizoom.com> wrote:
> > Hi Hanson,
> >
> > I was using your JAXB2 commons-lang plugin again today, and I have
> > another suggested improvement, if you're interested.
> >
> > I had the need to use a custom ToStringStyle, which the plugin doesn't
> > currently support. Two possibilities suggest themselves:
> >
> > * Extend the plugin args to allow the specification of the name of a
> > ToStringStyle subtype, rather than the name of a static field of the
> > ToStringStyle class itself.
> >
> > * Implement a second toString() method on the generated code, which
> > takes as an argument a ToStringStyle instance. So this qwould give you
> > code like this:
> >
> > @Override
> > public String toString() {
> > return toString(ToStringStyle.MULTI_LINE_STYLE);
> > }
> >
> > public String toString(ToStringStyle toStringStyle) {
> > return ToStringBuilder.reflectionToString(this, toStringStyle);
> > }
> >
> > The second one is nice and flexible, and requires no classpath
> > alterations, unlike the first approach.
> >
> >
> > What do you think?
> > cheers
> > kenny
> >
>