Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.rpc.JsonService");
12
dojo.require("dojo.rpc.RpcService");
13
dojo.require("dojo.io.*");
14
dojo.require("dojo.json");
15
dojo.require("dojo.lang.common");
16
dojo.rpc.JsonService = function (args) {
17
	if (args) {
18
		if (dojo.lang.isString(args)) {
19
			this.connect(args);
20
		} else {
21
			if (args["smdUrl"]) {
22
				this.connect(args.smdUrl);
23
			}
24
			if (args["smdStr"]) {
25
				this.processSmd(dj_eval("(" + args.smdStr + ")"));
26
			}
27
			if (args["smdObj"]) {
28
				this.processSmd(args.smdObj);
29
			}
30
			if (args["serviceUrl"]) {
31
				this.serviceUrl = args.serviceUrl;
32
			}
33
			if (typeof args["strictArgChecks"] != "undefined") {
34
				this.strictArgChecks = args.strictArgChecks;
35
			}
36
		}
37
	}
38
};
39
dojo.inherits(dojo.rpc.JsonService, dojo.rpc.RpcService);
40
dojo.extend(dojo.rpc.JsonService, {bustCache:false, contentType:"application/json-rpc", lastSubmissionId:0, callRemote:function (method, params) {
41
	var deferred = new dojo.Deferred();
42
	this.bind(method, params, deferred);
43
	return deferred;
44
}, bind:function (method, parameters, deferredRequestHandler, url) {
45
	dojo.io.bind({url:url || this.serviceUrl, postContent:this.createRequest(method, parameters), method:"POST", contentType:this.contentType, mimetype:"text/json", load:this.resultCallback(deferredRequestHandler), error:this.errorCallback(deferredRequestHandler), preventCache:this.bustCache});
46
}, createRequest:function (method, params) {
47
	var req = {"params":params, "method":method, "id":++this.lastSubmissionId};
48
	var data = dojo.json.serialize(req);
49
	dojo.debug("JsonService: JSON-RPC Request: " + data);
50
	return data;
51
}, parseResults:function (obj) {
52
	if (!obj) {
53
		return;
54
	}
55
	if (obj["Result"] != null) {
56
		return obj["Result"];
57
	} else {
58
		if (obj["result"] != null) {
59
			return obj["result"];
60
		} else {
61
			if (obj["ResultSet"]) {
62
				return obj["ResultSet"];
63
			} else {
64
				return obj;
65
			}
66
		}
67
	}
68
}});
69