Coverage Report - org.mule.impl.model.ComponentFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentFactory
67%
12/18
62%
5/8
4
 
 1  
 /*
 2  
  * $Id: ComponentFactory.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * Reusable methods for working with UMOComponents.
 25  
  */
 26  
 public final class ComponentFactory
 27  
 {
 28  
 
 29  
     /** Do not instanciate. */
 30  
     private ComponentFactory ()
 31  0
     {
 32  
         // no-op
 33  0
     }
 34  
 
 35  
     /**
 36  
      * Creates a component based on its descriptor.
 37  
      * 
 38  
      * @param descriptor the descriptor to create the component from
 39  
      * @return The newly created component
 40  
      * @throws UMOException
 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  
         // Call any custom initialisers
 78  80
         if (descriptor instanceof MuleDescriptor)
 79  
         {
 80  80
             ((MuleDescriptor) descriptor).fireInitialisationCallbacks(component);
 81  
         }
 82  
 
 83  80
         return component;
 84  
     }
 85  
 }