Coverage Report - org.mule.config.spring.parsers.generic.OptionalChildDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionalChildDefinitionParser
0%
0/18
0%
0/6
1.429
 
 1  
 /*
 2  
  * $Id: OptionalChildDefinitionParser.java 11695 2008-05-08 06:46:45Z dirk.olmes $
 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.generic;
 12  
 
 13  
 import org.mule.config.spring.parsers.assembly.BeanAssembler;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import org.springframework.beans.factory.config.BeanDefinition;
 17  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 18  
 import org.springframework.beans.factory.xml.ParserContext;
 19  
 import org.w3c.dom.Element;
 20  
 
 21  
 /**
 22  
  * This class should be used when the same element can be configured as a child or an orphan 
 23  
  * (i.e., top-level).  It will inject the bean into the parent if the parent exists, otherwise 
 24  
  * it will not complain (ChildDefinitionParser throws an exception if no parent exists).
 25  
  */
 26  
 public class OptionalChildDefinitionParser extends ChildDefinitionParser
 27  
 {
 28  
     private boolean isChild;
 29  
     
 30  
     public OptionalChildDefinitionParser(String setterMethod)
 31  
     {
 32  0
         super(setterMethod);
 33  0
     }
 34  
     
 35  
     public OptionalChildDefinitionParser(String setterMethod, Class clazz)
 36  
     {
 37  0
         super(setterMethod, clazz);
 38  0
     }
 39  
     
 40  
     public OptionalChildDefinitionParser(String setterMethod, Class clazz, Class constraint)
 41  
     {
 42  0
         super(setterMethod, clazz, constraint);
 43  0
     }
 44  
     
 45  
     public OptionalChildDefinitionParser(String setterMethod, Class clazz, Class constraint, boolean allowClassAttribute)
 46  
     {
 47  0
         super(setterMethod, clazz, constraint, allowClassAttribute);
 48  0
     }
 49  
 
 50  
     // @Override
 51  
     protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 52  
     {
 53  0
         String parentBean = getParentBeanName(element);
 54  0
         isChild = !(StringUtils.isBlank(parentBean));
 55  
 
 56  0
         super.parseChild(element, parserContext, builder);
 57  0
     }
 58  
 
 59  
     public BeanDefinition getParentBeanDefinition(Element element)
 60  
     {
 61  0
         if (isChild)
 62  
         {
 63  0
             return super.getParentBeanDefinition(element);
 64  
         }
 65  
         else
 66  
         {
 67  0
             return null;
 68  
         }
 69  
     }
 70  
 
 71  
     protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
 72  
     {
 73  0
         if (isChild)
 74  
         {
 75  0
             super.postProcess(context, assembler, element);
 76  
         }
 77  0
     }
 78  
 }
 79  
 
 80