1 package org
.argeo
.slc
.jcr
.execution
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.argeo
.slc
.core
.execution
.DefaultExecutionSpec
;
13 import org
.argeo
.slc
.core
.execution
.PrimitiveSpecAttribute
;
14 import org
.argeo
.slc
.core
.execution
.PrimitiveUtils
;
15 import org
.argeo
.slc
.core
.execution
.RefSpecAttribute
;
16 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
17 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
18 import org
.argeo
.slc
.execution
.RealizedFlow
;
19 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
20 import org
.argeo
.slc
.jcr
.SlcNames
;
21 import org
.argeo
.slc
.jcr
.SlcTypes
;
23 public class JcrRealizedFlow
extends RealizedFlow
implements SlcNames
{
24 private static final long serialVersionUID
= -3709453850260712001L;
27 public JcrRealizedFlow(Node node
) {
29 this.path
= node
.getPath();
31 } catch (RepositoryException e
) {
32 throw new SlcException("Cannot initialize from " + node
, e
);
36 protected void loadFromNode(Node realizedFlowNode
)
37 throws RepositoryException
{
38 if (realizedFlowNode
.hasNode(SLC_ADDRESS
)) {
39 String flowPath
= realizedFlowNode
.getNode(SLC_ADDRESS
)
40 .getProperty(Property
.JCR_PATH
).getString();
41 // TODO: convert to local path if remote
43 Node flowNode
= realizedFlowNode
.getSession().getNode(flowPath
);
44 String flowName
= flowNode
.getProperty(SLC_NAME
).getString();
46 Node executionModuleNode
= flowNode
.getSession().getNode(
47 SlcJcrUtils
.modulePath(flowPath
));
48 String executionModuleName
= executionModuleNode
.getProperty(
49 SLC_NAME
).getString();
50 String executionModuleVersion
= executionModuleNode
.getProperty(
51 SLC_VERSION
).getString();
53 RealizedFlow realizedFlow
= this;
54 realizedFlow
.setModuleName(executionModuleName
);
55 realizedFlow
.setModuleVersion(executionModuleVersion
);
57 // retrieve execution spec
58 DefaultExecutionSpec executionSpec
= new DefaultExecutionSpec();
59 Map
<String
, ExecutionSpecAttribute
> attrs
= readExecutionSpecAttributes(realizedFlowNode
);
60 executionSpec
.setAttributes(attrs
);
62 // set execution spec name
63 if (flowNode
.hasProperty(SlcNames
.SLC_SPEC
)) {
64 Node executionSpecNode
= flowNode
.getProperty(SLC_SPEC
)
66 executionSpec
.setBeanName(executionSpecNode
.getProperty(
67 SLC_NAME
).getString());
70 // explicitly retrieve values
71 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
72 for (String attrName
: attrs
.keySet()) {
73 ExecutionSpecAttribute attr
= attrs
.get(attrName
);
74 Object value
= attr
.getValue();
75 values
.put(attrName
, value
);
78 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(flowName
,
79 values
, executionSpec
);
80 realizedFlow
.setFlowDescriptor(efd
);
82 throw new SlcException("Unsupported realized flow "
87 protected Map
<String
, ExecutionSpecAttribute
> readExecutionSpecAttributes(
90 Map
<String
, ExecutionSpecAttribute
> attrs
= new HashMap
<String
, ExecutionSpecAttribute
>();
91 for (NodeIterator nit
= node
.getNodes(); nit
.hasNext();) {
92 Node specAttrNode
= nit
.nextNode();
94 .isNodeType(SlcTypes
.SLC_PRIMITIVE_SPEC_ATTRIBUTE
)) {
95 String type
= specAttrNode
.getProperty(SLC_TYPE
)
98 if (specAttrNode
.hasProperty(SLC_VALUE
)) {
99 String valueStr
= specAttrNode
.getProperty(SLC_VALUE
)
101 value
= PrimitiveUtils
.convert(type
, valueStr
);
103 PrimitiveSpecAttribute specAttr
= new PrimitiveSpecAttribute(
105 attrs
.put(specAttrNode
.getName(), specAttr
);
106 } else if (specAttrNode
107 .isNodeType(SlcTypes
.SLC_REF_SPEC_ATTRIBUTE
)) {
108 if (!specAttrNode
.hasProperty(SLC_VALUE
)) {
111 Integer value
= (int) specAttrNode
.getProperty(SLC_VALUE
)
113 RefSpecAttribute specAttr
= new RefSpecAttribute();
114 NodeIterator children
= specAttrNode
.getNodes();
117 while (children
.hasNext()) {
118 Node child
= children
.nextNode();
120 id
= child
.getName();
123 specAttr
.setValue(id
);
124 attrs
.put(specAttrNode
.getName(), specAttr
);
126 // throw new SlcException("Unsupported spec attribute "
130 } catch (RepositoryException e
) {
131 throw new SlcException("Cannot read spec attributes from " + node
,
136 public String
getPath() {