From 872c12a626fff934410c6116db94886c9e5ad651 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 9 Aug 2002 03:36:09 +0000 Subject: [PATCH] Marshaller and dispatcher class templates. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1635 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- lib/dispatcher.tmpl | 49 +++++++++++++++++++++++++++++ lib/marshaller.tmpl | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 lib/dispatcher.tmpl create mode 100644 lib/marshaller.tmpl diff --git a/lib/dispatcher.tmpl b/lib/dispatcher.tmpl new file mode 100644 index 000000000..f9b1f1f0e --- /dev/null +++ b/lib/dispatcher.tmpl @@ -0,0 +1,49 @@ +// +// $Id: dispatcher.tmpl,v 1.1 2002/08/09 03:36:09 mdb Exp $ + +package [% package %]; + +[% FOREACH import = imports -%] +import [% import %]; +[% END -%] + +/** + * Dispatches requests to the {@link [% name %]Provider}. + */ +public class [% name %]Dispatcher extends InvocationDispatcher +{ + /** + * Creates a dispatcher that may be registered to dispatch invocation + * service requests for the specified provider. + */ + public [% name %]Dispatcher ([% name %]Provider provider) + { + this.provider = provider; + } + + // documentation inherited + public InvocationMarshaller createMarshaller () + { + return new [% name %]Marshaller(); + } + + // documentation inherited + public void dispatchRequest ( + ClientObject source, int methodId, Object[] args) + throws InvocationException + { + switch (methodId) { +[% FOREACH method = methods -%] + case [% name %]Marshaller.[% method.mcode %]: + (([% name %]Provider)provider).[% method.mname %]( + source, + [% method.unwrapped_args %] + ); + return; + +[% END -%] + default: + super.dispatchRequest(source, methodId, args); + } + } +} diff --git a/lib/marshaller.tmpl b/lib/marshaller.tmpl new file mode 100644 index 000000000..a58719e6d --- /dev/null +++ b/lib/marshaller.tmpl @@ -0,0 +1,75 @@ +// +// $Id: marshaller.tmpl,v 1.1 2002/08/09 03:36:09 mdb Exp $ + +package [% package %]; + +[% FOREACH import = imports -%] +import [% import %]; +[% END -%] + +/** + * Provides the implementation of the {@link [% name %]Service} interface + * that marshalls the arguments and delivers the request to the provider + * on the server. Also provides an implementation of the response listener + * interfaces that marshall the response arguments and deliver them back + * to the requesting client. + */ +public class [% name %]Marshaller extends InvocationMarshaller + implements [% name %]Service +{ +[% FOREACH l = listeners -%] + // documentation inherited + public static class [% l.name %]Marshaller extends ListenerMarshaller + implements [% l.name %]Listener + { +[% FOREACH lm = l.methods -%] + /** The method id used to dispatch {@link #[% lm.mname %]} + * responses. */ + public static final int [% lm.mcode %] = [% lm.mcodeval %]; + + // documentation inherited from interface + public void [% lm.mname %] ([% lm.arglist %]) + { + omgr.postEvent(new InvocationResponseEvent( + callerOid, requestId, [% lm.mcode %], + new Object[] { [% lm.wrapped_args %] })); + } +[% END -%] + + // documentation inherited + public void dispatchResponse (int methodId, Object[] args) + { + switch (methodId) { +[% FOREACH lm = l.methods -%] + case [% lm.mcode %]: + (([% l.name %]Listener)listener).[% lm.mname %]( + [% lm.unwrapped_args %]); + return; + +[% END -%] + default: + super.dispatchResponse(methodId, args); + } + } + } + +[% END -%] +[% FOREACH m = methods -%] + /** The method id used to dispatch {@link #[% m.mname %]} requests. */ + public static final int [% m.mcode %] = [% m.mcodeval %]; + + // documentation inherited from interface + public void [% m.mname %] ([% m.arglist %]) + { +[% FOREACH la = m.listener_args -%] + [% la.mtype %] [% la.aname %] = new [% la.mtype %](); + [% la.aname %].listener = [% la.oaname %]; +[% END -%] + sendRequest(arg1, [% m.mcode %], new Object[] { + [% m.wrapped_args %] + }); + } + +[% END -%] + // Class file generated on [% genstamp %]. +}