Files
narya/src/java/com/threerings/presents/tools/marshaller.tmpl
T
Andrzej Kapolka ee74481cad Much work on generalizing the notion of message "transport" and
allowing the use of annotations to customize transport for 
DObject fields and service/receiver methods.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5099 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-05-16 01:47:33 +00:00

78 lines
2.3 KiB
Cheetah

package $package;
#foreach ($import in $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 in $listeners)
/**
* Marshalls results to implementations of {@link ${l.name}Listener}.
*/
public static class ${l.name}Marshaller extends ListenerMarshaller
implements ${l.name}Listener
{
#foreach ($lm in $l.methods)
/** The method id used to dispatch {@link #$lm.method.name}
* responses. */
public static final int $lm.code = $velocityCount;
// from interface ${l.name}Marshaller
public void $lm.method.name ($lm.getArgList(false))
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, $lm.code,
new Object[] { $lm.getWrappedArgList(false) }, transport));
}
#end
@Override // from InvocationMarshaller
public void dispatchResponse (int methodId, Object[] args)
{
switch (methodId) {
#foreach ($lm in $l.methods)
case $lm.code:
((${l.name}Listener)listener).${lm.method.name}(
${lm.getUnwrappedArgList(true)});
return;
#end
default:
super.dispatchResponse(methodId, args);
return;
}
}
}
#end
#foreach ($m in $methods)
#if ($velocityCount > 1)
#end
/** The method id used to dispatch {@link #$m.method.name} requests. */
public static final int $m.code = $velocityCount;
// from interface ${name}Service
public void $m.method.name ($m.getArgList(false))
{
#foreach ($la in $m.listenerArgs)
$la.marshaller listener$la.index = new ${la.marshaller}();
listener${la.index}.listener = arg$la.index;
#end
sendRequest(arg1, $m.code, new Object[] {
$m.getWrappedArgList(true)
}, $m.transport);
}
#end
}