]> git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Module.js
Add log4j for server JCR
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / execution / Module.js
1 /**
2 * Wrapper for ExecutionModule server object
3 */
4 qx.Class.define("org.argeo.slc.ria.execution.Module", {
5
6 extend : qx.core.Object,
7
8 properties : {
9 /**
10 * The name of the module
11 */
12 name : {
13 check : "String",
14 init : ""
15 },
16 label : {
17 check : "String",
18 init : ""
19 },
20 description : {
21 check : "String",
22 init : ""
23 },
24 /**
25 * The version of the module
26 */
27 version : {
28 check : "String",
29 init : ""
30 },
31 /**
32 * All execution flows registered by their name
33 */
34 executionFlows : {
35 check : "Map"
36 },
37 /**
38 * All execution specs registered by their name
39 */
40 executionSpecs : {
41 check : "Map"
42 },
43 /**
44 * XML description (castor)
45 */
46 xmlNode : {
47 apply : "_applyXmlNode"
48 }
49 },
50
51 statics : {
52 XPATH_ROOT : "slc:execution-module-descriptor",
53 XPATH_NAME : "slc:name",
54 XPATH_LABEL : "slc:label",
55 XPATH_DESCRIPTION : "slc:description",
56 XPATH_VERSION : "slc:version",
57 XPATH_EXECUTION_FLOWS : "slc:execution-flows/slc:execution-flow-descriptor",
58 XPATH_EXECUTION_SPECS : "slc:execution-specs/slc:default-execution-spec"
59 },
60
61 construct : function(){
62 this.base(arguments);
63 this.setExecutionFlows({});
64 this.setExecutionSpecs({});
65 },
66
67 members : {
68 /**
69 * Add an execution flow to this module
70 * @param executionFlow {org.argeo.slc.ria.execution.Flow} An instance of execution.Flow
71 */
72 addExecutionFlow : function(executionFlow){
73 var spec = this.getExecutionSpecByName(executionFlow.getExecutionSpecName());
74 if(spec){
75 executionFlow.setExecutionSpec(spec);
76 }else{
77 this.error("Warning, reference to an unknown ExecutionSpec : "+executionFlow.getExecutionSpecName());
78 }
79 this.getExecutionFlows()[executionFlow.getName()] = executionFlow;
80 },
81
82 /**
83 * Add an execution Spec to this module
84 * @param executionSpec {org.argeo.slc.ria.execution.Spec} An instance of ExecutionSpec
85 */
86 addExecutionSpec : function(executionSpec){
87 this.getExecutionSpecs()[executionSpec.getName()] = executionSpec;
88 },
89 /**
90 * Find an execution spec by its name
91 * @param name {String} Name of the spec
92 * @return {org.argeo.slc.ria.execution.Spec} The spec
93 */
94 getExecutionSpecByName : function(name){
95 return this.getExecutionSpecs()[name];
96 },
97
98 /**
99 * Find an execution flow by its name
100 * @param name {String} name of the flow
101 * @return {org.argeo.slc.ria.execution.Flow} The flow
102 */
103 getExecutionFlowByName : function(name){
104 return this.getExecutionFlows()[name];
105 },
106
107 moduleDataToXml : function(){
108 var xmlData = '<slc:module-name>'+this.getName()+'</slc:module-name>';
109 xmlData += '<slc:module-version>'+this.getVersion()+'</slc:module-version>';
110 return xmlData;
111 },
112
113 /**
114 * An xml node containing the castor mapped description of this object
115 * @param xmlNode {Node}
116 */
117 _applyXmlNode : function(xmlNode){
118 var appendRoot = "";
119 if(xmlNode.nodeName != this.self(arguments).XPATH_ROOT){
120 appendRoot = this.self(arguments).XPATH_ROOT+"/";
121 }
122 // Parse now
123 this.setName(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, appendRoot + this.self(arguments).XPATH_NAME) || "Not Found");
124 this.setVersion(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, appendRoot + this.self(arguments).XPATH_VERSION));
125 this.setLabel(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, appendRoot + this.self(arguments).XPATH_LABEL) || this.getName());
126 this.setDescription(org.argeo.ria.util.Element.getSingleNodeText(xmlNode, appendRoot + this.self(arguments).XPATH_DESCRIPTION) || "");
127
128 // Parse Specs first
129 var specs = org.argeo.ria.util.Element.selectNodes(xmlNode, appendRoot + this.self(arguments).XPATH_EXECUTION_SPECS);
130 if(specs){
131 for(i=0; i< specs.length;i++){
132 var execSpec = new org.argeo.slc.ria.execution.Spec();
133 execSpec.setXmlNode(specs[i]);
134 this.addExecutionSpec(execSpec);
135 }
136 }
137 // Now parse Flows : to do AFTER specs
138 var flows = org.argeo.ria.util.Element.selectNodes(xmlNode, appendRoot + this.self(arguments).XPATH_EXECUTION_FLOWS);
139 if(flows){
140 for(var i=0;i<flows.length;i++){
141 var execFlow = new org.argeo.slc.ria.execution.Flow();
142 execFlow.setXmlNode(flows[i]);
143 this.addExecutionFlow(execFlow);
144 }
145 }
146 }
147
148 }
149
150 });