Coverage Report - org.mule.config.spring.parsers.generic.NamedDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
NamedDefinitionParser
0%
0/21
0%
0/4
1.429
 
 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.generic;
 8  
 
 9  
 import org.mule.config.spring.parsers.assembly.BeanAssembler;
 10  
 
 11  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 12  
 import org.springframework.beans.factory.xml.ParserContext;
 13  
 import org.w3c.dom.Element;
 14  
 
 15  
 /**
 16  
  * Behaves as {@link org.mule.config.spring.parsers.generic.ParentDefinitionParser},
 17  
  * but allows any named bean to be the parent, rather than using the enclosing element in the DOM tree.
 18  
  */
 19  
 public class NamedDefinitionParser extends ParentDefinitionParser
 20  
 {
 21  
 
 22  
     private String name;
 23  0
     private boolean isDynamic = false;
 24  
 
 25  
     public NamedDefinitionParser()
 26  0
     {
 27  0
         isDynamic = true;
 28  0
     }
 29  
 
 30  
     public NamedDefinitionParser(String name)
 31  0
     {
 32  0
         addIgnored(ATTRIBUTE_NAME);
 33  0
         this.name = name;
 34  0
     }
 35  
 
 36  
     public String getName()
 37  
     {
 38  0
         return name;
 39  
     }
 40  
 
 41  
     public void setName(String name)
 42  
     {
 43  0
         this.name = name;
 44  0
     }
 45  
 
 46  
     protected String getParentBeanName(Element element)
 47  
     {
 48  0
         return name;
 49  
     }
 50  
 
 51  
     protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
 52  
     {
 53  0
         if (isDynamic)
 54  
         {
 55  0
             if (element.hasAttribute(ATTRIBUTE_NAME))
 56  
             {
 57  0
                 setName(element.getAttribute(ATTRIBUTE_NAME));
 58  0
                 element.removeAttribute(ATTRIBUTE_NAME);
 59  
             }
 60  
             else
 61  
             {
 62  0
                 throw new IllegalStateException("Missing name attribute for " + element.getLocalName());
 63  
             }
 64  
         }
 65  0
         return super.parseInternal(element, parserContext);
 66  
     }
 67  
 
 68  
     protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
 69  
     {
 70  0
         super.postProcess(context, assembler, element);
 71  
         // may be used as top level element, so set ID from name
 72  0
         AutoIdUtils.ensureUniqueId(element, "named");
 73  0
     }
 74  
 }