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