1 10 11 package org.mule.util; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 import java.util.Iterator ; 17 import java.util.Map ; 18 19 23 public class BeanUtils extends org.apache.commons.beanutils.BeanUtils 25 { 26 public static final String SET_PROPERTIES_METHOD = "setProperties"; 27 28 31 private static final Log logger = LogFactory.getLog(BeanUtils.class); 32 33 36 public static void populateWithoutFail(Object object, Map props, boolean logWarnings) 37 { 38 if (ClassUtils.getMethod(SET_PROPERTIES_METHOD, new Class []{Map .class}, object.getClass()) != null) 41 { 42 try 43 { 44 BeanUtils.setProperty(object, "properties", props); 45 } 46 catch (Exception e) 47 { 48 if (logWarnings) 51 { 52 logger.warn("Property: " + SET_PROPERTIES_METHOD + "=" + Map .class.getName() 53 + " not found on object: " + object.getClass().getName()); 54 } 55 } 56 } 57 else 58 { 59 for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) 60 { 61 Map.Entry entry = (Map.Entry )iterator.next(); 62 63 try 64 { 65 BeanUtils.setProperty(object, entry.getKey().toString(), entry.getValue()); 66 } 67 catch (Exception e) 68 { 69 if (logWarnings) 70 { 71 logger.warn("Property: " + entry.getKey() + "=" + entry.getValue() 72 + " not found on object: " + object.getClass().getName()); 73 } 74 } 75 } 76 } 77 } 78 79 } 80 | Popular Tags |