source: [view]
define("dojo/rpc/RpcService", ["dojo"], function(dojo) {
dojo.declare("dojo.rpc.RpcService", null, {
constructor: function(args){
//summary:
//Take a string as a url to retrieve an smd or an object that is an smd or partial smd to use
//as a definition for the service
//
// args: object
// Takes a number of properties as kwArgs for defining the service. It also
// accepts a string. When passed a string, it is treated as a url from
// which it should synchronously retrieve an smd file. Otherwise it is a kwArgs
// object. It accepts serviceUrl, to manually define a url for the rpc service
// allowing the rpc system to be used without an smd definition. strictArgChecks
// forces the system to verify that the # of arguments provided in a call
// matches those defined in the smd. smdString allows a developer to pass
// a jsonString directly, which will be converted into an object or alternatively
// smdObject is accepts an smdObject directly.
//
if(args){
//if the arg is a string, we assume it is a url to retrieve an smd definition from
if( (dojo.isString(args)) || (args instanceof dojo._Url)){
if (args instanceof dojo._Url){
var url = args + "";
}else{
url = args;
}
var def = dojo.xhrGet({
url: url,
handleAs: "json-comment-optional",
sync: true
});
def.addCallback(this, "processSmd");
def.addErrback(function() {
throw new Error("Unable to load SMD from " + args);
});
}else if(args.smdStr){
this.processSmd(dojo.eval("("+args.smdStr+")"));
}else{
// otherwise we assume it's an arguments object with the following
// (optional) properties:
// - serviceUrl
// - strictArgChecks
// - smdStr
// - smdObj
if(args.serviceUrl){
this.serviceUrl = args.serviceUrl;
}
this.timeout = args.timeout || 3000;
if("strictArgChecks" in args){
this.strictArgChecks = args.strictArgChecks;
}
this.processSmd(args);
}
}
},
strictArgChecks: true,
serviceUrl: "",
parseResults: function(obj){
// summary
// parse the results coming back from an rpc request. this
// base implementation, just returns the full object
// subclasses should parse and only return the actual results
// obj: Object
// Object that is the return results from an rpc request
return obj;