X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Forg.argeo.slc.ria%2Fsrc%2Fargeo-ria-lib%2Fslc%2Fclass%2Forg%2Fargeo%2Fslc%2Fria%2Fexecution%2FMessage.js;fp=server%2Forg.argeo.slc.ria%2Fsrc%2Fargeo-ria-lib%2Fslc%2Fclass%2Forg%2Fargeo%2Fslc%2Fria%2Fexecution%2FMessage.js;h=0140311db4ab2c7895e7611147a70486fb77d982;hb=d8e9131cdd34b663a03008df8eb97616694259ce;hp=0000000000000000000000000000000000000000;hpb=9b1896a43d37f6f58374a732fd23912fd26a6cf3;p=gpl%2Fargeo-slc.git diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Message.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Message.js new file mode 100644 index 000000000..0140311db --- /dev/null +++ b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Message.js @@ -0,0 +1,148 @@ +/** + * A generic JMS slcExecution message encapsulator. + */ +qx.Class.define("org.argeo.slc.ria.execution.Message", { + extend : qx.core.Object, + /** + * New instance + * @param uuid {String} The Uuid of the message. If none is passed, one is generated. + */ + construct : function(uuid){ + this.base(arguments); + if(uuid){ + this.setUuid(uuid); + }else{ + var s = []; + var itoh = '0123456789ABCDEF'; + for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10); + s[14] = 4; // Set 4 high bits of time_high field to version + s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence + for (var i = 0; i <36; i++) s[i] = itoh[s[i]]; + s[8] = s[13] = s[18] = s[23] = '-'; + this.setUuid(s.join('').toLowerCase()); + } + this.setBatchEntrySpecs([]); + this.setAttributes({}); + }, + properties : { + /** + * The unique id identifying the message + */ + uuid : { + check : "String" + }, + /** + * Execution status + */ + status : { + check : "String", + init : "STARTED" + }, + /** + * Execution type + */ + type : { + check : "String", + init : "slcAnt" + }, + /** + * Execution Host + */ + host : { + check : "String", + init : "localhost" + }, + /** + * Execution User + */ + user : { + check : "String", + init : "user" + }, + /** + * Date of the message. now() by default. + */ + date : { + check : "String", + init : new Date().toString() + }, + /** + * Additionnal attributes as map of key/values + */ + attributes : { + check : "Map" + }, + batchEntrySpecs : { + check : "Array" + } + }, + members : { + + /** + * Add a free attribute to the message + * @param attName {String} Name + * @param attValue {String} Value + */ + addAttribute: function(attName, attValue){ + var attr = this.getAttributes(); + attr[attName] = attValue; + this.setAttributes(attr); + }, + + addBatchEntrySpec : function(entrySpec){ + this.getBatchEntrySpecs().push(entrySpec); + }, + + /** + * Build the xml formatted message body to send + * + * @return {String} The message content as Xml + */ + toXml : function (){ + var builder = new qx.util.StringBuilder(); + builder.add(''); + builder.add(''+this.getStatus()+''); + builder.add(''+this.getType()+''); + builder.add(''+this.getHost()+''); + builder.add(''+this.getUser()+''); + var flows = this.getBatchEntrySpecs(); + if(flows.length){ + builder.add(''); + for(var i=0;i'); + } + var attr = this.getAttributes(); + if(qx.lang.Object.getLength(attr)){ + builder.add(''); + for(var key in attr){ + builder.add(''+attr[key]+''); + } + builder.add(''); + } + builder.add(''); + return builder.get(); + }, + + /** + * Parse an XML answer and fill the object with it. + * @param slcExecXml {String} An slcExecMessage mapped in XML. + */ + fromXml : function(slcExecXml){ + var NSMap = {slc:"http://argeo.org/projects/slc/schemas"}; + this.setStatus(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:status", NSMap)); + this.setType(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:type", NSMap)); + this.setHost(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:host", NSMap)); + this.setUser(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:user", NSMap)); + var attributes = org.argeo.ria.util.Element.selectNodes(slcExecXml, "slc:attribute", NSMap); + for(var i=0;i