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