Coverage Report - org.mule.config.spring.parsers.specific.SimpleComponentDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleComponentDefinitionParser
0%
0/23
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: SimpleComponentDefinitionParser.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.config.spring.parsers.specific;
 12  
 
 13  
 import org.mule.api.lifecycle.Disposable;
 14  
 import org.mule.api.lifecycle.Initialisable;
 15  
 import org.mule.component.DefaultJavaComponent;
 16  
 import org.mule.object.AbstractObjectFactory;
 17  
 import org.mule.object.SingletonObjectFactory;
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 23  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 24  
 import org.springframework.beans.factory.support.GenericBeanDefinition;
 25  
 import org.springframework.beans.factory.xml.ParserContext;
 26  
 import org.w3c.dom.Element;
 27  
 import org.w3c.dom.NamedNodeMap;
 28  
 import org.w3c.dom.Node;
 29  
 
 30  
 /**
 31  
  * Used to parse shortcut elements for simple built-in components such as
 32  
  * {@link org.mule.component.simple.EchoComponent} and
 33  
  * {@link org.mule.component.simple.LogComponent}. This allows shortcuts like
 34  
  * for example <i>&lt;mule:bridge-service/&gt;</i> to be used instead of having to
 35  
  * use the <i>&lt;mule:service/&gt;</i> element and specify the class name (and
 36  
  * scope) for built-in components that don't require configuration. <p/> <b>This
 37  
  * DefinitionParser should only be used for state-less components.</b> <p/> In order
 38  
  * to further customize components and use serviceFactory properties the
 39  
  * &lt;mule:service/&gt; element should be used.
 40  
  */
 41  
 public class SimpleComponentDefinitionParser extends ComponentDefinitionParser
 42  
 {
 43  0
     private static Class OBJECT_FACTORY_TYPE = SingletonObjectFactory.class;
 44  
     private Class componentInstanceClass;
 45  0
     private Map properties = new HashMap();
 46  
     
 47  
     public SimpleComponentDefinitionParser(Class component, Class componentInstanceClass)
 48  
     {
 49  0
         super(DefaultJavaComponent.class);
 50  0
         this.componentInstanceClass = componentInstanceClass;
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected void preProcess(Element element)
 55  
     {
 56  0
         super.preProcess(element);
 57  
 
 58  0
         NamedNodeMap attrs = element.getAttributes();
 59  
         
 60  0
         int numAttrs = attrs.getLength();
 61  
         Node attr;
 62  0
         for (int i = 0; i < numAttrs; ++i)
 63  
         {
 64  0
             attr = attrs.item(i);
 65  0
             properties.put(attr.getNodeName(), attr.getNodeValue());
 66  0
             attrs.removeNamedItem(attr.getNodeName());
 67  
         }
 68  0
     }
 69  
 
 70  
     protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 71  
     {
 72  
         // Create a BeanDefinition for the nested object factory and set it a
 73  
         // property value for the component
 74  0
         builder.addPropertyValue("objectFactory", getObjectFactoryDefinition(element));
 75  
 
 76  0
         super.parseChild(element, parserContext, builder);
 77  0
     }
 78  
     
 79  
     protected AbstractBeanDefinition getObjectFactoryDefinition(Element element)
 80  
     {
 81  0
         AbstractBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition();
 82  0
         objectFactoryBeanDefinition.setBeanClass(OBJECT_FACTORY_TYPE);
 83  0
         objectFactoryBeanDefinition.getPropertyValues()
 84  
             .addPropertyValue(AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS, componentInstanceClass);
 85  0
         objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("properties", properties);
 86  
 
 87  
         //Marker for MULE-4813
 88  0
         objectFactoryBeanDefinition.setInitMethodName(Initialisable.PHASE_NAME);
 89  0
         objectFactoryBeanDefinition.setDestroyMethodName(Disposable.PHASE_NAME);
 90  0
         return objectFactoryBeanDefinition;
 91  
     }
 92  
 }