Salome HOME
KnowledgeElementDTO is now used in KnowledgeElementFacade. Edit and rename knowledge...
[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
15 /**
16  * Helper class for beans. This class supplies : - methods to copy bean to an other bean
17  * 
18  * @author Maria KRUCHININA
19  * 
20  */
21 public final class BeanHelper {
22
23         /**
24          * private constructor to make it abstract.
25          */
26         private BeanHelper() {
27                 super();
28         }
29
30         /**
31          * copy a bean to a bean.
32          * 
33          * @param <T>
34          *            the original type
35          * @param <D>
36          *            the target type
37          * @param from
38          *            the original bean
39          * @param clazz
40          *            the destination class
41          * @return an instance of the destination class
42          */
43         public static <T, D> D copyBean(final T from, final Class<D> clazz) {
44                 D result;
45
46                 if (from == null) {
47                         result = null;
48                 } else {
49                         BeanTransformer bt = new BeanTransformer(
50                                         new TimestampTransformerFactory(),
51                                         new DTOTransformerFactory());
52                         // Don't check parameter types of getters and setters. 
53                         // Find them just by property name.
54                         bt.initDetailedPropertyFilter(null);
55                         
56                         BeanReplicator bp = new BeanReplicator(bt);
57                         result = bp.replicateBean(from, clazz);
58                 }
59                 return result;
60         }
61
62 }