From: Olivier Capillon Date: Fri, 21 May 2010 11:01:47 +0000 (+0000) Subject: slc flow namespace extended (flow:variables, list, map, etc. in flow:arg and spec... X-Git-Tag: argeo-slc-2.1.7~1295 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=30463809ad9db9e57ea3ffce5b2b22e10ec0bf1c;p=gpl%2Fargeo-slc.git slc flow namespace extended (flow:variables, list, map, etc. in flow:arg and spec default values) git-svn-id: https://svn.argeo.org/slc/trunk@3585 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- 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 index e5738b168..726f34230 100644 --- 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 @@ -1,44 +1,36 @@ 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.Element; 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. + * Inspired by org.springframework.aop.config.ScopedProxyBeanDefinitionDecorator */ -public class ExecutionScopeDecorator implements BeanDefinitionDecorator { - private Log log = LogFactory.getLog(ExecutionScopeDecorator.class); +public class ExecutionScopeDecorator implements BeanDefinitionDecorator { + private static final String PROXY_TARGET_CLASS = "proxy-target-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; + definition.getBeanDefinition().setScope("execution"); + + boolean proxyTargetClass = true; + if (node instanceof Element) { + Element ele = (Element) node; + if (ele.hasAttribute(PROXY_TARGET_CLASS)) { + proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS)).booleanValue(); + } } + + // 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)); + + return ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass); } } 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 f092bb1ac..a1d6912aa 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,7 +10,17 @@ public class FlowNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionDecoratorForAttribute("as-flow", new AsFlowDecorator()); registerBeanDefinitionParser("param", new ParamDecorator()); -// registerBeanDefinitionDecoratorForAttribute("var", new ExecutionScopeDecorator()); + + // The objective was to replace + // - attribute scope="execution" + // - and element "aop:scoped-proxy" + // by a single attribute, using an attribute decorator + // this 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. + // It works properly with element decorators (called after all attribute + // decorators + registerBeanDefinitionDecorator("variable", new ExecutionScopeDecorator()); } } 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 884faaa21..7af852fe9 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,7 +26,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -134,6 +134,10 @@ + + + + @@ -270,6 +274,10 @@ + + + + @@ -302,15 +310,35 @@ ]]> - + + + + + - - ---> + + + + + + + + + - + \ 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 b9f035db1..6f7a22206 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 @@ -1,6 +1,8 @@ package org.argeo.slc.core.execution.xml; import org.argeo.slc.core.execution.AbstractExecutionFlowTestCase; +import org.argeo.slc.core.test.SimpleTestResult; +import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.springframework.context.ConfigurableApplicationContext; @@ -16,5 +18,30 @@ public class FlowNamespaceTest extends AbstractExecutionFlowTestCase { ((ExecutionFlow) applicationContext.getBean("flow1")).run(); ((ExecutionFlow) applicationContext.getBean("flow2")).run(); ((ExecutionFlow) applicationContext.getBean("flow3")).run(); + + validateTestResult((SimpleTestResult) applicationContext + .getBean("testResult")); } + + public void testAdvancedExecution() throws Exception { + ConfigurableApplicationContext applicationContext = createApplicationContext("advanced.xml"); + + ExecutionContext executionContext = (ExecutionContext) applicationContext + .getBean("executionContext"); + executionContext.setVariable("param2", 4); + + ((ExecutionFlow) applicationContext.getBean("flow4")).run(); + + validateTestResult((SimpleTestResult) applicationContext + .getBean("testResult")); + } + + public void testContainers() throws Exception { + ConfigurableApplicationContext applicationContext = createApplicationContext("containers.xml"); + ((ExecutionFlow) applicationContext.getBean("test.list.flow1")).run(); + ((ExecutionFlow) applicationContext.getBean("test.list.flow2")).run(); + + validateTestResult((SimpleTestResult) applicationContext + .getBean("testResult")); + } } 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 index 4745a10c1..41164516a 100644 --- 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 @@ -1,72 +1,60 @@ + + + + + + + + + spec description - - - - - - - - + flow description - - - + + + - + - - - - + - - - - - - - - - - - + + + + - + - - - + + @@ -80,22 +68,26 @@ + + - - - - - - + + + + Would fail if param 2 is not changed at execution + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/containers.xml b/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/containers.xml new file mode 100644 index 000000000..d727508de --- /dev/null +++ b/runtime/org.argeo.slc.core/src/test/resources/org/argeo/slc/core/execution/xml/containers.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + val1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + val1 + val2 + + + + + val1 + val2 + + + + + + + + + + + + + + + + + + use default value for parameter "list1" + + + val1 + + + + + + \ No newline at end of file