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  
  * $Id: StaticComponentDefinitionParser.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  
 package org.mule.config.spring.parsers.specific;
 11  
 
 12  
 import org.mule.component.DefaultJavaComponent;
 13  
 import org.mule.component.simple.StaticComponent;
 14  
 import org.mule.util.IOUtils;
 15  
 import org.mule.util.StringUtils;
 16  
 
 17  
 import java.io.IOException;
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.springframework.beans.factory.BeanCreationException;
 22  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 23  
 import org.w3c.dom.Element;
 24  
 import org.w3c.dom.NodeList;
 25  
 
 26  
 /**
 27  
  * BDP which parses the <return-data> element of the <static-component>.
 28  
  */
 29  
 public class StaticComponentDefinitionParser extends SimpleComponentDefinitionParser
 30  
 {
 31  
     public StaticComponentDefinitionParser()
 32  
     {
 33  0
         super(DefaultJavaComponent.class, StaticComponent.class);
 34  0
     }
 35  
 
 36  
     @Override
 37  
     protected AbstractBeanDefinition getObjectFactoryDefinition(Element element)
 38  
     {
 39  0
         AbstractBeanDefinition objectFactoryBeanDefinition = super.getObjectFactoryDefinition(element);
 40  
         
 41  0
         String returnData = null;
 42  
 
 43  0
         NodeList list = element.getChildNodes();
 44  0
         for (int i = 0; i < list.getLength(); i++)
 45  
         {
 46  0
             if ("return-data".equals(list.item(i).getLocalName()))
 47  
             {
 48  0
                 Element rData = (Element) list.item(i);
 49  0
                 if (StringUtils.isNotEmpty(rData.getAttribute("file")))
 50  
                 {
 51  0
                     String file = rData.getAttribute("file");
 52  
                     try
 53  
                     {
 54  0
                         returnData = IOUtils.getResourceAsString(file, getClass());
 55  
                     }
 56  0
                     catch (IOException e)
 57  
                     {
 58  0
                         throw new BeanCreationException("Failed to load test-data resource: " + file, e);
 59  0
                     }
 60  0
                 }
 61  
                 else
 62  
                 {
 63  0
                     returnData = rData.getTextContent();
 64  
                 }
 65  
             }
 66  
         }
 67  
 
 68  0
         if (returnData != null)
 69  
         {
 70  0
             Map props = new HashMap();
 71  0
             props.put("data", returnData);
 72  0
             objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("properties", props);
 73  
         }
 74  
         
 75  0
         return objectFactoryBeanDefinition;
 76  
     }
 77  
 }