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();
45 String description
= null;
46 if (flowNode
.hasProperty(Property
.JCR_DESCRIPTION
))
47 description
= flowNode
.getProperty(Property
.JCR_DESCRIPTION
)
50 Node executionModuleNode
= flowNode
.getSession().getNode(
51 SlcJcrUtils
.modulePath(flowPath
));
52 String executionModuleName
= executionModuleNode
.getProperty(
53 SLC_NAME
).getString();
54 String executionModuleVersion
= executionModuleNode
.getProperty(
55 SLC_VERSION
).getString();
57 RealizedFlow realizedFlow
= this;
58 realizedFlow
.setModuleName(executionModuleName
);
59 realizedFlow
.setModuleVersion(executionModuleVersion
);
61 // retrieve execution spec
62 DefaultExecutionSpec executionSpec
= new DefaultExecutionSpec();
63 Map
<String
, ExecutionSpecAttribute
> attrs
= readExecutionSpecAttributes(realizedFlowNode
);
64 executionSpec
.setAttributes(attrs
);
66 // set execution spec name
67 if (flowNode
.hasProperty(SlcNames
.SLC_SPEC
)) {
68 Node executionSpecNode
= flowNode
.getProperty(SLC_SPEC
)
70 executionSpec
.setBeanName(executionSpecNode
.getProperty(
71 SLC_NAME
).getString());
74 // explicitly retrieve values
75 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
76 for (String attrName
: attrs
.keySet()) {
77 ExecutionSpecAttribute attr
= attrs
.get(attrName
);
78 Object value
= attr
.getValue();
79 values
.put(attrName
, value
);
82 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(flowName
,
83 description
, values
, executionSpec
);
84 realizedFlow
.setFlowDescriptor(efd
);
86 throw new SlcException("Unsupported realized flow "
91 protected Map
<String
, ExecutionSpecAttribute
> readExecutionSpecAttributes(
94 Map
<String
, ExecutionSpecAttribute
> attrs
= new HashMap
<String
, ExecutionSpecAttribute
>();
95 for (NodeIterator nit
= node
.getNodes(); nit
.hasNext();) {
96 Node specAttrNode
= nit
.nextNode();
98 .isNodeType(SlcTypes
.SLC_PRIMITIVE_SPEC_ATTRIBUTE
)) {
99 String type
= specAttrNode
.getProperty(SLC_TYPE
)
102 if (specAttrNode
.hasProperty(SLC_VALUE
)) {
103 String valueStr
= specAttrNode
.getProperty(SLC_VALUE
)
105 value
= PrimitiveUtils
.convert(type
, valueStr
);
107 PrimitiveSpecAttribute specAttr
= new PrimitiveSpecAttribute(
109 attrs
.put(specAttrNode
.getName(), specAttr
);
110 } else if (specAttrNode
111 .isNodeType(SlcTypes
.SLC_REF_SPEC_ATTRIBUTE
)) {
112 if (!specAttrNode
.hasProperty(SLC_VALUE
)) {
115 Integer value
= (int) specAttrNode
.getProperty(SLC_VALUE
)
117 RefSpecAttribute specAttr
= new RefSpecAttribute();
118 NodeIterator children
= specAttrNode
.getNodes();
121 while (children
.hasNext()) {
122 Node child
= children
.nextNode();
124 id
= child
.getName();
127 specAttr
.setValue(id
);
128 attrs
.put(specAttrNode
.getName(), specAttr
);
130 // throw new SlcException("Unsupported spec attribute "
134 } catch (RepositoryException e
) {
135 throw new SlcException("Cannot read spec attributes from " + node
,
140 public String
getPath() {