]>
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/Message.js
0140311db4ab2c7895e7611147a70486fb77d982
2 * A generic JMS slcExecution message encapsulator.
4 qx
.Class
.define("org.argeo.slc.ria.execution.Message", {
5 extend
: qx
.core
.Object
,
8 * @param uuid {String} The Uuid of the message. If none is passed, one is generated.
10 construct : function(uuid
){
16 var itoh
= '0123456789ABCDEF';
17 for (var i
= 0; i
<36; i
++) s
[i
] = Math
.floor(Math
.random()*0x10);
18 s
[14] = 4; // Set 4 high bits of time_high field to version
19 s
[19] = (s
[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
20 for (var i
= 0; i
<36; i
++) s
[i
] = itoh
[s
[i
]];
21 s
[8] = s
[13] = s
[18] = s
[23] = '-';
22 this.setUuid(s
.join('').toLowerCase());
24 this.setBatchEntrySpecs([]);
25 this.setAttributes({});
29 * The unique id identifying the message
63 * Date of the message. now() by default.
67 init
: new Date().toString()
70 * Additionnal attributes as map of key/values
82 * Add a free attribute to the message
83 * @param attName {String} Name
84 * @param attValue {String} Value
86 addAttribute: function(attName
, attValue
){
87 var attr
= this.getAttributes();
88 attr
[attName
] = attValue
;
89 this.setAttributes(attr
);
92 addBatchEntrySpec : function(entrySpec
){
93 this.getBatchEntrySpecs().push(entrySpec
);
97 * Build the xml formatted message body to send
99 * @return {String} The message content as Xml
102 var builder
= new qx
.util
.StringBuilder();
103 builder
.add('<slc:slc-execution xmlns:slc="http://argeo.org/projects/slc/schemas" uuid="'+this.getUuid()+'">');
104 builder
.add('<slc:status>'+this.getStatus()+'</slc:status>');
105 builder
.add('<slc:type>'+this.getType()+'</slc:type>');
106 builder
.add('<slc:host>'+this.getHost()+'</slc:host>');
107 builder
.add('<slc:user>'+this.getUser()+'</slc:user>');
108 var flows
= this.getBatchEntrySpecs();
110 builder
.add('<realized-flows>');
111 for(var i
=0;i
<flows
.length
;i
++){
112 builder
.add(flows
[i
].toXml());
114 builder
.add('</realized-flows>');
116 var attr
= this.getAttributes();
117 if(qx
.lang
.Object
.getLength(attr
)){
118 builder
.add('<slc:attributes>');
119 for(var key
in attr
){
120 builder
.add('<slc:attribute name="'+key
+'">'+attr
[key
]+'</slc:attribute>');
122 builder
.add('</slc:attributes>');
124 builder
.add('</slc:slc-execution>');
125 return builder
.get();
129 * Parse an XML answer and fill the object with it.
130 * @param slcExecXml {String} An slcExecMessage mapped in XML.
132 fromXml : function(slcExecXml
){
133 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
134 this.setStatus(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:status", NSMap
));
135 this.setType(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:type", NSMap
));
136 this.setHost(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:host", NSMap
));
137 this.setUser(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:user", NSMap
));
138 var attributes
= org
.argeo
.ria
.util
.Element
.selectNodes(slcExecXml
, "slc:attribute", NSMap
);
139 for(var i
=0;i
<attributes
.length
;i
++){
140 this.addAttribute(attribute
.getAttribute("name"), attribute
.firstChild
);
142 var stepsDates
= org
.argeo
.ria
.util
.Element
.selectNodes(slcExecXml
, "slc:steps/slc:slc-execution-step/slc:begin", NSMap
);
143 if(stepsDates
.length
){
144 this.setDate(org
.argeo
.ria
.util
.Element
.getSingleNodeText(stepsDates
[stepsDates
.length
-1], ".", NSMap
));