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