]>
Commit | Line | Data |
---|---|---|
2f01fe57 AD |
1 | /* |
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 | |
5 | */ | |
6 | ||
7 | ||
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){ | |
12 | if(_1){ | |
13 | if((dojo.isString(_1))||(_1 instanceof dojo._Url)){ | |
14 | if(_1 instanceof dojo._Url){ | |
15 | var _2=_1+""; | |
16 | }else{ | |
17 | _2=_1; | |
18 | } | |
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); | |
23 | }); | |
24 | }else{ | |
25 | if(_1.smdStr){ | |
26 | this.processSmd(dojo.eval("("+_1.smdStr+")")); | |
27 | }else{ | |
28 | if(_1.serviceUrl){ | |
29 | this.serviceUrl=_1.serviceUrl; | |
30 | } | |
31 | this.timeout=_1.timeout||3000; | |
32 | if("strictArgChecks" in _1){ | |
33 | this.strictArgChecks=_1.strictArgChecks; | |
34 | } | |
35 | this.processSmd(_1); | |
36 | } | |
37 | } | |
38 | } | |
39 | },strictArgChecks:true,serviceUrl:"",parseResults:function(_4){ | |
40 | return _4; | |
41 | },errorCallback:function(_5){ | |
42 | return function(_6){ | |
43 | _5.errback(_6.message); | |
44 | }; | |
45 | },resultCallback:function(_7){ | |
46 | var tf=dojo.hitch(this,function(_8){ | |
47 | if(_8.error!=null){ | |
48 | var _9; | |
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; | |
53 | }else{ | |
54 | _9=new Error(_8.error); | |
55 | } | |
56 | _9.id=_8.id; | |
57 | _9.errorObject=_8; | |
58 | _7.errback(_9); | |
59 | }else{ | |
60 | _7.callback(this.parseResults(_8)); | |
61 | } | |
62 | }); | |
63 | return tf; | |
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."); | |
69 | }else{ | |
70 | this.bind(_a,dojo._toArray(arguments),_d,_c); | |
71 | } | |
72 | return _d; | |
73 | }); | |
74 | },processSmd:function(_e){ | |
75 | if(_e.methods){ | |
76 | dojo.forEach(_e.methods,function(m){ | |
77 | if(m&&m.name){ | |
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+"()"); | |
81 | } | |
82 | } | |
83 | },this); | |
84 | } | |
85 | this.serviceUrl=_e.serviceUrl||_e.serviceURL; | |
86 | this.required=_e.required; | |
87 | this.smd=_e; | |
88 | }}); | |
89 | } |