private Class createInnerProxyClass(Class deferredProxyClass)
{
ProxyBuilder builder = new ProxyBuilder("InnerProxy", getModule(), getConfigurationType(),
getConfigurationType(), false);
ClassFab classFab = builder.getClassFab();
classFab.addField("_deferredProxy", deferredProxyClass);
classFab.addField("_configuration", getConfigurationType());
classFab.addField("_configurationPoint", ConfigurationPointImpl.class);
BodyBuilder body = new BodyBuilder();
// The constructor remembers the outer proxy and registers itself
// with the outer proxy.
body.begin();
body.addln("this($1);");
body.addln("_deferredProxy = $2;");
body.addln("_configurationPoint = $3;");
body.addln("_deferredProxy._setInner(this);");
body.end();
classFab.addConstructor(new Class[]
{ String.class, deferredProxyClass, ConfigurationPointImpl.class }, null, body.toString());
// Method _configuration() will look up the configuration,
// then update the deferred proxy to go directly to the
// configuration, bypassing itself!
body.clear();
body.begin();
body.add("if (_configuration == null)");
body.begin();
body.add("_configuration = (");
body.add(getConfigurationType().getName());
body.addln(") _configurationPoint.constructConfiguration();");
body.add("_deferredProxy._setInner(_configuration);");
body.end();
body.add("return _configuration;");
body.end();
classFab.addMethod(
Modifier.PRIVATE | Modifier.FINAL | Modifier.SYNCHRONIZED,
new MethodSignature(getConfigurationType(), "_configuration", null, null),
body.toString());
builder.addServiceMethods("_configuration()");
// Build the implementation of interface SingletonInnerProxy
body.clear();
body.begin();
body.add("_configuration();");
body.end();
classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
"_instantiateServiceImplementation", null, null), body.toString());
classFab.addInterface(SingletonInnerProxy.class);
return classFab.createClass();
}