]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-lib/slc/class/org/argeo/slc/ria/SlcExecutionMessage.js
2 * A generic JMS slcExecution message encapsulator.
4 qx
.Class
.define("org.argeo.slc.ria.SlcExecutionMessage", {
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.setAttributes({});
28 * The unique id identifying the message
62 * Date of the message. now() by default.
66 init
: new Date().toString()
69 * Additionnal attributes as map of key/values
78 * Add a free attribute to the message
79 * @param attName {String} Name
80 * @param attValue {String} Value
82 addAttribute: function(attName
, attValue
){
83 var attr
= this.getAttributes();
84 attr
[attName
] = attValue
;
85 this.setAttributes(attr
);
88 * Build the xml formatted message body to send
90 * @return {String} The message content as Xml
93 var builder
= new qx
.util
.StringBuilder();
94 builder
.add('<slc:slc-execution xmlns:slc="http://argeo.org/projects/slc/schemas" uuid="'+this.getUuid()+'">');
95 builder
.add('<slc:status>'+this.getStatus()+'</slc:status>');
96 builder
.add('<slc:type>'+this.getType()+'</slc:type>');
97 builder
.add('<slc:host>'+this.getHost()+'</slc:host>');
98 builder
.add('<slc:user>'+this.getUser()+'</slc:user>');
99 var attr
= this.getAttributes();
100 if(qx
.lang
.Object
.getLength(attr
)){
101 builder
.add('<slc:attributes>');
102 for(var key
in attr
){
103 builder
.add('<slc:attribute name="'+key
+'">'+attr
[key
]+'</slc:attribute>');
105 builder
.add('</slc:attributes>');
107 builder
.add('</slc:slc-execution>');
108 return builder
.get();
112 * Parse an XML answer and fill the object with it.
113 * @param slcExecXml {String} An slcExecMessage mapped in XML.
115 fromXml : function(slcExecXml
){
116 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
117 this.setStatus(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:status", NSMap
));
118 this.setType(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:type", NSMap
));
119 this.setHost(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:host", NSMap
));
120 this.setUser(org
.argeo
.ria
.util
.Element
.getSingleNodeText(slcExecXml
, "slc:user", NSMap
));
121 var attributes
= org
.argeo
.ria
.util
.Element
.selectNodes(slcExecXml
, "slc:attribute", NSMap
);
122 for(var i
=0;i
<attributes
.length
;i
++){
123 this.addAttribute(attribute
.getAttribute("name"), attribute
.firstChild
);
125 var stepsDates
= org
.argeo
.ria
.util
.Element
.selectNodes(slcExecXml
, "slc:steps/slc:slc-execution-step/slc:begin", NSMap
);
126 if(stepsDates
.length
){
127 this.setDate(org
.argeo
.ria
.util
.Element
.getSingleNodeText(stepsDates
[stepsDates
.length
-1], ".", NSMap
));