123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- if(!dojo._hasResource["dojo.rpc.RpcService"]){
- dojo._hasResource["dojo.rpc.RpcService"] = true;
- dojo.provide("dojo.rpc.RpcService");
- dojo.declare("dojo.rpc.RpcService", null, {
- constructor: function(args){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(args){
-
- 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{
-
-
-
-
-
-
- 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){
-
-
-
-
-
-
- return obj;
- },
- errorCallback: function(/* dojo.Deferred */ deferredRequestHandler){
-
-
-
-
- return function(data){
- deferredRequestHandler.errback(data.message);
- };
- },
- resultCallback: function(/* dojo.Deferred */ deferredRequestHandler){
-
-
-
-
- var tf = dojo.hitch(this,
- function(obj){
- if(obj.error!=null){
- var err;
- if(typeof obj.error == 'object'){
- err = new Error(obj.error.message);
- err.code = obj.error.code;
- err.error = obj.error.error;
- }else{
- err = new Error(obj.error);
- }
- err.id = obj.id;
- err.errorObject = obj;
- deferredRequestHandler.errback(err);
- }else{
- deferredRequestHandler.callback(this.parseResults(obj));
- }
- }
- );
- return tf;
- },
- generateMethod: function(/*string*/ method, /*array*/ parameters, /*string*/ url){
-
-
-
-
-
-
-
-
- return dojo.hitch(this, function(){
- var deferredRequestHandler = new dojo.Deferred();
-
- if( (this.strictArgChecks) &&
- (parameters != null) &&
- (arguments.length != parameters.length)
- ){
-
- throw new Error("Invalid number of parameters for remote method.");
- }else{
- this.bind(method, dojo._toArray(arguments), deferredRequestHandler, url);
- }
- return deferredRequestHandler;
- });
- },
- processSmd: function(object){
-
-
-
-
-
- if(object.methods){
- dojo.forEach(object.methods, function(m){
- if(m && m.name){
- this[m.name] = this.generateMethod( m.name,
- m.parameters,
- m.url||m.serviceUrl||m.serviceURL);
- if(!dojo.isFunction(this[m.name])){
- throw new Error("RpcService: Failed to create" + m.name + "()");
-
- }
- }
- }, this);
- }
- this.serviceUrl = object.serviceUrl||object.serviceURL;
- this.required = object.required;
- this.smd = object;
- }
- });
- }
|