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