Coverage Report - org.mule.config.spring.parsers.generic.OptionalChildDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionalChildDefinitionParser
0%
0/19
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: OptionalChildDefinitionParser.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.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
         isChild = isChild(element, parserContext, builder);
 54  0
         super.parseChild(element, parserContext, builder);
 55  0
     }
 56  
 
 57  
     protected boolean isChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
 58  
     {
 59  0
         String parentBean = getParentBeanName(element);
 60  0
         return !(StringUtils.isBlank(parentBean));
 61  
     }
 62  
     
 63  
     public BeanDefinition getParentBeanDefinition(Element element)
 64  
     {
 65  0
         if (isChild)
 66  
         {
 67  0
             return super.getParentBeanDefinition(element);
 68  
         }
 69  
         else
 70  
         {
 71  0
             return null;
 72  
         }
 73  
     }
 74  
 
 75  
     protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
 76  
     {
 77  0
         if (isChild)
 78  
         {
 79  0
             super.postProcess(context, assembler, element);
 80  
         }
 81  0
     }
 82  
 }
 83  
 
 84