Coverage Report - org.mule.module.xml.config.NamespaceManagerDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
NamespaceManagerDefinitionParser
0%
0/16
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: NamespaceManagerDefinitionParser.java 20321 2010-11-24 15:21:24Z dfeist $
 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.module.xml.config;
 11  
 
 12  
 import org.mule.api.config.MuleProperties;
 13  
 import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
 14  
 import org.mule.config.spring.parsers.generic.OrphanDefinitionParser;
 15  
 import org.mule.module.xml.util.NamespaceManager;
 16  
 
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 21  
 import org.springframework.beans.factory.xml.ParserContext;
 22  
 import org.w3c.dom.Element;
 23  
 import org.w3c.dom.Node;
 24  
 
 25  
 /**
 26  
  * TODO
 27  
  */
 28  
 public class NamespaceManagerDefinitionParser extends OrphanDefinitionParser
 29  
 {
 30  
     public NamespaceManagerDefinitionParser()
 31  
     {
 32  0
         super(NamespaceManager.class, true);
 33  0
     }
 34  
 
 35  
     /**
 36  
      * Parse the supplied {@link org.w3c.dom.Element} and populate the supplied
 37  
      * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} as required.
 38  
      * <p>The default implementation delegates to the <code>doParse</code>
 39  
      * version without ParserContext argument.
 40  
      *
 41  
      * @param element       the XML element being parsed
 42  
      * @param parserContext the object encapsulating the current state of the parsing process
 43  
      * @param builder       used to define the <code>BeanDefinition</code>
 44  
      */
 45  
     @Override
 46  
     protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 47  
     {
 48  0
         Map<String, String> ns = new HashMap<String, String>();
 49  
 
 50  0
         for (int i = 0; i < element.getParentNode().getAttributes().getLength(); i++)
 51  
         {
 52  0
             Node node = element.getParentNode().getAttributes().item(i);
 53  0
             String prefix = node.getNodeName();
 54  0
             if (prefix.startsWith("xmlns"))
 55  
             {
 56  0
                 if (prefix.indexOf(":") > 0)
 57  
                 {
 58  0
                     prefix = prefix.substring(prefix.indexOf(":") + 1);
 59  
                 }
 60  
                 else
 61  
                 {
 62  0
                     prefix = "";
 63  
                 }
 64  0
                 ns.put(prefix, node.getNodeValue());
 65  
             }
 66  
         }
 67  0
         builder.addPropertyValue("configNamespaces", ns);
 68  
 
 69  
         // this id must match the bean name
 70  0
         element.setAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_ID, MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER);
 71  
 
 72  0
         super.doParse(element, parserContext, builder);
 73  0
     }
 74  
 
 75  
     @Override
 76  
     public String getBeanName(Element element)
 77  
     {
 78  0
         return MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER;
 79  
     }
 80  
 }