Coverage Report - org.mule.config.spring.handlers.AbstractMuleNamespaceHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractMuleNamespaceHandler
0%
0/19
0%
0/2
1.5
AbstractMuleNamespaceHandler$IgnoredDefinitionParser
0%
0/3
N/A
1.5
AbstractMuleNamespaceHandler$RegisteredMdps
0%
0/44
0%
0/24
1.5
 
 1  
 /*
 2  
  * $Id: AbstractMuleNamespaceHandler.java 20381 2010-11-29 19:35:30Z tcarlson $
 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.config.spring.handlers;
 11  
 
 12  
 import org.mule.config.spring.factories.InboundEndpointFactoryBean;
 13  
 import org.mule.config.spring.factories.OutboundEndpointFactoryBean;
 14  
 import org.mule.config.spring.parsers.MuleDefinitionParser;
 15  
 import org.mule.config.spring.parsers.MuleDefinitionParserConfiguration;
 16  
 import org.mule.config.spring.parsers.PostProcessor;
 17  
 import org.mule.config.spring.parsers.PreProcessor;
 18  
 import org.mule.config.spring.parsers.assembly.configuration.ValueMap;
 19  
 import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser;
 20  
 import org.mule.config.spring.parsers.specific.endpoint.TransportEndpointDefinitionParser;
 21  
 import org.mule.config.spring.parsers.specific.endpoint.TransportGlobalEndpointDefinitionParser;
 22  
 import org.mule.config.spring.parsers.specific.endpoint.support.AddressedEndpointDefinitionParser;
 23  
 import org.mule.endpoint.EndpointURIEndpointBuilder;
 24  
 
 25  
 import java.util.HashSet;
 26  
 import java.util.Iterator;
 27  
 import java.util.Map;
 28  
 import java.util.Set;
 29  
 
 30  
 import org.apache.commons.logging.Log;
 31  
 import org.apache.commons.logging.LogFactory;
 32  
 import org.springframework.beans.factory.config.BeanDefinition;
 33  
 import org.springframework.beans.factory.xml.BeanDefinitionParser;
 34  
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 35  
 import org.springframework.beans.factory.xml.ParserContext;
 36  
 import org.w3c.dom.Element;
 37  
 
 38  
 /**
 39  
  * This Namespace handler extends the default Spring {@link org.springframework.beans.factory.xml.NamespaceHandlerSupport}
 40  
  * to allow certain elements in document to be ignored by the handler.
 41  
  */
 42  0
 public abstract class AbstractMuleNamespaceHandler extends NamespaceHandlerSupport
 43  
 {
 44  
     public static final String GLOBAL_ENDPOINT = "endpoint";
 45  
     public static final String INBOUND_ENDPOINT = "inbound-endpoint";
 46  
     public static final String OUTBOUND_ENDPOINT = "outbound-endpoint"; 
 47  
 
 48  0
     protected transient final Log logger = LogFactory.getLog(getClass());
 49  
 
 50  
     /**
 51  
      * @param name The name of the element to be ignored.
 52  
      */
 53  
     protected final void registerIgnoredElement(String name)
 54  
     {
 55  0
         registerBeanDefinitionParser(name, new IgnoredDefinitionParser());
 56  0
     }
 57  
     
 58  
     protected MuleDefinitionParserConfiguration registerConnectorDefinitionParser(Class connectorClass)
 59  
     {
 60  0
         return registerConnectorDefinitionParser( new MuleOrphanDefinitionParser(connectorClass, true));
 61  
     }
 62  
 
 63  
     protected MuleDefinitionParserConfiguration registerConnectorDefinitionParser(MuleDefinitionParser parser)
 64  
     {
 65  0
         registerBeanDefinitionParser("connector", parser);
 66  0
         return parser;
 67  
     }
 68  
 
 69  
     protected MuleDefinitionParserConfiguration registerMuleBeanDefinitionParser(String name, MuleDefinitionParser parser)
 70  
     {
 71  0
         registerBeanDefinitionParser(name, parser);
 72  0
         return parser;
 73  
     }
 74  
 
 75  
     protected MuleDefinitionParserConfiguration registerStandardTransportEndpoints(String protocol, String[] requiredAttributes)
 76  
     {
 77  0
         return new RegisteredMdps(protocol, AddressedEndpointDefinitionParser.PROTOCOL, requiredAttributes);
 78  
     }
 79  
 
 80  
     protected MuleDefinitionParserConfiguration registerMetaTransportEndpoints(String protocol)
 81  
     {
 82  0
         return new RegisteredMdps(protocol, AddressedEndpointDefinitionParser.META, new String[]{});
 83  
     }
 84  
 
 85  
     private static class IgnoredDefinitionParser implements BeanDefinitionParser
 86  
     {
 87  
         public IgnoredDefinitionParser()
 88  
         {
 89  0
             super();
 90  0
         }
 91  
         
 92  
         public BeanDefinition parse(Element element, ParserContext parserContext)
 93  
         {
 94  0
             return null;
 95  
         }
 96  
     }
 97  
 
 98  
     protected Class getInboundEndpointFactoryBeanClass()
 99  
     {
 100  0
         return InboundEndpointFactoryBean.class;
 101  
     }
 102  
 
 103  
     protected Class getOutboundEndpointFactoryBeanClass()
 104  
     {
 105  0
         return OutboundEndpointFactoryBean.class;
 106  
     }
 107  
 
 108  
     protected Class getGlobalEndpointBuilderBeanClass()
 109  
     {
 110  0
         return EndpointURIEndpointBuilder.class;
 111  
     }
 112  
 
 113  0
     private class RegisteredMdps implements MuleDefinitionParserConfiguration
 114  
     {
 115  0
         private Set bdps = new HashSet();
 116  
 
 117  
         public RegisteredMdps(String protocol, boolean isMeta, String[] requiredAttributes)
 118  0
         {
 119  0
             registerBeanDefinitionParser("endpoint", add(new TransportGlobalEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getGlobalEndpointBuilderBeanClass(), requiredAttributes, new String[]{})));
 120  0
             registerBeanDefinitionParser("inbound-endpoint", add(new TransportEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getInboundEndpointFactoryBeanClass(), requiredAttributes, new String[]{})));
 121  0
             registerBeanDefinitionParser("outbound-endpoint", add(new TransportEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getOutboundEndpointFactoryBeanClass(), requiredAttributes, new String[]{})));
 122  0
         }
 123  
 
 124  
         private MuleDefinitionParser add(MuleDefinitionParser bdp)
 125  
         {
 126  0
             bdps.add(bdp);
 127  0
             return bdp;
 128  
         }
 129  
 
 130  
         public MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor)
 131  
         {
 132  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 133  
             {
 134  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).registerPreProcessor(preProcessor);
 135  
             }
 136  0
             return this;
 137  
         }
 138  
 
 139  
         public MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor)
 140  
         {
 141  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 142  
             {
 143  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).registerPostProcessor(postProcessor);
 144  
             }
 145  0
             return this;
 146  
         }
 147  
 
 148  
         public MuleDefinitionParserConfiguration addReference(String propertyName)
 149  
         {
 150  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 151  
             {
 152  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addReference(propertyName);
 153  
             }
 154  0
             return this;
 155  
         }
 156  
 
 157  
         public MuleDefinitionParserConfiguration addMapping(String propertyName, Map mappings)
 158  
         {
 159  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 160  
             {
 161  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings);
 162  
             }
 163  0
             return this;
 164  
         }
 165  
 
 166  
         public MuleDefinitionParserConfiguration addMapping(String propertyName, String mappings)
 167  
         {
 168  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 169  
             {
 170  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings);
 171  
             }
 172  0
             return this;
 173  
         }
 174  
 
 175  
         public MuleDefinitionParserConfiguration addMapping(String propertyName, ValueMap mappings)
 176  
         {
 177  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 178  
             {
 179  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings);
 180  
             }
 181  0
             return this;
 182  
         }
 183  
 
 184  
         public MuleDefinitionParserConfiguration addAlias(String alias, String propertyName)
 185  
         {
 186  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 187  
             {
 188  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addAlias(alias, propertyName);
 189  
             }
 190  0
             return this;
 191  
         }
 192  
 
 193  
         public MuleDefinitionParserConfiguration addCollection(String propertyName)
 194  
         {
 195  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 196  
             {
 197  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addCollection(propertyName);
 198  
             }
 199  0
             return this;
 200  
         }
 201  
 
 202  
         public MuleDefinitionParserConfiguration addIgnored(String propertyName)
 203  
         {
 204  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 205  
             {
 206  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addIgnored(propertyName);
 207  
             }
 208  0
             return this;
 209  
         }
 210  
 
 211  
         public MuleDefinitionParserConfiguration removeIgnored(String propertyName)
 212  
         {
 213  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 214  
             {
 215  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).removeIgnored(propertyName);
 216  
             }
 217  0
             return this;
 218  
         }
 219  
 
 220  
         public MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll)
 221  
         {
 222  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 223  
             {
 224  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).setIgnoredDefault(ignoreAll);
 225  
             }
 226  0
             return this;
 227  
         }
 228  
 
 229  
         public MuleDefinitionParserConfiguration addBeanFlag(String flag)
 230  
         {
 231  0
             for (Iterator bdp = bdps.iterator(); bdp.hasNext();)
 232  
             {
 233  0
                 ((MuleDefinitionParserConfiguration) bdp.next()).addBeanFlag(flag);
 234  
             }
 235  0
             return this;
 236  
         }
 237  
     }
 238  
     
 239  
     /**
 240  
      * Subclasses can call this to register the supplied {@link BeanDefinitionParser} to
 241  
      * handle the specified element. The element name is the local (non-namespace qualified)
 242  
      * name.
 243  
      */
 244  
     protected void registerDeprecatedBeanDefinitionParser(String elementName, BeanDefinitionParser parser, String deprecationWarning) 
 245  
     {
 246  0
         if (parser instanceof MuleDefinitionParserConfiguration)
 247  
         {
 248  0
             ((MuleDefinitionParser) parser).setDeprecationWarning(deprecationWarning);
 249  
         }
 250  0
         registerBeanDefinitionParser(elementName, parser);
 251  0
     }
 252  
 
 253  
 }