* @version $Revision$
*****************************************************************************/
-package org.splat.util;
+package org.splat.util;
import net.sf.beanlib.provider.BeanTransformer;
import net.sf.beanlib.provider.replicator.BeanReplicator;
-import net.sf.beanlib.spi.BeanTransformerSpi;
-
/**
- * Helper class for beans.
- * This class supplies :
- * - methods to copy bean to an other bean
+ * Helper class for beans. This class supplies : - methods to copy bean to an other bean
+ *
* @author Maria KRUCHININA
- *
+ *
*/
public final class BeanHelper {
-
+
/**
* private constructor to make it abstract.
*/
- private BeanHelper(){
+ private BeanHelper() {
super();
}
-
+
/**
* copy a bean to a bean.
- * @param <T> the original type
- * @param <D> the target type
- * @param from the original bean
- * @param clazz the destination class
+ *
+ * @param <T>
+ * the original type
+ * @param <D>
+ * the target type
+ * @param from
+ * the original bean
+ * @param clazz
+ * the destination class
* @return an instance of the destination class
*/
- public static <T,D>D copyBean(final T from,final Class <D> clazz) {
+ public static <T, D> D copyBean(final T from, final Class<D> clazz) {
D result;
-
- if(from == null) {
+
+ if (from == null) {
result = null;
} else {
- BeanTransformerSpi transformer = new BeanTransformer(new TimestampTransformerFactory());
- BeanReplicator bp = new BeanReplicator(transformer);
-
+ BeanTransformer bt = new BeanTransformer(
+ new TimestampTransformerFactory(),
+ new DTOTransformerFactory());
+ // Don't check parameter types of getters and setters.
+ // Find them just by property name.
+ bt.initDetailedPropertyFilter(null);
+
+ BeanReplicator bp = new BeanReplicator(bt);
result = bp.replicateBean(from, clazz);
}
return result;