@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("