1 10 11 package org.mule.util.properties; 12 13 import org.mule.umo.UMOMessage; 14 import org.mule.util.StringUtils; 15 import org.apache.commons.beanutils.PropertyUtils; 16 import org.apache.commons.logging.LogFactory; 17 import org.apache.commons.logging.Log; 18 19 import java.lang.reflect.InvocationTargetException ; 20 21 24 public class PayloadPropertyExtractor implements PropertyExtractor 25 { 26 29 protected transient Log logger = LogFactory.getLog(getClass()); 30 31 public Object getProperty(String name, Object message) 32 { 33 Object payload = message; 34 if (message instanceof UMOMessage) 35 { 36 payload = ((UMOMessage)message).getPayload(); 37 } 38 Object value = null; 39 try 40 { 41 if ((PropertyUtils.getPropertyDescriptor(payload, name) != null)) 42 { 43 value = PropertyUtils.getProperty(payload, name); 44 if (value == null) 45 { 46 value = StringUtils.EMPTY; 47 } 48 } 49 } 50 catch (IllegalAccessException e) 51 { 52 logger.warn("Failed to read property: " + name, e); 53 } 54 catch (InvocationTargetException e) 55 { 56 logger.warn("Failed to read property: " + name, e); 57 } 58 catch (NoSuchMethodException e) 59 { 60 } 62 return value; 63 } 64 } 65 | Popular Tags |