users@jaxb.java.net

Re: [HJ3] How can i transfer the extendedCloneable plugin from HJ2 to HJ3?

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Mon, 29 Jan 2007 10:08:55 +0100

Hi Kostis,

I was away for few days, so sorry for not answering in time.

> Would it be possible for you to help me upgrade the extendedCloneable
> jaxbcommons plugin into xjc2?

I have implemented the "copyable" plugin in jaxb2-commons/basic. It produces two
copyTo methods:

public Object copyTo(Object target, CopyBuilder copyBuilder)
{
        ....
}

public Object copyTo(Object target)
{
        final CopyBuilder copyBuilder = new JAXBCopyBuilder();
        return copyTo(target, copyBuilder);
}

The second method simply calls the first one with a certain copyBuilder. Class
of the copyBuilder is configurable within the plugin. This copyBuilder is the
object responsible for the copying strategy. Currently, JAXBCopyBuilder makes
trivial deep copying (no cycles detection or checks if the object was already
copied etc.).
For the functionality similar to "extendedCloneable" you'll simply need to
implement an appropriate copy builder and configure it withing the plugin when
you invoke it. Or we can add there some kind of a switch or whatever.

ps. There are also hashCode, equals and toString plugins implemented in a
similar manner: the function strategy is extracted into a special "builder",
which can be provided externally. If it's not provided, a default JAXB-aware
implementation of this builder is used.

Bye.
/lexi