Coverage Report - org.mule.config.spring.parsers.collection.AttributeMapDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributeMapDefinitionParser
0%
0/17
0%
0/4
1.667
 
 1  
 /*
 2  
  * $Id: AttributeMapDefinitionParser.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.collection;
 11  
 
 12  
 import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
 13  
 import org.mule.config.spring.util.SpringXMLUtils;
 14  
 
 15  
 import org.springframework.beans.factory.config.MapFactoryBean;
 16  
 import org.springframework.beans.factory.config.RuntimeBeanReference;
 17  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 18  
 import org.springframework.beans.factory.support.ManagedMap;
 19  
 import org.springframework.beans.factory.xml.ParserContext;
 20  
 import org.w3c.dom.Attr;
 21  
 import org.w3c.dom.Element;
 22  
 import org.w3c.dom.NamedNodeMap;
 23  
 
 24  
 /**
 25  
  * Creates a single, stand-alone map object and processes all attributes to this map
 26  
  */
 27  
 public class AttributeMapDefinitionParser extends ChildDefinitionParser
 28  
 {
 29  
     public AttributeMapDefinitionParser(String setter)
 30  
     {
 31  0
         super(setter, ManagedMap.class);
 32  0
     }
 33  
 
 34  
     protected Class getBeanClass(Element element)
 35  
     {
 36  0
         return MapFactoryBean.class;
 37  
     }
 38  
 
 39  
     protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 40  
     {
 41  0
         ManagedMap values = new ManagedMap();
 42  0
         NamedNodeMap attributes = element.getAttributes();
 43  0
         for (int x = 0; x < attributes.getLength(); x++)
 44  
         {
 45  0
             Attr attribute = (Attr) attributes.item(x);
 46  0
             String oldName = SpringXMLUtils.attributeName(attribute);
 47  
             //TODO How can I use bestGuessName
 48  0
             String name = beanPropertyConfiguration.translateName(oldName);
 49  0
             Object value = beanPropertyConfiguration.translateValue(oldName, attribute.getNodeValue());
 50  0
             if (beanPropertyConfiguration.isReference(oldName))
 51  
             {
 52  0
                 values.put(name, new RuntimeBeanReference(attribute.getNodeValue()));
 53  
             }
 54  
             else
 55  
             {
 56  0
                 values.put(name, value);
 57  
             }
 58  
         }
 59  0
         builder.addPropertyValue("sourceMap", values);
 60  0
         builder.addPropertyValue("targetMapClass", super.getBeanClass(element));
 61  0
         postProcess(parserContext, getBeanAssembler(element, builder), element);
 62  0
     }
 63  
 
 64  
 }