Coverage Report - org.mule.config.spring.parsers.generic.ChildDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ChildDefinitionParser
0%
0/21
0%
0/6
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.spring.parsers.generic;
 8  
 
 9  
 import org.mule.config.spring.parsers.AbstractChildDefinitionParser;
 10  
 
 11  
 import org.w3c.dom.Element;
 12  
 
 13  
 /**
 14  
  * Creates a definition parser that will construct a single child element and inject it into
 15  
  * the parent object (the enclosing XML element).
 16  
  *
 17  
  * The parser will set all attributes defined in the Xml as bean properties and will
 18  
  * process any nested elements as bean properties too, except the correct Definition parser
 19  
  * for the element will be looked up automatically.
 20  
  */
 21  
 public class ChildDefinitionParser extends AbstractChildDefinitionParser
 22  
 {
 23  
 
 24  
     protected Class<?> clazz;
 25  
     protected String setterMethod;
 26  
 
 27  
     /**
 28  
      * The class will be inferred from the class attribute
 29  
      * @param setterMethod The target method (where the child will be injected)
 30  
      */
 31  
     public ChildDefinitionParser(String setterMethod)
 32  
     {
 33  0
         this(setterMethod, null, null, true);
 34  0
     }
 35  
 
 36  
     /**
 37  
      * @param setterMethod The target method (where the child will be injected)
 38  
      * @param clazz The class created by this element/parser
 39  
      */
 40  
     public ChildDefinitionParser(String setterMethod, Class<?> clazz)
 41  
     {
 42  0
         this(setterMethod, clazz, null, null == clazz);
 43  0
     }
 44  
 
 45  
     /**
 46  
      *
 47  
      * @param setterMethod
 48  
      * @param clazz
 49  
      * @param singleton  determines is bean should be singleton or not
 50  
      */
 51  
     public ChildDefinitionParser(String setterMethod, Class<?> clazz, boolean singleton)
 52  
     {
 53  0
         this(setterMethod, clazz);
 54  0
         this.singleton = singleton;
 55  0
     }
 56  
 
 57  
     /**
 58  
      * The class (which is inferred from the class attribute if null here) is checked to be
 59  
      * a subclass of the constraint
 60  
      * @param setterMethod The target method (where the child will be injected)
 61  
      * @param clazz The class created by this element/parser (may be null)
 62  
      * @param constraint Superclass of clazz (may be null)
 63  
      */
 64  
     public ChildDefinitionParser(String setterMethod, Class<?> clazz, Class<?> constraint)
 65  
     {
 66  0
         this(setterMethod, clazz, constraint, null == clazz);
 67  0
     }
 68  
 
 69  
     /**
 70  
      * The class (which is inferred from the class attribute if null here) is checked to be
 71  
      * a subclass of the constraint.
 72  
      *
 73  
      * @param setterMethod The target method (where the child will be injected)
 74  
      * @param clazz The class created by this element/parser (may be null)
 75  
      * @param constraint Superclass of clazz (may be null)
 76  
      * @param allowClassAttribute Is class read from class attribute (if present, takes precedence over clazz)
 77  
      */
 78  
     public ChildDefinitionParser(String setterMethod, Class<?> clazz, Class<?> constraint, boolean allowClassAttribute)
 79  0
     {
 80  0
         this.clazz = clazz;
 81  0
         this.setterMethod = setterMethod;
 82  0
         setClassConstraint(constraint);
 83  0
         setAllowClassAttribute(allowClassAttribute);
 84  0
     }
 85  
 
 86  
     @Override
 87  
     protected void preProcess(Element element)
 88  
     {
 89  0
         super.preProcess(element);
 90  0
         if (isAllowClassAttribute())
 91  
         {
 92  0
            clazz = null; // reset for this element
 93  
         }
 94  0
     }
 95  
 
 96  
     @Override
 97  
     protected Class<?> getBeanClass(Element element)
 98  
     {
 99  0
         return clazz;
 100  
     }
 101  
 
 102  
     @Override
 103  
     public String getPropertyName(Element e)
 104  
     {
 105  0
         return setterMethod;
 106  
     }
 107  
 
 108  
 }