Coverage Report - org.jtheque.core.spring.extension.ColorBeanDefinitionParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ColorBeanDefinitionParser
0 %
0/10
0 %
0/2
1.5
 
 1  
 package org.jtheque.core.spring.extension;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.utils.StringUtils;
 20  
 import org.springframework.beans.factory.config.ConstructorArgumentValues;
 21  
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 22  
 import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
 23  
 import org.springframework.beans.factory.xml.ParserContext;
 24  
 import org.w3c.dom.Element;
 25  
 
 26  
 import java.awt.Color;
 27  
 
 28  
 /**
 29  
  * A bean definition parser for the color element of the jtheque namespace.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  0
 public final class ColorBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
 34  
     /**
 35  
      * The String definition of an int.
 36  
      */
 37  
     private static final String INT_VALUE = "int";
 38  
 
 39  
     @Override
 40  
     protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
 41  0
         ConstructorArgumentValues values = new ConstructorArgumentValues();
 42  0
         values.addGenericArgumentValue(Integer.parseInt(element.getAttribute("r")), INT_VALUE);
 43  0
         values.addGenericArgumentValue(Integer.parseInt(element.getAttribute("g")), INT_VALUE);
 44  0
         values.addGenericArgumentValue(Integer.parseInt(element.getAttribute("b")), INT_VALUE);
 45  
 
 46  0
         if (StringUtils.isNotEmpty(element.getAttribute("alpha"))) {
 47  0
             values.addGenericArgumentValue(Integer.parseInt(element.getAttribute("alpha")), INT_VALUE);
 48  
         }
 49  
 
 50  0
         builder.getBeanDefinition().setConstructorArgumentValues(values);
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected Class<?> getBeanClass(Element element) {
 55  0
         return Color.class;
 56  
     }
 57  
 }