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;
    }
--
[EMAIL PROTECTED]                 T: +33 4 92 38 71 64
Equipe ProActive/OASIS Grid Research Team       F: +33 4 92 38 76 44
begin:vcard
fn:Ian STOKES-REES
n:STOKES-REES;Ian
org:INRIA Sophia, France;Project OASIS/ProActive
adr:;;2004 Rte Des Lucioles BP 93;Sophia Antipolis;;06902;France
email;internet:[EMAIL PROTECTED]
title:Research Scientist
tel;work:+33 4 92 38 71 64
tel;fax:+33 4 92 38 76 44
x-mozilla-html:FALSE
url:http://www-sop.inria.fr/oasis/personnel/Ian.Stokes-Rees/
version:2.1
end:vcard


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to