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.impl.container.ContainerKeyPair; |
15 | |
import org.mule.umo.manager.ContainerException; |
16 | |
import org.mule.umo.manager.UMOContainerContext; |
17 | |
|
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.apache.commons.beanutils.BeanUtils; |
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class ContainerReference |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | 0 | protected static final Log logger = LogFactory.getLog(ContainerReference.class); |
36 | |
|
37 | |
private String propertyName; |
38 | |
private String containerRef; |
39 | |
private String container; |
40 | |
private Object object; |
41 | |
private boolean required; |
42 | |
|
43 | |
public ContainerReference(String propertyName, |
44 | |
String containerRef, |
45 | |
Object object, |
46 | |
boolean required, |
47 | |
String container) |
48 | 0 | { |
49 | 0 | this.propertyName = propertyName; |
50 | 0 | this.containerRef = containerRef; |
51 | 0 | this.container = container; |
52 | 0 | this.object = object; |
53 | 0 | this.required = required; |
54 | 0 | } |
55 | |
|
56 | |
public void resolveReference(UMOContainerContext ctx) throws ContainerException |
57 | |
{ |
58 | 0 | Object comp = ctx.getComponent(new ContainerKeyPair(container, containerRef, required)); |
59 | 0 | if (comp == null) |
60 | |
{ |
61 | 0 | return; |
62 | |
} |
63 | |
|
64 | |
try |
65 | |
{ |
66 | 0 | if (object instanceof Map) |
67 | |
{ |
68 | 0 | ((Map) object).put(propertyName, comp); |
69 | |
} |
70 | 0 | else if (object instanceof List) |
71 | |
{ |
72 | 0 | ((List) object).add(comp); |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | 0 | BeanUtils.setProperty(object, propertyName, comp); |
77 | |
} |
78 | |
} |
79 | 0 | catch (Exception e) |
80 | |
{ |
81 | 0 | throw new ContainerException( |
82 | |
CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName, |
83 | |
object.getClass(), comp.getClass()), e); |
84 | 0 | } |
85 | 0 | } |
86 | |
} |