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