Aleksei Valikov wrote:
> Hi.
>
>
>>>> In my app I have a JAXB generated binding object instance. The instance
>>>> may be modified via "edit" actions. The modifications may be saved via
>>>> "save" action or discarded via "discard" action. I am looking for some
>>>> way to restore the original state of the JAXB generated binding object
>>>> from a snapshot of its original state. What would be terrific is if
>>>> there was some way to unmarshal previously marshalled state to an
>>>> existing object instance. This would allow me to restore the state on
>>>> discard.
>>>>
>>>> Is there any way to do this? If not, how have others solved similar
>>>> design issue? TIA for your help.
>>>>
>>>>
>>> Take a look at "copyable" plugin from jaxb2-commons. You can
>>> unmarshall an object an copy its state into another object. You may
>>> also provide an own "copy builder" which could, for instance, resolve
>>> conflicts while copying.
>>>
>>>
>>>
>> The "copyable" plugin from jaxb2-commons is just what I needed. Thank Lexi.
>> BTW the plugin is not documented at jaxb2-commons.dev.java.net.
>>
>> Lastly, when using the plugin I ran into some case of compile errors like:
>>
>> ValueType.java:94: org.xxx.ValueType is abstract; cannot be instantiated
>> final ValueType copy = ((target == null)?new
>> ValueType():((ValueType) target));
>>
>> The schema was defined as follows:
>>
>> <complexType name="ValueType" abstract="true">
>>
>> Is this a known issue ir shall I file a new issue report?
>>
>
> No, not known before, please file. I this a IllegalArgumentException
> should be thrown in this case
>
Issue 122 filed:
https://hyperjaxb3.dev.java.net/issues/show_bug.cgi?id=122
I realize now its probably on the wrong project. Will be more careful
next time.
I then did a workaround in my schema to remove abstract="true"
attributes in type defs.
This got me to generate compilable bindings.
I then proceeded to use the bindings. They solved my problem very
nicely. Thanks.
However, on some objects when I use the copyTo method I get the
following stack trace:
Unable to create a copy.
org.jvnet.jaxb2_commons.lang.builder.CopyBuilder.copy(CopyBuilder.java:27)
org.jvnet.jaxb2_commons.lang.builder.JAXBCopyBuilder.copy(JAXBCopyBuilder.java:36)
org.freebxml.omar.jaxb.bindings.rim._4_0.RegistryType.copyTo(RegistryType.java:275)
So far, I have identified that the following types are not supported as
targets of copyTo method:
javax.xml.datatype.Duration.
java.lang.Boolean
Here is an example of generated code that runs into trouble:
//From QueryExpressionType
{
Boolean sourceRequired;
sourceRequired = this.isRequired();
Boolean copyRequired = ((Boolean)
copyBuilder.copy(sourceRequired));
copy.setRequired(copyRequired);
}
//From FederationType and RegistryType
{
Duration sourceReplicationSyncLatency;
sourceReplicationSyncLatency = this.getReplicationSyncLatency();
Duration copyReplicationSyncLatency = ((Duration)
copyBuilder.copy(sourceReplicationSyncLatency));
copy.setReplicationSyncLatency(copyReplicationSyncLatency);
}
Shall I file a new issue? Also which project should I create the issue
on? Thanks for your terrific help.
--
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com