Have a read of this article:
http://www.javaworld.com/javaworld/javatips/jw-javatip76.html
It provides a class for doing deep copies of serializable objects (of
which castor objects are - i think!).
The article ends saying that it's not the fastest deep copy, but it is
very generic.
Hope that helps
Simon Lord
Ian Stokes-Rees wrote:
Hi,
Is there some easy/obvious way to make a copy of a Java object which has
been created out of an XML Schema definition? I have managed to do this
by piping marshall into unmarshall, but I need to write a method for
every object I want to copy (see example below).
Thanks,
Ian
<xs:element name="Algorithm">
<xs:complexType>
<xs:attribute name="timeIntervalsPerYear" type="xs:long"
use="required" />
<xs:attribute name="type" type="xs:string" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="EuropeanSimple"/>
<xs:enumeration value="EuropeanBarrier"/>
<xs:enumeration value="EuropeanBasket"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="iterations" type="xs:double" use="required" />
<xs:attribute name="queuedIts" type="xs:double" use="optional" />
</xs:complexType>
</xs:element>
<Algorithm
type="EuropeanSimple"
timeIntervalsPerYear="50"
iterations="1e5"
/>
static public Algorithm copyAlgorithm(Algorithm alg) {
Algorithm new_alg = new Algorithm();
try {
PipedReader reader = new PipedReader();
PipedWriter writer = new PipedWriter(reader);
alg.marshal(writer);
writer.close();
new_alg = (Algorithm)Unmarshaller.unmarshal(Algorithm.class,
reader);
} catch (Exception ex) {
log.error("Could not copy object");
ex.printStackTrace();
}
return new_alg;
}
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email