<@doc> A channel represents a connection to a remote server. The BaseChannel is the abstract base class from which all channel classes are derived. Instances of this class are created automatically by the system, and should not be created directly. (c) SAP AG 2003-2006. All rights reserved. Class BaseChannel; static readonly property compatability = {product:/visual composer/i, protocol:/(iis\/plain)|(j2ee\/dev)/i, version:/7\.1\.4/}; <@doc> Constructs and initializes an BaseChannel object The unique channel identifier constructor(id) this.id = id; end property channelResponse =""; <@doc>Gets the channel's domain readonly property domain = ''; <@doc>Gets the error encountered during the last operation on this channel, if any readonly property error = ''; <@doc>Gets the number of error encountered during the last operation on this channel, if any readonly property errorNumber = ''; <@doc>Gets the channel's identifier readonly property id = ''; <@doc>Indicates whether the channel is currently online (connected to a remote server) readonly property online = false; <@doc>Gets the channel's communication protocol readonly property protocol = ''; <@doc>Gets the friendly display name for the channel's server readonly property serverName = ''; <@doc>Gets the channel's server address readonly property serverUrl = ''; <@doc>Gets the channel's server version readonly property serverVer = ''; <@doc>Gets the connection start time readonly property since = ^Date; /////////////////////////////////////////////////////////////////////// // METHODS <@doc> Connects the channel to the server Returns ~true if the channel was successfully connected; otherwise, returns ~false method connect() if (this.isConnected()) return true; // channel is already connected this.error = ""; this.online = false; this.manifest = null; // Obtain server info var product = '#SYS[PRODUCT_NAME]'; var protocol = '#SYS[SERVER_PROTOCOL]'; var version = '#SYS[SERVER_VERSION]'; var srvname = '#SYS[SERVER_LABEL]'; var err; // Validate server info var c=this.getProperty('compatability'); if (!c.product.test(product)) { err = 'unrecognized #SYS[PRODUCT_NAME] server'; } else if (!c.protocol.test(protocol)) { err = 'unsupported #SYS[PRODUCT_NAME] protocol '+protocol; } else if (!c.version.test(version)) { err = 'incompatible #SYS[PRODUCT_NAME] version '+version; } if (err) { this.error = 'Unable to open models library at specified address ('+LOWER(err)+')'; this.notifyConnection(false); return false; } // Connection succeeded this.protocol = protocol; this.serverUrl = this.getNormalizedAddress(); this.serverName = srvname; this.serverVer = version; this.notifyConnection(true); return true; end <@doc> Disconnects the channel Returns ~true if the channel was successfully disconnected; otherwise, returns ~false method disconnect() this.error = ''; this.online = false; this.protocol = ''; this.serverName = ''; this.serverUrl = ''; this.serverVer = ''; this.since = null; this.manifest = null; this.notifyConnection(false); end <@doc> Checks whether the channel is already connected The test results method isConnected() return this.online; end <@doc> Notifies about a change in the channel connection status The new channel connection status method notifyConnection(status) this.online = BOOL(status); this.since = this.online ? new Date() : null; _notifyChannelConnection(this.id, this.online) end <@doc scope="private"> Returns the normalized channel's server address The normalized address, or an empty string in case of errors method getNormalizedAddress() var address = $CTL.studioUrl; address = address.replace(/\\/g, '/'); if (address.slice(-1) != '/') address += '/'; if (address.indexOf(':\/\/') < 0) address = 'http:\/\/'+address; return TRIM(address); end <@doc scope="private"> Gets the absolute address of a specified service on this channel Service name Optional parameters string to append to the service address The absolute address of the requested service method getServiceAddress(service, params) if (!this.online) return ''; switch (this.protocol) { case 'iis/plain': return this.serverUrl+"ServiceDispatcher.asp"; //service.replace(/\./g,'/')+'.asp'+(params ? '?'+params : ''); case 'j2ee/dev' : return '#SYS[SERVICE_CHANNEL]'; default: return ''; } end <@doc> Returns a string representation of this channel The string representation of this channel override method toString() return 'Channel '+this.id; end method constSubXML(param) // This method will retun a xml containing metadata for the param passed var stringToReturn =""; var stringToReturn =""; var paramType = typeof param; stringToReturn += ""; stringToReturn += ""; }else{ // Its an object var subString = ""; stringToReturn += "object' classname='" ; // found out its type var objectType = ""; var subXMLForObject = ""; for(var objectVariable in param){ if(ISARRAY(param[objectVariable])){ var type = "array"; var name = objectVariable; // value will become an param[objectVariable] subXMLForObject +=this.createSubNodeForArray(type,name,param[objectVariable]); }else if(objectVariable.match("_objectType")){ objectType = param[objectVariable]; }else if(!(objectVariable.match("setProperty") || objectVariable.match("getProperty") || objectVariable.match("isa") || objectVariable.match("Class") || objectVariable.match("Constructor") || objectVariable.match("_NAME_"))){ var tempType = typeof param[objectVariable]; if( tempType != 'object'){ subXMLForObject += this.createSubNodeForPrimitive(tempType,objectVariable,param[objectVariable]) }else{ var t; for(var tempVar in param[objectVariable]){ if(tempVar.match("_objectType")){ t = param[objectVariable][tempVar]; break; } } subXMLForObject += this.createSubNodeForObject(t,objectVariable,param[objectVariable]) } } } stringToReturn += objectType + "'>"; stringToReturn += subXMLForObject; } } stringToReturn += ""; return stringToReturn ; end method createNodeForArray(type,value) var startRetValue = "" retValue = startRetValue + retValue +""; return retValue; end method createSubNodeForArray(type,name,value) var startRetValue = "" retValue = startRetValue + retValue +""; return retValue; end method createSubNodeForObject(type,name,value) var retValue = ""; for(var tempVar in value){ if(ISARRAY(value[tempVar])){ var arrayType = "array"; var arrayname = tempVar; retValue += this.createSubNodeForArray(arrayType,arrayname,value[tempVar]); }else if(!(tempVar.match("setProperty") || tempVar.match("getProperty") || tempVar.match("isa") || tempVar.match("Class") || tempVar.match("Constructor") || tempVar.match("_NAME_")|| tempVar.match("_objectType"))){ var typeOfTempvar = typeof value[tempVar]; if( typeOfTempvar != 'object'){ retValue += this.createSubNodeForPrimitive(typeOfTempvar,tempVar,value[tempVar]); }else { var t; for(var temp in value[tempVar]){ if(temp.match("_objectType")){ t = value[tempVar][temp]; break; } } retValue += this.createSubNodeForObject(t,tempVar,value[tempVar]); } } } return retValue+""; end method createSubNodeForPrimitive(type,name,value) return ""; end /////////////////////////////////////////////////////////////////////// <@doc scope="private"> Creates a string which represents an XML that consists of the given parameters Service name Name of the service function which will get the generated string Array of parameters A string which represents an XML that consists of the given parameters method constXML(servicename,operation, params) var strRequest= ""; if(params!=null) { for (var i=0; i< params.length; i++ ) { // pass every parameter to constSubXMl for getting its corresponding sub xml strRequest += this.constSubXML(params[i]); } } strRequest= strRequest + ""; // GK: Due to Microsoft bug a request which is a multiply of 4092 crashes the browser // For complete thread see: http://groups-beta.google.com/group/microsoft.public.winhttp/browse_thread/thread/80f3bf99c77391d6/a7a04bc37472c950#a7a04bc37472c950 // Patch for Microsoft bug can be found in http://download.microsoft.com/download/6/5/C/65C2875D-A3C8-4290-9594-C5777EE5D9A7/MSXML4SP2-KB887606-x86-ENU.exe if (strRequest.length % 4092 == 0) { strRequest += " "; } return strRequest; end <@doc scope="private"> Indicates whether the given results are successful or not Returns ~true if results indicates of success; otherwise, returns ~false method resultSuccess(result) return (result && result._objectType!="com.sap.ds.core.types.Fault"); end <@doc scope="private"> Throws an error in case the the given results indicates of a failure An object Callback function to invoke when an error is encountered method exitOnError(result, onfailure) if (result && result._objectType && result._objectType =="com.sap.ds.core.types.Fault") { if (onfailure != null) onfailure(result); throw new Error(result.reason); } end <@doc scope="private"> Constructs the given XML into an object An XML Callback function to invoke upon successfull completion of the service Callback function to invoke when an error is encountered An object which was constructed of the given XML method analyseresults(xmlresp, onsuccess, onfailure) if (!xmlresp || (xmlresp && xmlresp.documentElement==null)){ return; } var result=constructobject(xmlresp.documentElement.xml,this); this.exitOnError(result, onfailure); if (typeof(result) != 'object') { var parsedXML = PARSEXML(result); var err = CHECKXML(parsedXML); if (!err) { result = parsedXML.documentElement; } } if(onsuccess!=null) onsuccess(this.handleArray(result)); else return this.handleArray(result); function constructobject(res,channel) { var doc=PARSEXML(res); var index= res.indexOf(" Returnes the values of the given array object An array object The values in the array oject method handleArray(nodevalue) if (typeof nodevalue == 'object') { if (nodevalue._objectType == "com.sap.ds.core.impl.soaptypes.StringArrayHolder") { return nodevalue.values; } else return nodevalue; } return nodevalue; end <@doc scope="private"> // TODO method dologout() if(this.online==true) { var strRequest= this.constXML("Environment","doLogout",null); this.sendRequest(strRequest); this.online=false; } end <@doc> Executes a specified function in the specified service and returns the execution results. This method reconstructs the result into an object. The request is send by POST method. Service name Name of the service function to execute Array of function parameters Callback function to invoke upon successfull completion of the service execution Callback function to invoke when an error is encountered XML document containing the results, or null in case of errors method executeService(servicename, operation, params, onsuccess, onfailure) return this.executeServlet(servicename, operation, params, onsuccess, onfailure, null, false); end method executeServiceAsync(servicename, operation, params, onsuccess, onfailure, asyncparams) return this.executeServletAsync(servicename, operation, params, onsuccess, onfailure, asyncparams, null, false); end <@doc> Executes a specified function in the specified service and returns the execution results. This method reconstructs the result into an object If no request method was mentioned then the request is send by GET method. Service name Name of the service function to execute Array of function parameters Callback function to invoke upon successfull completion of the service execution Callback function to invoke when an error is encountered url of server to send the request to if to send the request using GET method (or POST) XML document containing the results, or null in case of errors method executeServlet(servicename, operation, params, onsuccess, onfailure, url, GETMethod) GETMethod = NVL(GETMethod, true); var response = this.execute(servicename, operation, params, true, null, null, null, url, GETMethod); if (!response) return null; if (this.protocol == 'iis/plain') { if (response.documentElement.nodeName == "ERROR") { this.error = response.documentElement.text; return null; } return response.documentElement; } try { var res = this.analyseresults(response, onsuccess, onfailure); } catch (e) { if (e) { #LOG[2, e.description]; this.error = e.description; } return null; } return res; end method executeServletAsync(servicename, operation, params, onsuccess, onfailure, asyncparams, url, GETMethod) GETMethod = NVL(GETMethod, true); var response = this.execute(servicename, operation, params, true, onsuccess, onfailure, asyncparams, url, GETMethod); if (!response) return null; return response; end <@doc> Executes a specified function in the specified service. The result XML is returned raw (See @executeService). Service name Name of the service function to execute Array of function parameters Indicates whether to return the result of the service execution call this method if succeeded retrieving the data from server call this method if failed retrieving the data from server url of the server to send the request to if to send the request using GET method (or POST) XML document containing the results, or null in case of errors. This will be returned in case that the returnResult parameter is true method execute(servicename, operation, params, returnResult, onsuccess, onfailure, asyncparams, url, GETMethod) if (this.online==false) { this.online=true; } if(!url) url = this.getServiceAddress(servicename, params); var request = this.getXMLRequest(servicename, operation, params); var response = this.sendRequest(url, request, servicename, operation, onsuccess, onfailure, asyncparams, GETMethod); if ( returnResult ) return response; end <@doc scope="private"> Creates an XML request from the given parameters Service name Name of a service function Array of function parameters An XML request method getXMLRequest(servicename, operation, params) { return this.constXML(servicename, operation, params); } <@doc scope="private"> Sends the given request to the given URL URL to send the request to An XML request to send Service name Operation if to send the request using GET method (or POST) Returns the response (XML file) if the operation was successful; otherwise, returns null method sendRequest(url, request, servicename, operation, onsuccess, onfailure, asyncparams, GETMethod) GETMethod = NVL(GETMethod,false); if('#SYS[COM_SAP_VDS_PLATFORMSPECIFIC_PROPERTIES_PLATFORM]'=="eclipse" ) { if(servicename=="VCServiceAdapter"||servicename=="CompLibManager"||servicename=="FileWriter"||servicename=="ComponentWriter"||servicename=="ComponentReader"||servicename=="SearchService"||servicename=="VCbuilder"||servicename=="ComponentsSearchProvider" || servicename=="VCMassConfigService"||servicename=="ExportImportController"||servicename=="DrillDownUtil"||servicename=="BreakoutUtil" || servicename=="DebuggerService" ||servicename=="VCSDIProxyService" || servicename=="VCUIHandler" || servicename=="SRComponentHelper" || servicename=="VCActionHandler") { var frm = $ENV.document.all["_vcrespform"]; frm._vcobjectinfo.value = "serviceExecution"; frm.serviceName.value = servicename; frm.methodName.value = operation; frm.requestParam.value = request; frm.needsWorkspaceLock.value = "yes"; frm.responseXML.value = ""; $ENV.channel2.channelResponse = null; if(servicename=="BreakoutUtil" || servicename=="SearchService" || servicename=="VCMassConfigService") frm.needsWorkspaceLock.value = "no"; frm.submit(); response = $ENV.channel2.channelResponse; if(response != null){ if(typeof onsuccess != 'function'){ return PARSEXML(response); } else{ onsuccess(PARSEXML(response),asyncparams); } return PARSEXML(response); } } } try { if (!this.online) return null; this.error = ''; var res; if (GETMethod) { res = GETXML(url, onsuccess, asyncparams, onfailure); } else { res = POSTXML(request, url, onsuccess, asyncparams, onfailure); } if (!res) throw new Error(-1, "Failed to invoke the function: '" + operation + "' of the remote service:'" + servicename + "'"); return res; } catch (e) { this.error = e.description; this.errorNumber = e.number; return null; } end