Automatically generate the provider interface when generating the FooMarshaller
and FooDispatcher. This means we will no longer be able to make FooProvider a class that directly handles FooService methods, but the savings in confusion for first time users of the framework will more than make up for the minor inconvenience. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3714 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,6 +27,7 @@ import com.threerings.presents.data.InvocationMarshaller;
|
|||||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||||
import com.threerings.presents.server.InvocationDispatcher;
|
import com.threerings.presents.server.InvocationDispatcher;
|
||||||
import com.threerings.presents.server.InvocationException;
|
import com.threerings.presents.server.InvocationException;
|
||||||
|
import com.threerings.presents.server.InvocationProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Ant task for generating invocation service marshalling and
|
* An Ant task for generating invocation service marshalling and
|
||||||
@@ -132,6 +133,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
imports.keySet().iterator());
|
imports.keySet().iterator());
|
||||||
generateDispatcher(source, sname, spackage, methods,
|
generateDispatcher(source, sname, spackage, methods,
|
||||||
imports.keySet().iterator());
|
imports.keySet().iterator());
|
||||||
|
generateProvider(source, sname, spackage, methods, listeners,
|
||||||
|
imports.keySet().iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void generateMarshaller (
|
protected void generateMarshaller (
|
||||||
@@ -217,6 +220,46 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void generateProvider (
|
||||||
|
File source, String sname, String spackage, List methods,
|
||||||
|
List listeners, Iterator imports)
|
||||||
|
{
|
||||||
|
String name = StringUtil.replace(sname, "Service", "");
|
||||||
|
String mname = StringUtil.replace(sname, "Service", "Provider");
|
||||||
|
String mpackage = StringUtil.replace(spackage, ".client", ".server");
|
||||||
|
|
||||||
|
// construct our imports list
|
||||||
|
SortableArrayList implist = new SortableArrayList();
|
||||||
|
CollectionUtil.addAll(implist, imports);
|
||||||
|
checkedAdd(implist, ClientObject.class.getName());
|
||||||
|
checkedAdd(implist, InvocationProvider.class.getName());
|
||||||
|
checkedAdd(implist, InvocationException.class.getName());
|
||||||
|
implist.sort();
|
||||||
|
|
||||||
|
VelocityContext ctx = new VelocityContext();
|
||||||
|
ctx.put("name", name);
|
||||||
|
ctx.put("package", mpackage);
|
||||||
|
ctx.put("methods", methods);
|
||||||
|
ctx.put("listeners", listeners);
|
||||||
|
ctx.put("imports", implist);
|
||||||
|
|
||||||
|
try {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
_velocity.mergeTemplate(PROVIDER_TMPL, "UTF-8", ctx, sw);
|
||||||
|
|
||||||
|
// determine the path to our provider file
|
||||||
|
String mpath = source.getPath();
|
||||||
|
mpath = StringUtil.replace(mpath, "Service", "Provider");
|
||||||
|
mpath = StringUtil.replace(mpath, "/client/", "/server/");
|
||||||
|
|
||||||
|
writeFile(mpath, sw.toString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Failed processing template");
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Specifies the path to the marshaller template. */
|
/** Specifies the path to the marshaller template. */
|
||||||
protected static final String MARSHALLER_TMPL =
|
protected static final String MARSHALLER_TMPL =
|
||||||
"com/threerings/presents/tools/marshaller.tmpl";
|
"com/threerings/presents/tools/marshaller.tmpl";
|
||||||
@@ -224,4 +267,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
/** Specifies the path to the dispatcher template. */
|
/** Specifies the path to the dispatcher template. */
|
||||||
protected static final String DISPATCHER_TMPL =
|
protected static final String DISPATCHER_TMPL =
|
||||||
"com/threerings/presents/tools/dispatcher.tmpl";
|
"com/threerings/presents/tools/dispatcher.tmpl";
|
||||||
|
|
||||||
|
/** Specifies the path to the provider template. */
|
||||||
|
protected static final String PROVIDER_TMPL =
|
||||||
|
"com/threerings/presents/tools/provider.tmpl";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,16 +119,16 @@ public abstract class InvocationTask extends Task
|
|||||||
return StringUtil.unStudlyName(method.getName()).toUpperCase();
|
return StringUtil.unStudlyName(method.getName()).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArgList ()
|
public String getArgList (boolean providerMode)
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
Class[] args = method.getParameterTypes();
|
Class[] args = method.getParameterTypes();
|
||||||
for (int ii = 0; ii < args.length; ii++) {
|
for (int ii = providerMode ? 1 : 0; ii < args.length; ii++) {
|
||||||
if (buf.length() > 0) {
|
if (buf.length() > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
buf.append(GenUtil.simpleName(args[ii]));
|
buf.append(GenUtil.simpleName(args[ii]));
|
||||||
buf.append(" arg").append(ii+1);
|
buf.append(" arg").append(providerMode ? ii : ii+1);
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class ${name}Marshaller extends InvocationMarshaller
|
|||||||
public static final int $lm.code = $velocityCount;
|
public static final int $lm.code = $velocityCount;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public void $lm.method.name ($lm.argList)
|
public void $lm.method.name ($lm.getArgList(false))
|
||||||
{
|
{
|
||||||
omgr.postEvent(new InvocationResponseEvent(
|
omgr.postEvent(new InvocationResponseEvent(
|
||||||
callerOid, requestId, $lm.code,
|
callerOid, requestId, $lm.code,
|
||||||
@@ -56,7 +56,7 @@ public class ${name}Marshaller extends InvocationMarshaller
|
|||||||
public static final int $m.code = $velocityCount;
|
public static final int $m.code = $velocityCount;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public void $m.method.name ($m.argList)
|
public void $m.method.name ($m.getArgList(false))
|
||||||
{
|
{
|
||||||
#foreach ($la in $m.listenerArgs)
|
#foreach ($la in $m.listenerArgs)
|
||||||
$la.marshaller listener$la.index = new ${la.marshaller}();
|
$la.marshaller listener$la.index = new ${la.marshaller}();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package $package;
|
||||||
|
|
||||||
|
#foreach ($import in $imports)
|
||||||
|
import $import;
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the server-side of the {@link ${name}Service}.
|
||||||
|
*/
|
||||||
|
public interface ${name}Provider extends InvocationProvider
|
||||||
|
{
|
||||||
|
#foreach ($m in $methods)
|
||||||
|
/**
|
||||||
|
* Handles a {@link ${name}Service#$m.method.name} request.
|
||||||
|
*/
|
||||||
|
#if ($m.listenerArgs.size() > 0)
|
||||||
|
public void $m.method.name (ClientObject caller, $m.getArgList(true))
|
||||||
|
throws InvocationException;
|
||||||
|
#else
|
||||||
|
public void $m.method.name (ClientObject caller, $m.getArgList(true));
|
||||||
|
#end
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user