From b9336fb77b251c886f7bc09ffafeb9818a50eb94 Mon Sep 17 00:00:00 2001 From: Olivier Capillon Date: Tue, 18 May 2010 08:39:00 +0000 Subject: [PATCH] FlowNamespace extended (flows in flows, param in arg) git-svn-id: https://svn.argeo.org/slc/trunk@3580 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../core/execution/InstantiationManager.java | 27 +++-- .../xml/ExecutionScopeDecorator.java | 44 ++++++++ .../xml/FlowBeanDefinitionParser.java | 25 ++--- .../execution/xml/FlowNamespaceHandler.java | 1 + .../xml/SpecBeanDefinitionParser.java | 3 + .../slc/core/execution/xml/slc-flow-0.12.xsd | 17 ++- .../core/execution/xml/FlowNamespaceTest.java | 7 ++ .../argeo/slc/core/execution/xml/advanced.xml | 101 ++++++++++++++++++ 8 files changed, 198 insertions(+), 27 deletions(-) create mode 100644 runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java create mode 100644 runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/advanced.xml diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java index eb6ce5347..c3692a550 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java @@ -26,14 +26,14 @@ public class InstantiationManager { } public void flowInitializationStarted(ExecutionFlow flow, String flowName) { - if (log.isTraceEnabled()) - log.trace("Start initialization of " + flow.hashCode() + " (" - + flow + " - " + flow.getClass() + ")"); - // set the flow name if it is DefaultExecutionFlow if (flow instanceof DefaultExecutionFlow) { ((DefaultExecutionFlow) flow).setBeanName(flowName); } + + if (log.isTraceEnabled()) + log.trace("Start initialization of " + flow.hashCode() + " (" + + flow + " - " + flow.getClass() + ")"); // log.info("# flowInitializationStarted " + flowName); // create a stack for this thread if there is none @@ -47,12 +47,19 @@ public class InstantiationManager { if (log.isTraceEnabled()) log.trace("Finish initialization of " + flow.hashCode() + " (" + flow + " - " + flow.getClass() + ")"); - ExecutionFlow registeredFlow = flowStack.get().pop(); - if (registeredFlow != null) { - if (!flow.getName().equals(registeredFlow.getName())) - throw new SlcException("Current flow is " + flow); - // log.info("# flowInitializationFinished " + flowName); - // initializingFlow.set(null); + + if(flowStack.get() != null) { + ExecutionFlow registeredFlow = flowStack.get().pop(); + if (registeredFlow != null) { + if (!flow.getName().equals(registeredFlow.getName())) + throw new SlcException("Current flow is " + flow); + // log.info("# flowInitializationFinished " + flowName); + // initializingFlow.set(null); + } + } + else { + // happens for flows imported as services + log.warn("flowInitializationFinished - Flow Stack is null"); } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java new file mode 100644 index 000000000..e5738b168 --- /dev/null +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/ExecutionScopeDecorator.java @@ -0,0 +1,44 @@ +package org.argeo.slc.core.execution.xml; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.parsing.BeanComponentDefinition; +import org.springframework.beans.factory.xml.BeanDefinitionDecorator; +import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Node; + +/** + * Inspired by org.springframework.aop.config.AopNamespaceHandler + * Conceived to replace Element "aop:scoped-proxy" by an attribute. + * Does not work correctly with other attribute decorators (e.g. + * p namespace) since this decorator needs to be called after all + * properties have been set on target bean. + */ +public class ExecutionScopeDecorator implements BeanDefinitionDecorator { + private Log log = LogFactory.getLog(ExecutionScopeDecorator.class); + + public BeanDefinitionHolder decorate(Node node, + BeanDefinitionHolder definition, ParserContext parserContext) { + + Boolean isVar = Boolean.valueOf(node.getNodeValue()); + + if(isVar) { + definition.getBeanDefinition().setScope("execution"); + + boolean proxyTargetClass = true; + + // Register the original bean definition as it will be referenced by the scoped proxy and is relevant for tooling (validation, navigation). + String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName()); + parserContext.getReaderContext().fireComponentRegistered(new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName)); + + log.debug("Decorating bean " + definition.getBeanName()); + + return ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass); + } + else { + return definition; + } + } +} diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java index 30fc5926c..8594e956e 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java @@ -42,6 +42,10 @@ public class FlowBeanDefinitionParser extends if (StringUtils.hasText(parent)) builder.setParentName(parent); + + builder.getBeanDefinition().setDescription(DomUtils.getChildElementValueByTagName(element, + "description")); + List execElems = new ArrayList(); List argsElems = new ArrayList(); NodeList nodeList = element.getChildNodes(); @@ -50,7 +54,7 @@ public class FlowBeanDefinitionParser extends if (node instanceof Element) { if (DomUtils.nodeNameEquals(node, "arg")) argsElems.add((Element) node); - else + else if(!DomUtils.nodeNameEquals(node, "description")) execElems.add((Element) node); } } @@ -73,21 +77,10 @@ public class FlowBeanDefinitionParser extends // Executables if (execElems.size() != 0) { ManagedList executables = new ManagedList(execElems.size()); - for (int i = 0; i < execElems.size(); i++) { - Element child = execElems.get(i); - String name = child.getLocalName(); - if (DomUtils.nodeNameEquals(child, "bean") - || DomUtils.nodeNameEquals(child, "ref")) { - // Object target = parseBeanReference((Element) child, - // parserContext, builder); - executables.add(NamespaceUtils.parseBeanOrReference(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."); - } else { - throw new SlcException("Unsupported child '" + name + "'"); - } + for(Element child : execElems) { + // child validity check is performed in xsd + executables.add(NamespaceUtils.parseBeanOrReference(child, + parserContext, builder.getBeanDefinition())); } builder.addPropertyValue("executables", executables); } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowNamespaceHandler.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowNamespaceHandler.java index db6484011..f092bb1ac 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowNamespaceHandler.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowNamespaceHandler.java @@ -10,6 +10,7 @@ public class FlowNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionDecoratorForAttribute("as-flow", new AsFlowDecorator()); registerBeanDefinitionParser("param", new ParamDecorator()); +// registerBeanDefinitionDecoratorForAttribute("var", new ExecutionScopeDecorator()); } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java index 2e970e096..e5a4531ab 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java @@ -26,6 +26,9 @@ public class SpecBeanDefinitionParser extends @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + builder.getBeanDefinition().setDescription(DomUtils.getChildElementValueByTagName(element, + "description")); + ManagedMap attributes = new ManagedMap(); // Primitives diff --git a/runtime/org.argeo.slc.core/src/main/resources/org/argeo/slc/core/execution/xml/slc-flow-0.12.xsd b/runtime/org.argeo.slc.core/src/main/resources/org/argeo/slc/core/execution/xml/slc-flow-0.12.xsd index 439528e0f..884faaa21 100644 --- a/runtime/org.argeo.slc.core/src/main/resources/org/argeo/slc/core/execution/xml/slc-flow-0.12.xsd +++ b/runtime/org.argeo.slc.core/src/main/resources/org/argeo/slc/core/execution/xml/slc-flow-0.12.xsd @@ -26,6 +26,7 @@ + @@ -41,6 +42,7 @@ + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/xml/FlowNamespaceTest.java b/runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/xml/FlowNamespaceTest.java index 119a1e5b0..b9f035db1 100644 --- a/runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/xml/FlowNamespaceTest.java +++ b/runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/xml/FlowNamespaceTest.java @@ -10,4 +10,11 @@ public class FlowNamespaceTest extends AbstractExecutionFlowTestCase { ((ExecutionFlow) applicationContext.getBean("canonic-ns.001")).run(); ((ExecutionFlow) applicationContext.getBean("canonic-ns.002")).run(); } + + public void testAdvanced() throws Exception { + ConfigurableApplicationContext applicationContext = createApplicationContext("advanced.xml"); + ((ExecutionFlow) applicationContext.getBean("flow1")).run(); + ((ExecutionFlow) applicationContext.getBean("flow2")).run(); + ((ExecutionFlow) applicationContext.getBean("flow3")).run(); + } } diff --git a/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/advanced.xml b/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/advanced.xml new file mode 100644 index 000000000..4745a10c1 --- /dev/null +++ b/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/advanced.xml @@ -0,0 +1,101 @@ + + + + + + + + spec description + + + + + + + + + + + + + + flow description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.39.2