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
.execution
.RefSpecAttribute
;
9 import org
.argeo
.slc
.execution
.RefValueChoice
;
10 import org
.argeo
.slc
.primitive
.PrimitiveSpecAttribute
;
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
;
21 /** Interprets the <flow:spec> tag */
22 public class SpecBeanDefinitionParser
extends
23 AbstractSingleBeanDefinitionParser
{
24 private Log log
= LogFactory
.getLog(SpecBeanDefinitionParser
.class);
27 protected void doParse(Element element
, ParserContext parserContext
,
28 BeanDefinitionBuilder builder
) {
29 builder
.getBeanDefinition().setDescription(
30 DomUtils
.getChildElementValueByTagName(element
, "description"));
32 ManagedMap
<String
, BeanDefinition
> attributes
= new ManagedMap
<String
, BeanDefinition
>();
35 for (Element child
: (List
<Element
>) DomUtils
36 .getChildElementsByTagName(element
, "primitive")) {
37 BeanDefinitionBuilder childBuilder
= BeanDefinitionBuilder
38 .genericBeanDefinition(PrimitiveSpecAttribute
.class);
39 addCommonProperties(child
, parserContext
, childBuilder
);
41 String type
= child
.getAttribute("type");
42 if (StringUtils
.hasText(type
))
43 childBuilder
.addPropertyValue("type", type
);
45 putInAttributes(attributes
, child
,
46 childBuilder
.getBeanDefinition(), "primitive");
50 for (Element refAttrElem
: (List
<Element
>) DomUtils
51 .getChildElementsByTagName(element
, "ref")) {
52 BeanDefinitionBuilder refAttrBuilder
= BeanDefinitionBuilder
53 .genericBeanDefinition(RefSpecAttribute
.class);
54 addCommonProperties(refAttrElem
, parserContext
, refAttrBuilder
);
56 String targetClassName
= refAttrElem
.getAttribute("targetClass");
57 if (StringUtils
.hasText(targetClassName
))
58 refAttrBuilder
.addPropertyValue("targetClass", targetClassName
);
61 Element choicesElem
= DomUtils
.getChildElementByTagName(
62 refAttrElem
, "choices");
63 if (choicesElem
!= null) {
64 List
<Element
> choices
= DomUtils
.getChildElementsByTagName(
65 choicesElem
, "choice");
66 ManagedList
<BeanDefinition
> choiceBeans
= new ManagedList
<BeanDefinition
>(
68 for (Element choiceElem
: choices
) {
69 BeanDefinitionBuilder choiceBuilder
= BeanDefinitionBuilder
70 .genericBeanDefinition(RefValueChoice
.class);
71 choiceBuilder
.addPropertyValue("name",
72 choiceElem
.getAttribute("name"));
73 String desc
= choiceElem
.getAttribute("description");
74 if (StringUtils
.hasText(desc
))
75 choiceBuilder
.addPropertyValue("description", desc
);
77 choiceBeans
.add(choiceBuilder
.getBeanDefinition());
79 refAttrBuilder
.addPropertyValue("choices", choiceBeans
);
82 putInAttributes(attributes
, refAttrElem
,
83 refAttrBuilder
.getBeanDefinition(), "ref");
86 builder
.addPropertyValue("attributes", attributes
);
89 protected void addCommonProperties(Element element
,
90 ParserContext parserContext
, BeanDefinitionBuilder specAttr
) {
91 addBooleanProperty("isImmutable", specAttr
, element
);
92 addBooleanProperty("isConstant", specAttr
, element
);
93 addBooleanProperty("isHidden", specAttr
, element
);
94 addBooleanProperty("isParameter", specAttr
, element
);
95 addBooleanProperty("isFrozen", specAttr
, element
);
97 Object value
= NamespaceUtils
.parseValue(element
, parserContext
,
98 specAttr
.getBeanDefinition(), "value");
100 specAttr
.addPropertyValue("value", value
);
104 protected void putInAttributes(
105 ManagedMap
<String
, BeanDefinition
> attributes
, Element child
,
106 BeanDefinition beanDefinition
, String nature
) {
107 String name
= child
.getAttribute("name");
108 attributes
.put(name
, beanDefinition
);
109 if (log
.isTraceEnabled())
110 log
.debug("Added " + nature
+ " attribute " + name
);
114 private void addBooleanProperty(String name
,
115 BeanDefinitionBuilder specAttr
, Element element
) {
116 String bool
= element
.getAttribute(name
);
117 if (StringUtils
.hasText(bool
))
118 specAttr
.addPropertyValue(name
, Boolean
.parseBoolean(bool
));
123 protected Class
<DefaultExecutionSpec
> getBeanClass(Element element
) {
124 return DefaultExecutionSpec
.class;
127 protected boolean shouldGenerateIdAsFallback() {