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 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 {
49 this.propertyName = propertyName;
50 this.containerRef = containerRef;
51 this.container = container;
52 this.object = object;
53 this.required = required;
54 }
55
56 public void resolveReference(UMOContainerContext ctx) throws ContainerException
57 {
58 Object comp = ctx.getComponent(new ContainerKeyPair(container, containerRef, required));
59 if (comp == null)
60 {
61 return;
62 }
63
64 try
65 {
66 if (object instanceof Map)
67 {
68 ((Map) object).put(propertyName, comp);
69 }
70 else if (object instanceof List)
71 {
72 ((List) object).add(comp);
73 }
74 else
75 {
76 BeanUtils.setProperty(object, propertyName, comp);
77 }
78 }
79 catch (Exception e)
80 {
81 throw new ContainerException(
82 CoreMessages.cannotSetPropertyOnObjectWithParamType(propertyName,
83 object.getClass(), comp.getClass()), e);
84 }
85 }
86 }