Coverage Report - org.mule.config.spring.parsers.delegate.AbstractFirstResultSerialDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFirstResultSerialDefinitionParser
0%
0/23
0%
0/8
3.75
 
 1  
 /*
 2  
  * $Id: AbstractFirstResultSerialDefinitionParser.java 10258 2008-01-08 18:17:45Z acooke $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.parsers.MuleDefinitionParser;
 14  
 
 15  
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 16  
 import org.springframework.beans.factory.xml.ParserContext;
 17  
 import org.w3c.dom.Element;
 18  
 
 19  
 /**
 20  
  * Extend {@link org.mule.config.spring.parsers.delegate.AbstractSerialDelegatingDefinitionParser}
 21  
  * to return the first definition as the final result
 22  
  */
 23  
 public class AbstractFirstResultSerialDefinitionParser extends AbstractSerialDelegatingDefinitionParser
 24  
 {
 25  
 
 26  
     protected AbstractBeanDefinition firstDefinition;
 27  0
     private boolean returnFirstResult = true;
 28  
 
 29  
     public AbstractFirstResultSerialDefinitionParser()
 30  
     {
 31  0
         super();
 32  0
     }
 33  
 
 34  
     public AbstractFirstResultSerialDefinitionParser(boolean doReset)
 35  
     {
 36  0
         super(doReset);
 37  0
     }
 38  
 
 39  
     public void setReturnFirstResult(boolean returnFirstResult)
 40  
     {
 41  0
         this.returnFirstResult = returnFirstResult;
 42  0
     }
 43  
 
 44  
     protected AbstractBeanDefinition doSingleBean(int index, MuleDefinitionParser parser, Element element, ParserContext parserContext)
 45  
     {
 46  
         try
 47  
         {
 48  0
             AbstractBeanDefinition result = null;
 49  
             try
 50  
             {
 51  0
                 result = super.doSingleBean(index, parser, element, parserContext);
 52  
             }
 53  0
             catch (RuntimeException e)
 54  
             {
 55  0
                 if (!isExceptionHandled(e))
 56  
                 {
 57  0
                     throw e;
 58  
                 }
 59  0
             }
 60  0
             if (0 == index)
 61  
             {
 62  0
                 firstDefinition = result;
 63  
             }
 64  0
             if (size() == index + 1)
 65  
             {
 66  0
                 if (returnFirstResult)
 67  
                 {
 68  0
                     return firstDefinition;
 69  
                 }
 70  
                 else
 71  
                 {
 72  0
                     return result;
 73  
                 }
 74  
             }
 75  
             else
 76  
             {
 77  0
                 return null;
 78  
             }
 79  
         }
 80  0
         catch (RuntimeException e)
 81  
         {
 82  0
             firstDefinition = null;
 83  0
             throw e;
 84  
         }
 85  
     }
 86  
 
 87  
 }