Coverage Report - org.mule.config.spring.parsers.collection.OrphanMapDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
OrphanMapDefinitionParser
0%
0/27
0%
0/4
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.collection;
 8  
 
 9  
 import org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate;
 10  
 import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
 11  
 
 12  
 import java.util.Map;
 13  
 
 14  
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 15  
 import org.springframework.beans.factory.config.MapFactoryBean;
 16  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 17  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 18  
 import org.springframework.beans.factory.xml.ParserContext;
 19  
 import org.w3c.dom.Element;
 20  
 
 21  
 /**
 22  
  * Creates a single, stand-alone map object and processes standard Spring sub elements
 23  
  */
 24  
 public class OrphanMapDefinitionParser extends AbstractMuleBeanDefinitionParser
 25  
 {
 26  
     protected Class mapClass;
 27  
     protected String name;
 28  
     protected boolean attributeName;
 29  0
     protected boolean dynamicName = false;
 30  
 
 31  
     /**
 32  
      * Creates a Map parser that will add the map directly to the registry
 33  
      *
 34  
      * @param mapClass the type of map to create
 35  
      */
 36  
     public OrphanMapDefinitionParser(Class mapClass)
 37  0
     {
 38  0
         this.mapClass = mapClass;
 39  0
         dynamicName = true;
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Creates a Map parser that will add the map directly to the registry
 44  
      *
 45  
      * @param mapClass the type of map to create
 46  
      * @param name the name of the map property
 47  
      */
 48  
     public OrphanMapDefinitionParser(Class mapClass, String name)
 49  0
     {
 50  0
         this.mapClass = mapClass;
 51  0
         this.name = name;
 52  0
     }
 53  
 
 54  
     /**
 55  
      * Creates a Map parser that will add the map directly to the registry
 56  
      *
 57  
      * @param mapClass the type of map to create
 58  
      * @param name the name of the map property
 59  
      * @param attributeName whether the name specified is actually an attribute name on the element.  The map name will
 60  
      * be retrieved from the element attribute.
 61  
      */
 62  
     public OrphanMapDefinitionParser(Class mapClass, String name, boolean attributeName)
 63  0
     {
 64  0
         this.mapClass = mapClass;
 65  0
         this.name = name;
 66  0
         this.attributeName = attributeName;
 67  0
     }
 68  
 
 69  
     protected Class getBeanClass(Element element)
 70  
     {
 71  0
         return MapFactoryBean.class;
 72  
     }
 73  
 
 74  
     protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 75  
     {
 76  0
         Map parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
 77  0
         builder.addPropertyValue("sourceMap", parsedMap);
 78  0
         builder.addPropertyValue("targetMapClass", mapClass.getName());
 79  0
         getBeanAssembler(element, builder).setBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE);
 80  0
     }
 81  
 
 82  
     @Override
 83  
 
 84  
     protected void preProcess(Element element)
 85  
     {
 86  0
         super.preProcess(element);
 87  0
         if (dynamicName)
 88  
         {
 89  0
             name = null;
 90  
         }
 91  0
     }
 92  
     
 93  
     @java.lang.Override
 94  
     protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException
 95  
     {
 96  0
         if(attributeName)
 97  
         {
 98  0
             return element.getAttribute(name);
 99  
         }
 100  0
         return name;
 101  
     }
 102  
 }