| 1 | |
package org.jtheque.core.spring.extension; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 0 | public final class ColorBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser { |
| 34 | |
|
| 35 | |
|
| 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 | |
} |