1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.builders; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.umo.lifecycle.InitialisationException; |
15 | |
import org.mule.umo.transformer.UMOTransformer; |
16 | |
import org.mule.util.MuleObjectHelper; |
17 | |
|
18 | |
import org.apache.commons.beanutils.BeanUtils; |
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class TransformerReference |
30 | |
{ |
31 | |
|
32 | |
|
33 | |
|
34 | 0 | protected static final Log logger = LogFactory.getLog(TransformerReference.class); |
35 | |
|
36 | |
private final String propertyName; |
37 | |
private final String transformerName; |
38 | |
private final Object object; |
39 | |
|
40 | |
public TransformerReference(String propertyName, String transformerName, Object object) |
41 | 0 | { |
42 | 0 | this.propertyName = propertyName; |
43 | 0 | this.transformerName = transformerName; |
44 | 0 | this.object = object; |
45 | 0 | } |
46 | |
|
47 | |
public String getPropertyName() |
48 | |
{ |
49 | 0 | return propertyName; |
50 | |
} |
51 | |
|
52 | |
public String getTransformerName() |
53 | |
{ |
54 | 0 | return transformerName; |
55 | |
} |
56 | |
|
57 | |
public Object getObject() |
58 | |
{ |
59 | 0 | return object; |
60 | |
} |
61 | |
|
62 | |
public void resolveTransformer() throws InitialisationException |
63 | |
{ |
64 | 0 | UMOTransformer trans = null; |
65 | |
try |
66 | |
{ |
67 | 0 | trans = MuleObjectHelper.getTransformer(transformerName, " "); |
68 | 0 | if (trans == null) |
69 | |
{ |
70 | 0 | throw new InitialisationException( |
71 | |
CoreMessages.objectNotRegisteredWithManager("Transformer '" + transformerName + "'"), object); |
72 | |
} |
73 | 0 | logger.info("Setting transformer: " + transformerName + " on " + object.getClass().getName() |
74 | |
+ "." + propertyName); |
75 | |
|
76 | 0 | BeanUtils.setProperty(object, propertyName, trans); |
77 | |
} |
78 | 0 | catch (InitialisationException e) |
79 | |
{ |
80 | 0 | throw e; |
81 | |
} |
82 | 0 | catch (Exception e) |
83 | |
{ |
84 | 0 | throw new InitialisationException( |
85 | |
CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName, |
86 | |
object.getClass(), trans.getClass()), e); |
87 | 0 | } |
88 | 0 | } |
89 | |
} |