1 3 package jodd.bean; 4 5 import jodd.introspector.ClassDescriptor; 6 import jodd.introspector.DefaultIntrospector; 7 8 11 public class BeanCopy { 12 13 15 23 public static void copyProperties(Object source, Object destination, boolean supressSecurity) { 24 ClassDescriptor cdSrc = DefaultIntrospector.lookup(source.getClass()); 25 ClassDescriptor cdDest = DefaultIntrospector.lookup(destination.getClass()); 26 27 String [] mdata = cdSrc.getAllBeanGetterNames(supressSecurity); 28 for (int i = 0; i < mdata.length; i++) { 29 String name = mdata[i]; 30 31 if (cdDest.getBeanSetter(name, supressSecurity) == null) { 32 return; 33 } 34 try { 35 Object value = BeanUtil.getProperty(source, name); 36 BeanUtil.setProperty(destination, name, value); 37 } catch (BeanException bex) { 38 } 40 } 41 } 42 43 49 public static void copyProperties(Object source, Object destination) { 50 copyProperties(source, destination, false); 51 } 52 } 53 | Popular Tags |