com.threerings.presents.tools.marshaller.tmpl Maven / Gradle / Ivy
package {{package}};
{{#importGroups}}
{{#this}}
import {{this}};
{{/this}}
{{/importGroups}}
/**
* 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.
*/
{{generated}}
public class {{name}}Marshaller extends InvocationMarshaller{{typeParameters}}
implements {{name}}Service
{
{{#listeners}}
/**
* Marshalls results to implementations of {@code {{name}}Service.{{listenerName}}Listener}.
*/
public static class {{listenerName}}Marshaller extends ListenerMarshaller
implements {{listenerName}}Listener
{
{{#methods}}
/** The method id used to dispatch {@link #{{method.name}}}
* responses. */
public static final int {{code}} = {{-index}};
// from interface {{listenerName}}Marshaller
public void {{method.name}} ({{getArgList}})
{
sendResponse({{code}}, new Object[] { {{getWrappedArgList}} });
}
{{/methods}}
@Override // from InvocationMarshaller
public void dispatchResponse (int methodId, Object[] args)
{
switch (methodId) {
{{#methods}}
case {{code}}:
(({{listenerName}}Listener)listener).{{method.name}}(
{{getUnwrappedArgListAsListeners}});
return;
{{/methods}}
default:
super.dispatchResponse(methodId, args);
return;
}
}
}
{{/listeners}}
{{#methods}}
{{^-first}}
{{/-first}}
/** The method id used to dispatch {@link #{{method.name}}} requests. */
public static final int {{code}} = {{-index}};
// from interface {{name}}Service
public {{typeParams}}void {{method.name}} ({{getArgList}})
{
{{#listenerArgs}}
{{marshaller}} listener{{index}} = new {{marshaller}}();
listener{{index}}.listener = arg{{index}};
{{/listenerArgs}}
sendRequest({{code}}, new Object[] {
{{#hasArgs}}
{{getWrappedArgList}}
{{/hasArgs}}
}{{transport}});
}
{{/methods}}
}