1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.model; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.impl.MuleDescriptor; |
16 | |
import org.mule.impl.container.ContainerKeyPair; |
17 | |
import org.mule.umo.UMODescriptor; |
18 | |
import org.mule.umo.UMOException; |
19 | |
import org.mule.umo.lifecycle.InitialisationException; |
20 | |
import org.mule.umo.manager.UMOManager; |
21 | |
import org.mule.util.BeanUtils; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public final class ComponentFactory |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
private ComponentFactory () |
31 | 0 | { |
32 | |
|
33 | 0 | } |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public static Object createComponent(UMODescriptor descriptor) throws UMOException |
43 | |
{ |
44 | 80 | UMOManager manager = MuleManager.getInstance(); |
45 | 80 | Object impl = descriptor.getImplementation(); |
46 | |
Object component; |
47 | |
|
48 | 80 | if (impl instanceof String) |
49 | |
{ |
50 | 0 | impl = new ContainerKeyPair(null, impl); |
51 | |
} |
52 | 80 | if (impl instanceof ContainerKeyPair) |
53 | |
{ |
54 | 70 | component = manager.getContainerContext().getComponent(impl); |
55 | |
|
56 | 70 | if (descriptor.isSingleton()) |
57 | |
{ |
58 | 0 | descriptor.setImplementation(component); |
59 | |
} |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 10 | component = impl; |
64 | |
} |
65 | |
|
66 | |
try |
67 | |
{ |
68 | 80 | BeanUtils.populate(component, descriptor.getProperties()); |
69 | |
} |
70 | 0 | catch (Exception e) |
71 | |
{ |
72 | 0 | throw new InitialisationException( |
73 | |
CoreMessages.failedToSetPropertiesOn("Component '" + descriptor.getName() + "'"), |
74 | |
e, descriptor); |
75 | 80 | } |
76 | |
|
77 | |
|
78 | 80 | if (descriptor instanceof MuleDescriptor) |
79 | |
{ |
80 | 80 | ((MuleDescriptor) descriptor).fireInitialisationCallbacks(component); |
81 | |
} |
82 | |
|
83 | 80 | return component; |
84 | |
} |
85 | |
} |