package $package;

import javax.annotation.Generated;

#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.
 */
${generated}
public class ${name}Marshaller extends InvocationMarshaller
    implements ${name}Service
{
#foreach ($l in $listeners)
    /**
     * Marshalls results to implementations of {@link ${name}Service.${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
#if ($l.hasParameterizedMethodArgs())
        @SuppressWarnings("unchecked")
#end
        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[] {#if($m.hasArgs(true))

            $m.getWrappedArgList(true)
        #end}$m.transport);
    }
#end
}
