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