]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java
Complete implementation of flow namespace + unit tests
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / xml / FlowBeanDefinitionParser.java
index 85269778c895c442c568f17a7a924cb2ab748617..7bc04ea5466dba96762e13218f184dc887709047 100644 (file)
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.util.StringUtils;
+import org.springframework.util.xml.DomUtils;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -30,7 +31,7 @@ public class FlowBeanDefinitionParser extends
 
                String spec = element.getAttribute("spec");
                if (StringUtils.hasText(spec))
-                       builder.getRawBeanDefinition().getConstructorArgumentValues()
+                       builder.getBeanDefinition().getConstructorArgumentValues()
                                        .addGenericArgumentValue(new RuntimeBeanReference(spec));
 
                String abstrac = element.getAttribute("abstract");
@@ -47,7 +48,7 @@ public class FlowBeanDefinitionParser extends
                for (int i = 0; i < nodeList.getLength(); i++) {
                        Node node = nodeList.item(i);
                        if (node instanceof Element) {
-                               if ("arg".equals(node.getLocalName()))
+                               if (DomUtils.nodeNameEquals(node, "arg"))
                                        argsElems.add((Element) node);
                                else
                                        execElems.add((Element) node);
@@ -58,17 +59,14 @@ public class FlowBeanDefinitionParser extends
                if (argsElems.size() != 0) {
                        ManagedMap args = new ManagedMap(argsElems.size());
                        for (Element argElem : argsElems) {
-                               if (argElem.hasAttribute("value"))
-                                       args.put(argElem.getAttribute("name"), argElem
-                                                       .getAttribute("value"));
-                               else if (argElem.hasAttribute("ref"))
-                                       args.put(argElem.getAttribute("name"),
-                                                       new RuntimeBeanReference(argElem
-                                                                       .getAttribute("ref")));
+                               Object value = NamespaceUtils.parseValue(argElem,
+                                               parserContext, builder.getBeanDefinition(), null);
+                               if (value != null)
+                                       args.put(argElem.getAttribute("name"), value);
                                else
                                        throw new SlcException("No value defined.");
                        }
-                       builder.getRawBeanDefinition().getConstructorArgumentValues()
+                       builder.getBeanDefinition().getConstructorArgumentValues()
                                        .addGenericArgumentValue(args);
                }
 
@@ -78,13 +76,15 @@ public class FlowBeanDefinitionParser extends
                        for (int i = 0; i < execElems.size(); i++) {
                                Element child = execElems.get(i);
                                String name = child.getLocalName();
-                               if ("bean".equals(name) || "ref".equals(name)) {
-                                       Object target = parseBeanReference((Element) child,
-                                                       parserContext, builder);
-                                       executables.add(target);
-                               } else if ("flow".equals(name)) {
+                               if (DomUtils.nodeNameEquals(child, "bean")
+                                               || DomUtils.nodeNameEquals(child, "ref")) {
+                                       // Object target = parseBeanReference((Element) child,
+                                       // parserContext, builder);
+                                       executables.add(NamespaceUtils.parseBeanReference(child,
+                                                       parserContext, builder.getBeanDefinition()));
+                               } else if (DomUtils.nodeNameEquals(child, "flow")) {
                                        throw new SlcException(
-                                                       "Nested flows are not yet supported use a standard ref to another flow.");
+                                                       "Nested flows are not yet supported, use a standard ref to another flow.");
                                } else {
                                        throw new SlcException("Unsupported child '" + name + "'");
                                }
@@ -99,11 +99,11 @@ public class FlowBeanDefinitionParser extends
        }
 
        // parse nested bean definition
-       private Object parseBeanReference(Element element,
-                       ParserContext parserContext, BeanDefinitionBuilder builder) {
-               return parserContext.getDelegate().parsePropertySubElement(element,
-                               builder.getBeanDefinition());
-       }
+       // private Object parseBeanReference(Element element,
+       // ParserContext parserContext, BeanDefinitionBuilder builder) {
+       // return parserContext.getDelegate().parsePropertySubElement(element,
+       // builder.getBeanDefinition());
+       // }
 
        protected boolean shouldGenerateIdAsFallback() {
                return true;