Salome HOME
167d41701ea497b8d1b2a3ecddce42a8dc5359d3
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / util / BeanHelper.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   05.10.2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package org.splat.util; 
11
12 import net.sf.beanlib.provider.BeanTransformer;
13 import net.sf.beanlib.provider.replicator.BeanReplicator;
14 import net.sf.beanlib.spi.BeanTransformerSpi;
15
16
17 /**
18  * Helper class for beans.
19  * This class supplies :
20  *              - methods to copy bean to an other bean
21  * @author Maria KRUCHININA
22  *
23  */
24 public final class BeanHelper {
25         
26         /**
27          * private constructor to make it abstract.
28          */
29         private BeanHelper(){
30                 super();
31         }
32         
33         /**
34          * copy a bean to a bean.
35          * @param <T> the original type
36          * @param <D> the target type
37          * @param from the original bean
38          * @param clazz the destination class
39          * @return an instance of the destination class
40          */
41         public static <T,D>D copyBean(final T from,final Class <D> clazz) {
42                 D result;
43                 
44                 if(from == null) {
45                         result = null;
46                 } else {
47                         BeanTransformerSpi transformer = new BeanTransformer(new TimestampTransformerFactory());
48                         BeanReplicator bp = new BeanReplicator(transformer);
49
50                         result = bp.replicateBean(from, clazz);
51                 }
52                 return result;
53         }
54
55 }