users@jaxb.java.net

JAXB2 commons-lang plugin 2.1.3 released

From: Hanson Char <hanson.char_at_gmail.com>
Date: Sat, 28 Apr 2007 17:41:31 -0700

Enhancement to support custom ToStringStyle.

https://jaxb2-commons.dev.java.net/commons-lang-plugin/
https://jaxb2-commons.dev.java.net/commons-lang-plugin/release/2.1.3/jaxb-commons-lang-plugin-2.1.3.jar
https://jaxb2-commons.dev.java.net/commons-lang-plugin/release/2.1.3/jaxb-commons-lang-plugin-2.1.3-sources.jar

Cheers,
Hanson Char

On 4/19/07, Hanson Char <hanson.char_at_gmail.com> wrote:
>
> 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
> > >
> >
>