+ throw new SlcException("Cannot add flow " + efd + " from module "
+ + module, e);
+ }
+
+ }
+
+ protected Node createExecutionFlowNode(Node moduleNode,
+ String relativePath, ExecutionFlowDescriptor efd)
+ throws RepositoryException {
+ Node flowNode = null;
+ Iterator<String> names = Arrays.asList(relativePath.split("/"))
+ .iterator();
+ // create intermediary paths
+ Node currNode = moduleNode;
+ while (names.hasNext()) {
+ String name = names.next();
+ if (currNode.hasNode(name))
+ currNode = currNode.getNode(name);
+ else {
+ if (names.hasNext())
+ currNode = currNode.addNode(name);
+ else
+ flowNode = currNode.addNode(name,
+ SlcTypes.SLC_EXECUTION_FLOW);
+ }
+ }
+
+ // name, description
+ flowNode.setProperty(SLC_NAME, efd.getName());
+ String[] tokens = relativePath.split("/");
+ String endName = tokens[tokens.length - 1];
+ flowNode.setProperty(Property.JCR_TITLE, endName);
+ if (efd.getDescription() != null
+ && !efd.getDescription().trim().equals("")) {
+ flowNode.setProperty(Property.JCR_DESCRIPTION, efd.getDescription());
+ } else {
+ flowNode.setProperty(Property.JCR_DESCRIPTION, endName);
+ }
+
+ // execution spec
+ ExecutionSpec executionSpec = efd.getExecutionSpec();
+ String esName = executionSpec.getName();
+ if (!(esName == null || esName.equals(ExecutionSpec.INTERNAL_NAME))) {
+ // reference spec node
+ Node executionSpecsNode = moduleNode.hasNode(SLC_EXECUTION_SPECS) ? moduleNode
+ .getNode(SLC_EXECUTION_SPECS) : moduleNode
+ .addNode(SLC_EXECUTION_SPECS);
+ Node executionSpecNode = executionSpecsNode.addNode(esName,
+ SlcTypes.SLC_EXECUTION_SPEC);
+ executionSpecNode.setProperty(SLC_NAME, esName);
+ executionSpecNode.setProperty(Property.JCR_TITLE, esName);
+ if (executionSpec.getDescription() != null
+ && !executionSpec.getDescription().trim().equals(""))
+ executionSpecNode.setProperty(Property.JCR_DESCRIPTION,
+ executionSpec.getDescription());
+ mapExecutionSpec(executionSpecNode, executionSpec);
+ flowNode.setProperty(SLC_SPEC, executionSpecNode);
+ } else {
+ // internal spec node
+ mapExecutionSpec(flowNode, executionSpec);
+ }
+
+ // 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);
+ valueNode.setProperty(SLC_TYPE, psa.getType());
+ SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
+ (PrimitiveValue) efd.getValues().get(attr));
+ }