1 package org
.argeo
.slc
.core
.execution
.xml
;
3 import java
.util
.ArrayList
;
6 import org
.argeo
.slc
.SlcException
;
7 import org
.argeo
.slc
.core
.execution
.DefaultExecutionFlow
;
8 import org
.argeo
.slc
.execution
.ExecutionFlow
;
9 import org
.springframework
.beans
.factory
.BeanDefinitionStoreException
;
10 import org
.springframework
.beans
.factory
.config
.RuntimeBeanReference
;
11 import org
.springframework
.beans
.factory
.support
.AbstractBeanDefinition
;
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
.Node
;
21 import org
.w3c
.dom
.NodeList
;
23 public class FlowBeanDefinitionParser
extends
24 AbstractSingleBeanDefinitionParser
{
25 // private Log log = LogFactory.getLog(FlowBeanDefinitionParser.class);
27 @SuppressWarnings("unchecked")
29 protected void doParse(Element element
, ParserContext parserContext
,
30 BeanDefinitionBuilder builder
) {
31 String path
= element
.getAttribute("path");
32 if (StringUtils
.hasText(path
))
33 builder
.addPropertyValue("path", path
);
35 String spec
= element
.getAttribute("spec");
36 if (StringUtils
.hasText(spec
))
37 builder
.getBeanDefinition().getConstructorArgumentValues()
38 .addGenericArgumentValue(new RuntimeBeanReference(spec
));
40 String abstrac
= element
.getAttribute("abstract");
41 if (StringUtils
.hasText(abstrac
))
42 builder
.setAbstract(Boolean
.parseBoolean(abstrac
));
44 String parent
= element
.getAttribute("parent");
45 if (StringUtils
.hasText(parent
))
46 builder
.setParentName(parent
);
48 builder
.getBeanDefinition().setDescription(
49 DomUtils
.getChildElementValueByTagName(element
, "description"));
51 List
<Element
> execElems
= new ArrayList
<Element
>();
52 List
<Element
> argsElems
= new ArrayList
<Element
>();
53 NodeList nodeList
= element
.getChildNodes();
54 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
55 Node node
= nodeList
.item(i
);
56 if (node
instanceof Element
) {
57 if (DomUtils
.nodeNameEquals(node
, "arg"))
58 argsElems
.add((Element
) node
);
59 else if (!DomUtils
.nodeNameEquals(node
, "description"))
60 execElems
.add((Element
) node
);
65 if (argsElems
.size() != 0) {
66 ManagedMap args
= new ManagedMap(argsElems
.size());
67 for (Element argElem
: argsElems
) {
68 Object value
= NamespaceUtils
.parseValue(argElem
,
69 parserContext
, builder
.getBeanDefinition(), null);
71 args
.put(argElem
.getAttribute("name"), value
);
73 throw new SlcException("No value defined.");
75 builder
.getBeanDefinition().getConstructorArgumentValues()
76 .addGenericArgumentValue(args
);
80 if (execElems
.size() != 0) {
81 ManagedList executables
= new ManagedList(execElems
.size());
82 for (Element child
: execElems
) {
83 // child validity check is performed in xsd
84 executables
.add(NamespaceUtils
.parseBeanOrReference(child
,
85 parserContext
, builder
.getBeanDefinition()));
87 if (executables
.size() > 0)
88 builder
.addPropertyValue("executables", executables
);
92 @SuppressWarnings("unchecked")
94 protected Class
<?
extends ExecutionFlow
> getBeanClass(Element element
) {
95 String clss
= element
.getAttribute("class");
96 if (StringUtils
.hasText(clss
))
97 // TODO: check that it actually works
99 return (Class
<?
extends ExecutionFlow
>) getClass()
100 .getClassLoader().loadClass(clss
);
101 } catch (ClassNotFoundException e
) {
103 return (Class
<?
extends ExecutionFlow
>) Thread
104 .currentThread().getContextClassLoader().loadClass(
106 } catch (ClassNotFoundException e1
) {
107 throw new SlcException("Cannot load class " + clss
, e
);
111 return DefaultExecutionFlow
.class;
114 // parse nested bean definition
115 // private Object parseBeanReference(Element element,
116 // ParserContext parserContext, BeanDefinitionBuilder builder) {
117 // return parserContext.getDelegate().parsePropertySubElement(element,
118 // builder.getBeanDefinition());
122 protected String
resolveId(Element element
,
123 AbstractBeanDefinition definition
, ParserContext parserContext
)
124 throws BeanDefinitionStoreException
{
125 String name
= element
.getAttribute("name");
126 if (StringUtils
.hasText(name
)) {
129 return super.resolveId(element
, definition
, parserContext
);
133 protected boolean shouldGenerateIdAsFallback() {