Coverage Report - org.mule.config.spring.parsers.specific.StaticComponentDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
StaticComponentDefinitionParser
0%
0/21
0%
0/8
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.spring.parsers.specific;
 8  
 
 9  
 import org.mule.component.DefaultJavaComponent;
 10  
 import org.mule.component.simple.StaticComponent;
 11  
 import org.mule.util.IOUtils;
 12  
 import org.mule.util.StringUtils;
 13  
 
 14  
 import java.io.IOException;
 15  
 import java.util.HashMap;
 16  
 import java.util.Map;
 17  
 
 18  
 import org.springframework.beans.factory.BeanCreationException;
 19  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 20  
 import org.w3c.dom.Element;
 21  
 import org.w3c.dom.NodeList;
 22  
 
 23  
 /**
 24  
  * BDP which parses the <return-data> element of the <static-component>.
 25  
  */
 26  
 public class StaticComponentDefinitionParser extends SimpleComponentDefinitionParser
 27  
 {
 28  
     public StaticComponentDefinitionParser()
 29  
     {
 30  0
         super(DefaultJavaComponent.class, StaticComponent.class);
 31  0
     }
 32  
 
 33  
     @Override
 34  
     protected AbstractBeanDefinition getObjectFactoryDefinition(Element element)
 35  
     {
 36  0
         AbstractBeanDefinition objectFactoryBeanDefinition = super.getObjectFactoryDefinition(element);
 37  
         
 38  0
         String returnData = null;
 39  
 
 40  0
         NodeList list = element.getChildNodes();
 41  0
         for (int i = 0; i < list.getLength(); i++)
 42  
         {
 43  0
             if ("return-data".equals(list.item(i).getLocalName()))
 44  
             {
 45  0
                 Element rData = (Element) list.item(i);
 46  0
                 if (StringUtils.isNotEmpty(rData.getAttribute("file")))
 47  
                 {
 48  0
                     String file = rData.getAttribute("file");
 49  
                     try
 50  
                     {
 51  0
                         returnData = IOUtils.getResourceAsString(file, getClass());
 52  
                     }
 53  0
                     catch (IOException e)
 54  
                     {
 55  0
                         throw new BeanCreationException("Failed to load test-data resource: " + file, e);
 56  0
                     }
 57  0
                 }
 58  
                 else
 59  
                 {
 60  0
                     returnData = rData.getTextContent();
 61  
                 }
 62  
             }
 63  
         }
 64  
 
 65  0
         if (returnData != null)
 66  
         {
 67  0
             Map props = new HashMap();
 68  0
             props.put("data", returnData);
 69  0
             objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("properties", props);
 70  
         }
 71  
         
 72  0
         return objectFactoryBeanDefinition;
 73  
     }
 74  
 }