alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (RpcService.js)

This example Struts source code file (RpcService.js) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

attempting, attempting, creating, dojo, failed, failed, invalid, method, processing, rpcservice, rpcservice, smd, smd, successfully

The Struts RpcService.js source code

/*
	Copyright (c) 2004-2006, The Dojo Foundation
	All Rights Reserved.

	Licensed under the Academic Free License version 2.1 or above OR the
	modified BSD license. For more information on Dojo licensing, see:

		http://dojotoolkit.org/community/licensing.shtml
*/



dojo.provide("dojo.rpc.RpcService");
dojo.require("dojo.io.*");
dojo.require("dojo.json");
dojo.require("dojo.lang.func");
dojo.require("dojo.Deferred");
dojo.rpc.RpcService = function (url) {
	if (url) {
		this.connect(url);
	}
};
dojo.lang.extend(dojo.rpc.RpcService, {strictArgChecks:true, serviceUrl:"", parseResults:function (obj) {
	return obj;
}, errorCallback:function (deferredRequestHandler) {
	return function (type, e) {
		deferredRequestHandler.errback(new Error(e.message));
	};
}, resultCallback:function (deferredRequestHandler) {
	var tf = dojo.lang.hitch(this, function (type, obj, e) {
		if (obj["error"] != null) {
			var err = new Error(obj.error);
			err.id = obj.id;
			deferredRequestHandler.errback(err);
		} else {
			var results = this.parseResults(obj);
			deferredRequestHandler.callback(results);
		}
	});
	return tf;
}, generateMethod:function (method, parameters, url) {
	return dojo.lang.hitch(this, function () {
		var deferredRequestHandler = new dojo.Deferred();
		if ((this.strictArgChecks) && (parameters != null) && (arguments.length != parameters.length)) {
			dojo.raise("Invalid number of parameters for remote method.");
		} else {
			this.bind(method, arguments, deferredRequestHandler, url);
		}
		return deferredRequestHandler;
	});
}, processSmd:function (object) {
	dojo.debug("RpcService: Processing returned SMD.");
	if (object.methods) {
		dojo.lang.forEach(object.methods, function (m) {
			if (m && m["name"]) {
				dojo.debug("RpcService: Creating Method: this.", m.name, "()");
				this[m.name] = this.generateMethod(m.name, m.parameters, m["url"] || m["serviceUrl"] || m["serviceURL"]);
				if (dojo.lang.isFunction(this[m.name])) {
					dojo.debug("RpcService: Successfully created", m.name, "()");
				} else {
					dojo.debug("RpcService: Failed to create", m.name, "()");
				}
			}
		}, this);
	}
	this.serviceUrl = object.serviceUrl || object.serviceURL;
	dojo.debug("RpcService: Dojo RpcService is ready for use.");
}, connect:function (smdUrl) {
	dojo.debug("RpcService: Attempting to load SMD document from:", smdUrl);
	dojo.io.bind({url:smdUrl, mimetype:"text/json", load:dojo.lang.hitch(this, function (type, object, e) {
		return this.processSmd(object);
	}), sync:true});
}});

Other Struts examples (source code examples)

Here is a short list of links related to this Struts RpcService.js source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.