
if(typeof org=="undefined"||org==null)
org=new Object();if(typeof org.xmlBlaster=="undefined"||org.xmlBlaster==null)
org.xmlBlaster=new Object();if(typeof org.xmlBlaster.util=="undefined"||org.xmlBlaster.util==null)
org.xmlBlaster.client=new Object();org.xmlBlaster.util.PropTO=function(key,value){this.key=key||null;if(key==null)
throw"Illegal Argument null for PropTO key";this.value=value||"";this.encoding="";this.getEncoding=function(){return(typeof this.encoding=="undefined"||this.encoding==null)?"":this.encoding;}
this.isBase64Encoding=function(){return org.xmlBlaster.util.PropTO.ENCODING_BASE64==this.getEncoding();}
this.setEncoding=function(encoding){this.encoding=encoding||"";}
this.getKey=function(){return this.key;}
this.setKey=function(key){this.key=key||"";}
this.getValue=function(){if(typeof this.value=="undefined"||this.value==null)
return"";if(this.isBase64Encoding()){try{return org.xmlBlaster.util.Base64.decode(this.value);}catch(ex){org.xmlBlaster.util.log.error("PropTO: Can't convert Base64 to UTF-8 '"+this.value+"'",ex);}}
return this.value;}
this.getValueRaw=function(){return this.value;}
this.setValue=function(value){this.value=value||"";}
this.toXml=function(){return"<p k='"+org.xmlBlaster.util.escapeXml(this.key)+"'>"+org.xmlBlaster.util.escapeXml(this.value)+"</p>";}}
org.xmlBlaster.util.PropTO.ENCODING_BASE64="base64";org.xmlBlaster.util.PropTO.ENCODING_PLAIN="";org.xmlBlaster.util.PropTO.KEY_SERVICENAME="serviceName";org.xmlBlaster.util.PropTO.KEY_TASKTYPE="taskType";org.xmlBlaster.util.PropTO.KEY_TASK="task";org.xmlBlaster.util.PropTO.KEY_TASKACK="taskAck";org.xmlBlaster.util.PropTO.KEY_TASKENCODING="taskEncoding";org.xmlBlaster.util.PropTO.VALUE_TASKENCODING_DEFAULT=org.xmlBlaster.util.PropTO.ENCODING_PLAIN;org.xmlBlaster.util.PropTO.KEY_DATA="data";org.xmlBlaster.util.PropTO.KEY_DATAENCODING="dataEncoding";org.xmlBlaster.util.PropTO.VALUE_DATAENCODING_DEFAULT=org.xmlBlaster.util.PropTO.ENCODING_PLAIN;org.xmlBlaster.util.PropTO.KEY_ERRORCODE="errorCode";org.xmlBlaster.util.PropTO.KEY_MIME="mime";org.xmlBlaster.util.PropTO.KEY_RESULTMIME="resultMime";org.xmlBlaster.util.PropTO.KEY_RESULTENCODING="resultEncoding";org.xmlBlaster.util.PropTO.KEY_RESULT="result";org.xmlBlaster.util.PropTO.KEY_BOUNCE="bounce";org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_NAMED="named";org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_DEFAULT=org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_NAMED;org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_EXACT="exact";org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_XPATH="xpath";org.xmlBlaster.util.PropTO.VALUE_TASKTYPE_UPDATE="update";org.xmlBlaster.util.PropTO.VALUE_RESULTENCODING_DEFAULT=org.xmlBlaster.util.PropTO.ENCODING_PLAIN;org.xmlBlaster.util.PropTO.KEY="k";org.xmlBlaster.util.PropTO.PROP="p";org.xmlBlaster.util.ServiceTO=function(propTOs){this.propTOs=propTOs||[];var PropTO=org.xmlBlaster.util.PropTO;this.getProps=function(){return this.propTOs;}
this.getProp=function(key){if(!org.xmlBlaster.util.isDefined(key))
return null;if(!org.xmlBlaster.util.isDefined(this.propTOs))
return null;for(var i=0,l=this.propTOs.length;i<l;i++){var propTO=this.propTOs[i];if(key==propTO.getKey())
return propTO;}
return null;}
this.getPropValue=function(key){var propTO=this.getProp(key);if(propTO==null)
return"";var val=propTO.getValue();return(!org.xmlBlaster.util.isDefined(val))?"":val;}
this.addProp=function(propTO){if(!org.xmlBlaster.util.isDefined(propTO))
return false;return this.getProps().push(propTO);}
this.setProps=function(propTOs){this.propTOs=propTOs;}
this.getServiceName=function(){return this.getPropValue(PropTO.KEY_SERVICENAME);}
this.getQueryType=function(){return this.getPropValue(PropTO.KEY_TASKTYPE);}
this.getQuery=function(){return this.getPropValue(PropTO.KEY_TASK);}
this.getTask=function(){return this.getPropValue(PropTO.KEY_TASK);}
this.isTask=function(task){return task==this.getPropValue(PropTO.KEY_TASK);}
this.getBounce=function(){return this.getPropValue(PropTO.KEY_BOUNCE);}
this.getErrorCode=function(){return this.getPropValue(PropTO.KEY_ERRORCODE);}
this.getErrorMessage=function(){var result=this.getPropValue(PropTO.KEY_RESULT);if(result==null)
result=this.getPropValue(PropTO.KEY_DATA);if(result!=null){var index=result.indexOf(":");if(index>0)
return result.substring(index+1);return result;}
return"";}
this.getErrorHtmlMessage=function(){var errorCode=this.getPropValue(PropTO.KEY_ERRORCODE);var errorMessage=this.getPropValue(PropTO.KEY_RESULT);var originalCommand=this.getPropValue(PropTO.KEY_DATA);var response="";response+="<b><font color='red'>"+errorCode+"</font></b> ";response+="<br /> "+errorMessage;response+="<br /> ("+originalCommand+")";return response;}
this.getResult=function(){return this.getPropValue(PropTO.KEY_RESULT);}
this.getResultMime=function(){return this.getPropValue(PropTO.KEY_RESULTMIME);}
this.getResultEncoding=function(){var resultEncoding=this.getPropValue(PropTO.KEY_RESULTENCODING);if(resultEncoding.length>0&&PropTO.ENCODING_BASE64!=resultEncoding){org.xmlBlaster.util.log.warn("ServiceTO: resultEncoding="+resultEncoding
+" is not supported");resultEncoding=PropTO.VALUE_RESULTENCODING_DEFAULT;}else if(resultEncoding.length==0){resultEncoding=PropTO.VALUE_RESULTENCODING_DEFAULT;}
return resultEncoding;}
this.isResultEncodingBase64=function(){return PropTO.ENCODING_BASE64==this.getResultEncoding();}
this.getDataEncoding=function(){var dataEncoding=this.getPropValue(PropTO.KEY_DATAENCODING);if(dataEncoding.length>0&&PropTO.ENCODING_BASE64!=dataEncoding){org.xmlBlaster.util.log.warn("ServiceTO: dataEncoding="+dataEncoding
+" is not supported");dataEncoding=PropTO.VALUE_DATAENCODING_DEFAULT;}else if(dataEncoding.length==0){dataEncoding=PropTO.VALUE_DATAENCODING_DEFAULT;}
return dataEncoding;}
this.isDataEncodingBase64=function(){return PropTO.ENCODING_BASE64==this.getDataEncoding();}
this.getQueryEncoding=function(){var queryEncoding=this.getPropValue(PropTO.KEY_TASKENCODING);if(queryEncoding.length>0&&PropTO.ENCODING_BASE64!=queryEncoding){org.xmlBlaster.util.log.error("ServiceTO: queryEncoding="+queryEncoding
+" is not supported");queryEncoding=PropTO.VALUE_TASKENCODING_DEFAULT;}else if(queryEncoding.length==0){queryEncoding=PropTO.VALUE_TASKENCODING_DEFAULT;}
return queryEncoding;}
this.isQueryTypeNamed=function(){var qt=this.getQueryType();if(qt.length<1)
qt=PropTO.VALUE_TASKTYPE_DEFAULT;return(PropTO.VALUE_TASKTYPE_NAMED==qt);}
this.isException=function(){return(PropTO.VALUE_RESULTMIME_EXCEPTION==this.getPropValue(PropTO.KEY_RESULTMIME));}
this.toXml=function(){var xml="<s>";for(var i=0,l=this.propTOs.length;i<l;i++){var propTO=this.propTOs[i];xml+=propTO.toXml();}
xml+="</s>";return xml;}
this.readResolve=function(){{var prop=this.getProp(PropTO.KEY_DATA);if(prop!=null)
prop.setEncoding(this.getDataEncoding());}
{var prop=this.getProp(PropTO.KEY_TASK);if(prop!=null)
prop.setEncoding(this.getQueryEncoding());}
{var prop=this.getProp(PropTO.KEY_RESULT);if(prop!=null)
prop.setEncoding(this.getResultEncoding());}
return this;}}
org.xmlBlaster.util.ServiceListTO=function(serviceTO){this.serviceTOs=new Array();if(org.xmlBlaster.util.isDefined(serviceTO)){if(typeof serviceTO.toXml=="function"){this.serviceTOs.push(serviceTO);}
else if(typeof serviceTO.push=="function"){this.serviceTOs=serviceTO;}
else{throw"IllegalArgument: ServiceListTO argument must be of type 'Array' or 'org.xmlBlaster.util.ServiceTO' but is of type "+typeof serviceTO;}}
this.addService=function(serviceTO){this.serviceTOs.push(serviceTO);}
this.getServices=function(){return this.serviceTOs;}
this.getTasks=function(){var tasks="";for(var i=0,l=this.serviceTOs.length;i<l;i++){var serviceTO=this.serviceTOs[i];if(i>0)tasks+=",";tasks+=serviceTO.getPropValue(org.xmlBlaster.util.PropTO.KEY_TASK);}
return tasks;}
this.countServices=function(){return this.serviceTOs.length;}
this.setServices=function(serviceTOs){this.serviceTOs=serviceTOs||new Array();}
this.toXml=function(){var xml="<sc>";for(var i=0,l=this.serviceTOs.length;i<l;i++){var serviceTO=this.serviceTOs[i];xml+=serviceTO.toXml();}
xml+="</sc>";return xml;}}
org.xmlBlaster.util.ServiceListTO.parse=function(xmlString){if(!org.xmlBlaster.util.isDefined(xmlString)){return null;}
var domDocument=org.xmlBlaster.util.getDOMDocument(xmlString);var rootNode=domDocument.documentElement;var serviceListTO=new org.xmlBlaster.util.ServiceListTO();var ME="service.js-ServiceListTO.parse(): ";var log=org.xmlBlaster.util.log;if(rootNode.nodeName=="parsererror"){log.error(ME+"'parsererror' for "+xmlString);return null;}
for(var i=0,l=rootNode.childNodes.length;i<l;i++){var node=rootNode.childNodes[i];if(node.nodeType!=Node.ELEMENT_NODE){var val=org.xmlBlaster.util.isDefined(node.nodeValue)?node.nodeValue:"";var tmp=org.xmlBlaster.util.trim(val);if(tmp.length==0)continue;val=": '"+val+"'";var txt="Ignoring service xml node "+org.xmlBlaster.util.getXPathLocation(node,true)+val;(node.nodeType==Node.COMMENT_NODE||node.nodeType==Node.TEXT_NODE)?org.xmlBlaster.util.log.debug(ME+txt):org.xmlBlaster.util.log.warn(ME+txt);continue;}
switch(node.nodeName){case"sc":break;case"s":var serviceTO=new org.xmlBlaster.util.ServiceTO();serviceListTO.addService(serviceTO);for(var j=0;j<node.childNodes.length;j++){var nd=node.childNodes[j];if(nd.nodeName!="p"){if(nd.nodeName!="#text")
log.error(ME+"Expected <p> tag but got <"+nd.nodeName+">: "+xmlString);continue;}
var key=nd.getAttribute('k');var value=org.xmlBlaster.util.collectTextFromNodeChilds(nd);var propTO=new org.xmlBlaster.util.PropTO(key,value);serviceTO.addProp(propTO);}
serviceTO.readResolve();break;default:log.warn(ME+"("+org.xmlBlaster.util.getXPathLocation(node,true)+"): Ignoring xmlBlaster service tag");break;}}
return serviceListTO;}