}
private Class createProxyClass(String serviceId, Class serviceInterface, boolean eagerLoad,
String proxyDescription)
{
ClassFab cf = _registry.newClass(serviceInterface);
cf.addField("_creator", ObjectCreator.class);
cf.addField("_delegate", serviceInterface);
cf.addField("_shutdown", boolean.class);
cf.addConstructor(new Class[]
{ ObjectCreator.class }, null, "_creator = $1;");
addDelegateGetter(cf, serviceInterface, serviceId);
addShutdownListenerMethod(cf);
cf.proxyMethodsToDelegate(serviceInterface, "_delegate()", proxyDescription);
// For eager load services, add an eagerLoadService() method that calls _delegate(), to
// force the creation of the service.
if (eagerLoad)
{
cf.addInterface(EagerLoadServiceProxy.class);
cf.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "eagerLoadService", null,
null), "_delegate();");
}
return cf.createClass();
}