Coverage Report - org.mule.config.spring.parsers.delegate.AbstractDelegatingDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractDelegatingDefinitionParser
0%
0/49
0%
0/24
1.632
 
 1  
 /*
 2  
  * $Id: AbstractDelegatingDefinitionParser.java 19191 2010-08-25 21:05:23Z 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  
 
 11  
 package org.mule.config.spring.parsers.delegate;
 12  
 
 13  
 import org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate;
 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.AutoIdUtils;
 20  
 import org.mule.util.ArrayUtils;
 21  
 
 22  
 import java.util.Map;
 23  
 
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 27  
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 28  
 import org.springframework.beans.factory.xml.ParserContext;
 29  
 import org.w3c.dom.Element;
 30  
 
 31  
 /**
 32  
  * This allows a definition parsers to be dynamically represented by different
 33  
  * definition parsers, depending on the context.  For example, a single model may
 34  
  * be defined across file - the first use defines the model and subsequent uses
 35  
  * extend it (for this particular case, see {@link InheritDefinitionParser}).
 36  
  *
 37  
  * <p>Note that the sub-parsers must be consistent.  That includes matching the
 38  
  * same schema, for example.</p>
 39  
  */
 40  
 public abstract class AbstractDelegatingDefinitionParser extends AbstractBeanDefinitionParser
 41  
     implements MuleDefinitionParser
 42  
 {
 43  
 
 44  0
     protected Log logger = LogFactory.getLog(getClass());
 45  
     
 46  
     private MuleDefinitionParser[] delegates;
 47  
 
 48  
     protected AbstractDelegatingDefinitionParser()
 49  
     {
 50  0
         this(new MuleDefinitionParser[0]);
 51  0
     }
 52  
 
 53  
     protected AbstractDelegatingDefinitionParser(MuleDefinitionParser[] delegates)
 54  0
     {
 55  0
         this.delegates = delegates;
 56  0
         addBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_FORCE_RECURSE);
 57  0
     }
 58  
 
 59  
     protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
 60  
     {
 61  0
         return muleParse(element, parserContext);
 62  
     }
 63  
 
 64  
     protected MuleDefinitionParserConfiguration addDelegate(MuleDefinitionParser delegate)
 65  
     {
 66  0
         delegates = (MuleDefinitionParser[]) ArrayUtils.add(delegates, delegate);
 67  0
         return delegate;
 68  
     }
 69  
 
 70  
     protected int size()
 71  
     {
 72  0
         return delegates.length;
 73  
     }
 74  
 
 75  
     protected MuleDefinitionParser getDelegate(int index)
 76  
     {
 77  0
         return delegates[index];
 78  
     }
 79  
 
 80  
     public MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor)
 81  
     {
 82  0
         for (int i = 0; i < delegates.length; ++i)
 83  
         {
 84  0
             delegates[i].registerPreProcessor(preProcessor);
 85  
         }
 86  0
         return this;
 87  
     }
 88  
 
 89  
     public MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor)
 90  
     {
 91  0
         for (int i = 0; i < delegates.length; ++i)
 92  
         {
 93  0
             delegates[i].registerPostProcessor(postProcessor);
 94  
         }
 95  0
         return this;
 96  
     }
 97  
 
 98  
     public MuleDefinitionParserConfiguration addReference(String propertyName)
 99  
     {
 100  0
         for (int i = 0; i < delegates.length; ++i)
 101  
         {
 102  0
             delegates[i].addReference(propertyName);
 103  
         }
 104  0
         return this;
 105  
     }
 106  
 
 107  
     public MuleDefinitionParserConfiguration addMapping(String propertyName, Map mappings)
 108  
     {
 109  0
         for (int i = 0; i < delegates.length; ++i)
 110  
         {
 111  0
             delegates[i].addMapping(propertyName, mappings);
 112  
         }
 113  0
         return this;
 114  
     }
 115  
 
 116  
     public MuleDefinitionParserConfiguration addMapping(String propertyName, String mappings)
 117  
     {
 118  0
         for (int i = 0; i < delegates.length; ++i)
 119  
         {
 120  0
             delegates[i].addMapping(propertyName, mappings);
 121  
         }
 122  0
         return this;
 123  
     }
 124  
 
 125  
     public MuleDefinitionParserConfiguration addMapping(String propertyName, ValueMap mappings)
 126  
     {
 127  0
         for (int i = 0; i < delegates.length; ++i)
 128  
         {
 129  0
             delegates[i].addMapping(propertyName, mappings);
 130  
         }
 131  0
         return this;
 132  
     }
 133  
 
 134  
     public MuleDefinitionParserConfiguration addAlias(String alias, String propertyName)
 135  
     {
 136  0
         for (int i = 0; i < delegates.length; ++i)
 137  
         {
 138  0
             delegates[i].addAlias(alias, propertyName);
 139  
         }
 140  0
         return this;
 141  
     }
 142  
 
 143  
     public MuleDefinitionParserConfiguration addCollection(String propertyName)
 144  
     {
 145  0
         for (int i = 0; i < delegates.length; ++i)
 146  
         {
 147  0
             delegates[i].addCollection(propertyName);
 148  
         }
 149  0
         return this;
 150  
     }
 151  
 
 152  
     public MuleDefinitionParserConfiguration addIgnored(String propertyName)
 153  
     {
 154  0
         for (int i = 0; i < delegates.length; ++i)
 155  
         {
 156  0
             delegates[i].addIgnored(propertyName);
 157  
         }
 158  0
         return this;
 159  
     }
 160  
 
 161  
     public MuleDefinitionParserConfiguration removeIgnored(String propertyName)
 162  
     {
 163  0
         for (int i = 0; i < delegates.length; ++i)
 164  
         {
 165  0
             delegates[i].removeIgnored(propertyName);
 166  
         }
 167  0
         return this;
 168  
     }
 169  
 
 170  
     public MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll)
 171  
     {
 172  0
         for (int i = 0; i < delegates.length; ++i)
 173  
         {
 174  0
             delegates[i].setIgnoredDefault(ignoreAll);
 175  
         }
 176  0
         return this;
 177  
     }
 178  
 
 179  
     public String getBeanName(Element element)
 180  
     {
 181  0
         return AutoIdUtils.getUniqueName(element, "delegate");
 182  
     }
 183  
 
 184  
     public MuleDefinitionParserConfiguration addBeanFlag(String flag)
 185  
     {
 186  0
         for (int i = 0; i < delegates.length; ++i)
 187  
         {
 188  0
             delegates[i].addBeanFlag(flag);
 189  
         }
 190  0
         return this;
 191  
     }
 192  
 
 193  
 }