2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dojo.rpc.RpcService"]){
9 dojo._hasResource["dojo.rpc.RpcService"]=true;
10 dojo.provide("dojo.rpc.RpcService");
11 dojo.declare("dojo.rpc.RpcService",null,{constructor:function(_1){
13 if((dojo.isString(_1))||(_1 instanceof dojo._Url)){
14 if(_1 instanceof dojo._Url){
19 var _3=dojo.xhrGet({url:_2,handleAs:"json-comment-optional",sync:true});
20 _3.addCallback(this,"processSmd");
21 _3.addErrback(function(){
22 throw new Error("Unable to load SMD from "+_1);
26 this.processSmd(dojo.eval("("+_1.smdStr+")"));
29 this.serviceUrl=_1.serviceUrl;
31 this.timeout=_1.timeout||3000;
32 if("strictArgChecks" in _1){
33 this.strictArgChecks=_1.strictArgChecks;
39 },strictArgChecks:true,serviceUrl:"",parseResults:function(_4){
41 },errorCallback:function(_5){
43 _5.errback(_6.message);
45 },resultCallback:function(_7){
46 var tf=dojo.hitch(this,function(_8){
49 if(typeof _8.error=="object"){
50 _9=new Error(_8.error.message);
51 _9.code=_8.error.code;
52 _9.error=_8.error.error;
54 _9=new Error(_8.error);
60 _7.callback(this.parseResults(_8));
64 },generateMethod:function(_a,_b,_c){
65 return dojo.hitch(this,function(){
66 var _d=new dojo.Deferred();
67 if((this.strictArgChecks)&&(_b!=null)&&(arguments.length!=_b.length)){
68 throw new Error("Invalid number of parameters for remote method.");
70 this.bind(_a,dojo._toArray(arguments),_d,_c);
74 },processSmd:function(_e){
76 dojo.forEach(_e.methods,function(m){
78 this[m.name]=this.generateMethod(m.name,m.parameters,m.url||m.serviceUrl||m.serviceURL);
79 if(!dojo.isFunction(this[m.name])){
80 throw new Error("RpcService: Failed to create"+m.name+"()");
85 this.serviceUrl=_e.serviceUrl||_e.serviceURL;
86 this.required=_e.required;