Coverage Report - org.mule.config.spring.parsers.specific.endpoint.support.ChildEndpointDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ChildEndpointDefinitionParser
0%
0/22
0%
0/22
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.config.spring.parsers.specific.endpoint.support;
 8  
 
 9  
 import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
 10  
 import org.mule.config.spring.parsers.generic.AutoIdUtils;
 11  
 import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
 12  
 import org.mule.util.StringUtils;
 13  
 
 14  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 15  
 import org.w3c.dom.Element;
 16  
 
 17  
 /**
 18  
  * A parser for "embedded" endpoints - ie inbound, outbound and response endpoints.
 19  
  * Because we have automatic String -> MuleEnpointURI conversion via property editors
 20  
  * this can be used in a variety of ways. It should work directly with a simple
 21  
  * String address attribute or, in combination with a child element (handled by
 22  
  * {@link ChildAddressDefinitionParser}, or embedded in
 23  
  * {@link AddressedEndpointDefinitionParser} for a more compact single-element
 24  
  * approach.
 25  
  * <p>
 26  
  * This class does support references to other endpoints.
 27  
  * </p>
 28  
  * TODO - check that references are global!
 29  
  */
 30  
 public class ChildEndpointDefinitionParser extends ChildDefinitionParser
 31  
 {
 32  
 
 33  
     public ChildEndpointDefinitionParser(Class endpoint)
 34  
     {
 35  0
         super("messageProcessor", endpoint);
 36  0
         addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF);
 37  0
         EndpointUtils.addProperties(this);
 38  0
         EndpointUtils.addPostProcess(this);
 39  0
     }
 40  
 
 41  
     @Override
 42  
     public BeanDefinitionBuilder createBeanDefinitionBuilder(Element element, Class beanClass)
 43  
     {
 44  0
         BeanDefinitionBuilder builder = super.createBeanDefinitionBuilder(element, beanClass);
 45  0
         String global = element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF);
 46  0
         if (StringUtils.isNotBlank(global))
 47  
         {
 48  0
             builder.addConstructorArgReference(global);
 49  0
             builder.addDependsOn(global);
 50  
         }
 51  0
         return builder;
 52  
     }
 53  
 
 54  
     @Override
 55  
     public String getPropertyName(Element e)
 56  
     {
 57  0
         String parent = e.getParentNode().getLocalName().toLowerCase();
 58  0
         if (e.getLocalName() != null
 59  
             && (e.getLocalName().toLowerCase().endsWith("inbound-endpoint") || e.getLocalName()
 60  
                 .toLowerCase()
 61  
                 .equals("poll")))
 62  
         {
 63  0
             return "messageSource";
 64  
         }
 65  0
         else if ("wire-tap".equals(parent) || "wire-tap-router".equals(parent))
 66  
         {
 67  0
             return "tap";
 68  
         }
 69  0
         else if ("binding".equals(parent) || "java-interface-binding".equals(parent)
 70  
                  || "publish-notifications".equals(parent) || "remote-dispatcher-agent".equals(parent))
 71  
         {
 72  0
             return "endpoint";
 73  
         }
 74  
         else
 75  
         {
 76  0
             return super.getPropertyName(e);
 77  
         }
 78  
     }
 79  
 
 80  
     @Override
 81  
     public String getBeanName(Element element)
 82  
     {
 83  0
         if (null != element.getAttributeNode(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF))
 84  
         {
 85  0
             return AutoIdUtils.uniqueValue("ref:"
 86  
                                            + element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF));
 87  
         }
 88  
         else
 89  
         {
 90  0
             return super.getBeanName(element);
 91  
         }
 92  
     }
 93  
 }