Optionally generate action script listener adapters for designated services.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5814 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -143,6 +143,15 @@ public class GenServiceTask extends InvocationTask
|
||||
}
|
||||
}
|
||||
|
||||
/** Used to track services for which we should create listener adapters in actionscript. */
|
||||
public class Adapter
|
||||
{
|
||||
public void setService (String className)
|
||||
{
|
||||
_aslistenerAdapters.add(className);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the path to our ActionScript source files.
|
||||
*/
|
||||
@@ -151,12 +160,16 @@ public class GenServiceTask extends InvocationTask
|
||||
_asroot = asroot;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Providerless createProviderless ()
|
||||
{
|
||||
return new Providerless();
|
||||
}
|
||||
|
||||
public Adapter createAdapter ()
|
||||
{
|
||||
return new Adapter();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@Override
|
||||
protected void processService (File source, Class<?> service)
|
||||
@@ -454,10 +467,19 @@ public class GenServiceTask extends InvocationTask
|
||||
|
||||
sw = new StringWriter();
|
||||
_velocity.mergeTemplate(AS_LISTENER_SERVICE_TMPL, "UTF-8", ctx, sw);
|
||||
String amlpath = _asroot + File.separator + sppath +
|
||||
String aslpath = _asroot + File.separator + sppath +
|
||||
File.separator + sname + "_" +
|
||||
listener.getName() + "Listener.as";
|
||||
writeFile(amlpath, sw.toString());
|
||||
writeFile(aslpath, sw.toString());
|
||||
|
||||
if (_aslistenerAdapters.contains(sname)) {
|
||||
sw = new StringWriter();
|
||||
_velocity.mergeTemplate(AS_LISTENER_ADAPTER_SERVICE_TMPL, "UTF-8", ctx, sw);
|
||||
String aslapath = _asroot + File.separator + sppath +
|
||||
File.separator + sname + "_" +
|
||||
listener.getName() + "ListenerAdapter.as";
|
||||
writeFile(aslapath, sw.toString());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -679,6 +701,9 @@ public class GenServiceTask extends InvocationTask
|
||||
/** Services for which we should not generate provider interfaces. */
|
||||
protected HashSet<String> _providerless = Sets.newHashSet();
|
||||
|
||||
/** Services for which we should generate actionscript listener adapters. */
|
||||
protected HashSet<String> _aslistenerAdapters = Sets.newHashSet();
|
||||
|
||||
/** Specifies the path to the marshaller template. */
|
||||
protected static final String MARSHALLER_TMPL =
|
||||
"com/threerings/presents/tools/marshaller.tmpl";
|
||||
@@ -699,6 +724,10 @@ public class GenServiceTask extends InvocationTask
|
||||
protected static final String AS_LISTENER_SERVICE_TMPL =
|
||||
"com/threerings/presents/tools/service_listener_as.tmpl";
|
||||
|
||||
/** Specifies the path to the ActionScript listener adapter service template. */
|
||||
protected static final String AS_LISTENER_ADAPTER_SERVICE_TMPL =
|
||||
"com/threerings/presents/tools/service_listener_adapter_as.tmpl";
|
||||
|
||||
/** Specifies the path to the ActionScript marshaller template. */
|
||||
protected static final String AS_MARSHALLER_TMPL =
|
||||
"com/threerings/presents/tools/marshaller_as.tmpl";
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package $package {
|
||||
|
||||
#foreach ($import in $imports)
|
||||
import $import;
|
||||
#end
|
||||
|
||||
/**
|
||||
* A functional adapter for the ${name}Service_${listener.name}Listener interface.
|
||||
*/
|
||||
public class ${name}Service_${listener.name}ListenerAdapter
|
||||
implements ${name}Service_${listener.name}Listener
|
||||
{
|
||||
#set ($cparams = "")
|
||||
#foreach ($lm in $listener.methods)
|
||||
#set ($cparams = $cparams + "$lm.method.name :Function, ")
|
||||
#end
|
||||
/**
|
||||
* Creates a new $name service $listener.name listener that will delegate to the given
|
||||
* function(s). Any Function that is null will simply not be called.
|
||||
*/
|
||||
public function ${name}Service_${listener.name}ListenerAdapter (
|
||||
${cparams}failed :Function)
|
||||
{
|
||||
#foreach ($lm in $listener.methods)
|
||||
_$lm.method.name = $lm.method.name;
|
||||
#end
|
||||
_failed = failed;
|
||||
}
|
||||
#foreach ($lm in $listener.methods)
|
||||
|
||||
// from Java ${name}Service_${listener.name}Listener
|
||||
public function $lm.method.name ($lm.getASArgList(false)) :void
|
||||
{
|
||||
#set ($alist = "")
|
||||
#foreach ($type in $lm.method.getParameterTypes())
|
||||
#if ($velocityCount > 1)
|
||||
#set ($alist = $alist + ", ")
|
||||
#end
|
||||
#set ($alist = $alist + "arg$velocityCount")
|
||||
#end
|
||||
if (_$lm.method.name != null) {
|
||||
_${lm.method.name}($alist);
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
// from InvocationService_InvocationListener
|
||||
public function requestFailed (cause :String) :void
|
||||
{
|
||||
if (_failed != null) {
|
||||
_failed(cause);
|
||||
}
|
||||
}
|
||||
|
||||
#foreach ($lm in $listener.methods)
|
||||
protected var _$lm.method.name :Function;
|
||||
#end
|
||||
protected var _failed :Function;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user