cf.addConstructor(new Class[]
{ StrategyRegistry.class }, null, "_registry = $1;");
BodyBuilder builder = new BodyBuilder();
MethodIterator mi = new MethodIterator(interfaceClass);
while (mi.hasNext())
{
MethodSignature sig = mi.next();
// TODO: Checks for methods that don't have at least one parameter, or don't have a
// compatible 1st parameter. Currently, we'll get a Javassist exception.
builder.clear();
builder.begin();
builder.addln("Object selector = $1;");
builder.addln(
"%s adapter = (%<s) _registry.getByInstance(selector);",
interfaceClassName);
builder.addln("return ($r) adapter.%s($$);", sig.getName());
builder.end();
cf.addMethod(Modifier.PUBLIC, sig, builder.toString());
}
if (!mi.getToString())
cf.addToString(String.format("<Strategy for %s>", interfaceClassName));
return cf.createClass();
}