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 {
32
33 }
34
35
36
37
38
39
40
41
42 public static Object createComponent(UMODescriptor descriptor) throws UMOException
43 {
44 UMOManager manager = MuleManager.getInstance();
45 Object impl = descriptor.getImplementation();
46 Object component;
47
48 if (impl instanceof String)
49 {
50 impl = new ContainerKeyPair(null, impl);
51 }
52 if (impl instanceof ContainerKeyPair)
53 {
54 component = manager.getContainerContext().getComponent(impl);
55
56 if (descriptor.isSingleton())
57 {
58 descriptor.setImplementation(component);
59 }
60 }
61 else
62 {
63 component = impl;
64 }
65
66 try
67 {
68 BeanUtils.populate(component, descriptor.getProperties());
69 }
70 catch (Exception e)
71 {
72 throw new InitialisationException(
73 CoreMessages.failedToSetPropertiesOn("Component '" + descriptor.getName() + "'"),
74 e, descriptor);
75 }
76
77
78 if (descriptor instanceof MuleDescriptor)
79 {
80 ((MuleDescriptor) descriptor).fireInitialisationCallbacks(component);
81 }
82
83 return component;
84 }
85 }