From 006e9a660a4edb4b3815f5a96e4366f80dbcc3ea Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 30 Jul 2009 19:57:54 +0000 Subject: [PATCH] Flowdescriptor ordering git-svn-id: https://svn.argeo.org/slc/trunk@2842 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- ...faultExecutionFlowDescriptorConverter.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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 e10b4bc76..1ff50e0db 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 @@ -1,8 +1,11 @@ package org.argeo.slc.core.execution; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; +import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -22,6 +25,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; public class DefaultExecutionFlowDescriptorConverter implements ExecutionFlowDescriptorConverter, ApplicationContextAware { @@ -82,6 +86,8 @@ public class DefaultExecutionFlowDescriptorConverter implements public void addFlowsToDescriptor(ExecutionModuleDescriptor md, Map executionFlows) { + SortedSet set = new TreeSet( + new ExecutionFlowDescriptorComparator()); for (String name : executionFlows.keySet()) { ExecutionFlow executionFlow = executionFlows.get(name); @@ -128,6 +134,8 @@ public class DefaultExecutionFlowDescriptorConverter implements values, executionSpec); if (executionFlow.getPath() != null) efd.setPath(executionFlow.getPath()); + else + efd.setPath(""); // Takes description from spring BeanDefinition bd = getBeanFactory().getBeanDefinition(name); @@ -138,8 +146,10 @@ public class DefaultExecutionFlowDescriptorConverter implements md.getExecutionSpecs().add(executionSpec); // Add execution flow - md.getExecutionFlows().add(efd); + set.add(efd); + // md.getExecutionFlows().add(efd); } + md.getExecutionFlows().addAll(set); } @SuppressWarnings(value = { "unchecked" }) @@ -204,4 +214,26 @@ public class DefaultExecutionFlowDescriptorConverter implements this.applicationContext = applicationContext; } + private static class ExecutionFlowDescriptorComparator implements + Comparator { + public int compare(ExecutionFlowDescriptor o1, + ExecutionFlowDescriptor o2) { + if (StringUtils.hasText(o1.getPath()) + && StringUtils.hasText(o2.getPath())) { + return o1.getPath().compareTo(o2.getPath()); + } else if (!StringUtils.hasText(o1.getPath()) + && StringUtils.hasText(o2.getPath())) { + return 1; + } else if (StringUtils.hasText(o1.getPath()) + && !StringUtils.hasText(o2.getPath())) { + return -1; + } else if (!StringUtils.hasText(o1.getPath()) + && !StringUtils.hasText(o2.getPath())) { + return o1.getName().compareTo(o2.getName()); + } else { + return 0; + } + } + + } } -- 2.39.2