]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java
Merge JCR, OSGi and Ant support into SLC Core
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionModulesListener.java
index 541d366bf78b2b74fb27b3d422f77ccd4530a265..ea734a8bbd6da7eed8c427b5321b7e74af6e5832 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -243,13 +243,9 @@ 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);
+               List<String> pathTokens = Arrays.asList(relativePath.split("/"));
 
-               Iterator<String> names = Arrays.asList(relativePath.split("/"))
-                               .iterator();
+               Iterator<String> names = pathTokens.iterator();
                // create intermediary paths
                Node currNode = moduleNode;
                while (names.hasNext()) {
@@ -267,8 +263,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
 
                // name, description
                flowNode.setProperty(SLC_NAME, efd.getName());
-               String[] tokens = relativePath.split("/");
-               String endName = tokens[tokens.length - 1];
+               String endName = pathTokens.get(pathTokens.size() - 1);
                flowNode.setProperty(Property.JCR_TITLE, endName);
                if (efd.getDescription() != null
                                && !efd.getDescription().trim().equals("")) {
@@ -301,13 +296,14 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        flowNode.setProperty(SLC_SPEC, executionSpecNode);
                }
 
-               // values
+               // flow values
                for (String attr : efd.getValues().keySet()) {
                        ExecutionSpecAttribute esa = executionSpec.getAttributes()
                                        .get(attr);
                        if (esa instanceof PrimitiveSpecAttribute) {
                                PrimitiveSpecAttribute psa = (PrimitiveSpecAttribute) esa;
-                               Node valueNode = flowNode.addNode(attr);
+                               // if spec reference there will be no node at this stage
+                               Node valueNode = JcrUtils.getOrAdd(flowNode, attr);
                                valueNode.setProperty(SLC_TYPE, psa.getType());
                                SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
                                                (PrimitiveValue) efd.getValues().get(attr));
@@ -388,9 +384,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);