From 9d9c630a744a1d8394da90bd083461dffb03b178 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 12 Nov 2012 10:11:39 +0000 Subject: [PATCH] Revert removal of execution flow paths git-svn-id: https://svn.argeo.org/slc/trunk@5769 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../core/execution/DefaultExecutionFlow.java | 35 +++++++++++++++-- ...faultExecutionFlowDescriptorConverter.java | 9 +++-- .../generator/ExecutionFlowGenerator.java | 3 +- .../xml/FlowBeanDefinitionParser.java | 15 +++++++- .../argeo/slc/execution/ExecutionFlow.java | 6 +++ .../JcrExecutionModulesListener.java | 10 ++--- .../slc/osgi/OsgiExecutionModulesManager.java | 38 +++++++++---------- 7 files changed, 80 insertions(+), 36 deletions(-) diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java index 9f2c9dbea..20c3c7c4a 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java @@ -27,10 +27,12 @@ import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.InitializingBean; import org.springframework.validation.MapBindingResult; /** Default implementation of an execution flow. */ -public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware { +public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, + BeanNameAware { private final static Log log = LogFactory .getLog(DefaultExecutionFlow.class); @@ -39,6 +41,8 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware { private Map parameters = new HashMap(); private List executables = new ArrayList(); + private String path; + private Boolean failOnError = true; public DefaultExecutionFlow() { @@ -132,6 +136,28 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware { runnable.run(); } + public void afterPropertiesSet() throws Exception { + if (path == null) { + if (name.charAt(0) == '/') { + path = name.substring(0, name.lastIndexOf('/')); + } + } + + if (path != null) { + for (Runnable executable : executables) { + if (executable instanceof DefaultExecutionFlow) { + // so we don't need to have DefaultExecutionFlow + // implementing StructureAware + // FIXME: probably has side effects + DefaultExecutionFlow flow = (DefaultExecutionFlow) executable; + String newPath = path + '/' + flow.getName(); + flow.setPath(newPath); + log.warn(newPath + " was forcibly set on " + flow); + } + } + } + } + public void setBeanName(String name) { this.name = name; } @@ -195,9 +221,12 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware { return name.hashCode(); } - /** @deprecated does nothing */ - @Deprecated + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; } public Boolean getFailOnError() { diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java index ce523a082..a5a966215 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java @@ -164,6 +164,7 @@ public class DefaultExecutionFlowDescriptorConverter implements md.getExecutionFlows().addAll(set); } + @SuppressWarnings("deprecation") public ExecutionFlowDescriptor getExecutionFlowDescriptor( ExecutionFlow executionFlow) { if (executionFlow.getName() == null) @@ -211,10 +212,10 @@ public class DefaultExecutionFlowDescriptorConverter implements ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, values, executionSpec); -// if (executionFlow.getPath() != null) -// efd.setPath(executionFlow.getPath()); -// else -// efd.setPath(""); + if (executionFlow.getPath() != null) + efd.setPath(executionFlow.getPath()); + else + efd.setPath(""); // Takes description from spring BeanFactory bf = getBeanFactory(); diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java index 9c1b7fda6..d7abc7d56 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java @@ -124,7 +124,8 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, mpv.addPropertyValue("runnableCalls", flowDescriptor.getRunnableCalls()); mpv.addPropertyValue("sharedContextValuesMap", new RuntimeBeanReference(contextValuesBeanName)); - mpv.addPropertyValue("name", flowDescriptor.getPath() + "/" + beanName); + mpv.addPropertyValue("name", beanName); + mpv.addPropertyValue("path", flowDescriptor.getPath()); mpv.addPropertyValue("executionContext", new RuntimeBeanReference(executionContextBeanName)); 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 23b050748..7a1fc7219 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,13 +42,24 @@ public class FlowBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { private Log log = LogFactory.getLog(FlowBeanDefinitionParser.class); + /** Whether the user has already be warned on path attribute usage. */ + private Boolean warnedAboutPathAttribute = false; + @SuppressWarnings("unchecked") @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String path = element.getAttribute("path"); - if (StringUtils.hasText(path)) - log.warn("The 'path' attribute is not used anymore to build flows"); + if (StringUtils.hasText(path)) { + builder.addPropertyValue("path", path); + + // warns user only once + if (!warnedAboutPathAttribute) + log.warn("The path=\"\" attribute is deprecated" + + " and will be removed in a later release." + + " Use ."); + warnedAboutPathAttribute = true; + } String spec = element.getAttribute("spec"); if (StringUtils.hasText(spec)) diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java index 387e5eac1..f9e737ccf 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java @@ -31,4 +31,10 @@ public interface ExecutionFlow extends Runnable { * interpreted by UIs as a hierarchy; */ public String getName(); + + /** + * @deprecated will be removed in SLC 2.0, the path should be the part of + * the name with '/' + */ + public String getPath(); } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java index 541d366bf..f63acb5c0 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -243,11 +243,6 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, String relativePath, ExecutionFlowDescriptor efd) throws RepositoryException { Node flowNode = null; - // if (relativePath.startsWith("/")) - // relativePath = relativePath.substring(1); - // if (relativePath.endsWith("/")) - // relativePath = relativePath.substring(0, relativePath.length() - 1); - Iterator names = Arrays.asList(relativePath.split("/")) .iterator(); // create intermediary paths @@ -388,9 +383,12 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, * UTILITIES */ /** @return the relative path, never starts with '/' */ + @SuppressWarnings("deprecation") protected String getExecutionFlowRelativePath( ExecutionFlowDescriptor executionFlow) { - String relativePath = executionFlow.getName(); + String relativePath = executionFlow.getPath() == null ? executionFlow + .getName() : executionFlow.getPath() + '/' + + executionFlow.getName(); // we assume that it is more than one char long if (relativePath.charAt(0) == '/') relativePath = relativePath.substring(1); diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java index f85df26aa..bd38e6ca8 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java @@ -596,35 +596,33 @@ public class OsgiExecutionModulesManager extends } } + @SuppressWarnings("deprecation") protected ObjectName flowMBeanName(Module module, ExecutionFlow executionFlow) { String executionModulesPrefix = "SLCExecutionModules"; - // String path = executionFlow.getPath(); + String path = executionFlow.getPath(); String name = executionFlow.getName(); - // if (path == null && name.indexOf('/') >= 0) { - // path = name.substring(0, name.lastIndexOf('/')); - // name = name.substring(name.lastIndexOf('/')); - // } + if (path == null && name.indexOf('/') >= 0) { + path = name.substring(0, name.lastIndexOf('/')); + name = name.substring(name.lastIndexOf('/')); + } StringBuffer buf = new StringBuffer(executionModulesPrefix + ":" + "module=" + module.getName() + " [" + module.getVersion() + "],"); - // if (path != null && !path.equals("")) { - // int depth = 0; - // for (String token : path.split("/")) { - // if (!token.equals("")) { - // buf.append("path").append(depth).append('='); - // // in order to have directories first - // buf.append('/'); - // buf.append(token).append(','); - // depth++; - // } - // } - // } - - // FIXME deal with / - + if (path != null && !path.equals("")) { + int depth = 0; + for (String token : path.split("/")) { + if (!token.equals("")) { + buf.append("path").append(depth).append('='); + // in order to have directories first + buf.append('/'); + buf.append(token).append(','); + depth++; + } + } + } buf.append("name=").append(name); try { return new ObjectName(buf.toString()); -- 2.39.5