1 package org
.argeo
.slc
.core
.execution
.xml
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.argeo
.slc
.core
.execution
.DefaultExecutionSpec
;
8 import org
.argeo
.slc
.core
.execution
.PrimitiveSpecAttribute
;
9 import org
.argeo
.slc
.core
.execution
.RefSpecAttribute
;
10 import org
.argeo
.slc
.core
.execution
.RefValueChoice
;
11 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
12 import org
.springframework
.beans
.factory
.support
.BeanDefinitionBuilder
;
13 import org
.springframework
.beans
.factory
.support
.ManagedList
;
14 import org
.springframework
.beans
.factory
.support
.ManagedMap
;
15 import org
.springframework
.beans
.factory
.xml
.AbstractSingleBeanDefinitionParser
;
16 import org
.springframework
.beans
.factory
.xml
.ParserContext
;
17 import org
.springframework
.util
.StringUtils
;
18 import org
.springframework
.util
.xml
.DomUtils
;
19 import org
.w3c
.dom
.Element
;
20 import org
.w3c
.dom
.NodeList
;
22 public class SpecBeanDefinitionParser
extends
23 AbstractSingleBeanDefinitionParser
{
24 private Log log
= LogFactory
.getLog(SpecBeanDefinitionParser
.class);
26 @SuppressWarnings("unchecked")
28 protected void doParse(Element element
, ParserContext parserContext
,
29 BeanDefinitionBuilder builder
) {
30 ManagedMap attributes
= new ManagedMap();
33 for (Element child
: (List
<Element
>) DomUtils
34 .getChildElementsByTagName(element
, "primitive")) {
35 BeanDefinitionBuilder childBuilder
= BeanDefinitionBuilder
36 .genericBeanDefinition(PrimitiveSpecAttribute
.class);
37 addCommonProperties(child
, parserContext
, childBuilder
);
39 String type
= child
.getAttribute("type");
40 if (StringUtils
.hasText(type
))
41 childBuilder
.addPropertyValue("type", type
);
43 putInAttributes(attributes
, child
,
44 childBuilder
.getBeanDefinition(), "primitive");
48 for (Element child
: (List
<Element
>) DomUtils
49 .getChildElementsByTagName(element
, "ref")) {
50 BeanDefinitionBuilder childBuilder
= BeanDefinitionBuilder
51 .genericBeanDefinition(RefSpecAttribute
.class);
52 addCommonProperties(child
, parserContext
, childBuilder
);
54 String targetClassName
= child
.getAttribute("targetClass");
55 if (StringUtils
.hasText(targetClassName
))
56 childBuilder
.addPropertyValue("targetClass", targetClassName
);
59 NodeList choicesNd
= child
.getElementsByTagName("choices");
60 if (choicesNd
.getLength() > 0) {
61 Element choicesElem
= (Element
) choicesNd
.item(0);
62 List choices
= DomUtils
.getChildElementsByTagName(choicesElem
,
64 ManagedList choiceBeans
= new ManagedList(choices
.size());
65 for (Element choiceElem
: (List
<Element
>) choices
) {
66 BeanDefinitionBuilder choiceBuilder
= BeanDefinitionBuilder
67 .genericBeanDefinition(RefValueChoice
.class);
68 choiceBuilder
.addPropertyValue("name", choiceElem
69 .getAttribute("name"));
70 String desc
= choiceElem
.getAttribute("description");
71 if (StringUtils
.hasText(desc
))
72 choiceBuilder
.addPropertyValue("description", desc
);
74 choiceBeans
.add(choiceBuilder
.getBeanDefinition());
79 putInAttributes(attributes
, child
,
80 childBuilder
.getBeanDefinition(), "ref");
83 builder
.addPropertyValue("attributes", attributes
);
86 protected void addCommonProperties(Element element
,
87 ParserContext parserContext
, BeanDefinitionBuilder specAttr
) {
88 addBooleanProperty("isParameter", specAttr
, element
);
89 addBooleanProperty("isFrozen", specAttr
, element
);
90 addBooleanProperty("isHidden", specAttr
, element
);
92 Object value
= NamespaceUtils
.parseValue(element
, parserContext
,
93 specAttr
.getBeanDefinition(), "value");
95 specAttr
.addPropertyValue("value", value
);
99 @SuppressWarnings("unchecked")
100 protected void putInAttributes(ManagedMap attributes
, Element child
,
101 BeanDefinition beanDefinition
, String nature
) {
102 String name
= child
.getAttribute("name");
103 attributes
.put(name
, beanDefinition
);
104 if (log
.isTraceEnabled())
105 log
.debug("Added " + nature
+ " attribute " + name
);
109 private void addBooleanProperty(String name
,
110 BeanDefinitionBuilder specAttr
, Element element
) {
111 String bool
= element
.getAttribute(name
);
112 if (StringUtils
.hasText(bool
))
113 specAttr
.addPropertyValue(name
, Boolean
.parseBoolean(bool
));
118 protected Class
<DefaultExecutionSpec
> getBeanClass(Element element
) {
119 return DefaultExecutionSpec
.class;
122 protected boolean shouldGenerateIdAsFallback() {