1 package fr.in2p3.jsaga.helpers.cloner;
2
3 import org.exolab.castor.xml.Marshaller;
4 import org.exolab.castor.xml.Unmarshaller;
5 import org.w3c.dom.Document;
6
7 import javax.xml.parsers.DocumentBuilderFactory;
8 import java.io.Serializable;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class BeanCloner {
23
24
25
26
27
28 public Serializable cloneBean(Serializable source) throws CloneNotSupportedException {
29 try {
30 Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
31 Marshaller.marshal(source, doc);
32 return (Serializable) Unmarshaller.unmarshal(source.getClass(), doc);
33 } catch (Exception e) {
34 throw new CloneNotSupportedException(e.getMessage());
35 }
36 }
37 }