return jm;
}
public JavaSource generate(JavaSourceFactory pInterfaceFactory,
JavaQName pTargetClass,
ProxyGenerator.InterfaceDescription[] pDescription) {
JavaSource result = super.generate(pInterfaceFactory, pTargetClass,
pDescription);
result.clearImplements();
return result;
}
};
JavaSource proxyInterface = proxyInterfaceGenerator.generate(pFactory, getChainInterface(), interfaces);
proxyInterface.setType(JavaSource.INTERFACE);
ProxyGenerator proxyImplementationGenerator = new ProxyGenerator(){
protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
}
protected JavaConstructor getConstructor(JavaSource pJs,
InterfaceDescription[] pInterfaces) {
JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PROTECTED);
jcon.addParam(getChainInterface(), "o");
jcon.addIf("o == null");
jcon.addThrowNew(NullPointerException.class,
JavaSource.getQuoted("The supplied object must not be null."));
jcon.addEndIf();
jcon.addLine("backingObject = o;");
return jcon;
}
public JavaMethod getInterfaceMethod(JavaSource pSource,
ProxyGenerator.InterfaceDescription pDescription,
java.lang.reflect.Method pMethod) {
JavaMethod jm = pSource.newJavaMethod(pMethod);
Parameter[] parameters = jm.getParams();
JavaQName controllerInterfaceQName = JavaQNameImpl.getInstance(getControllerInterface());
jm.clearParams();
jm.addParam(controllerInterfaceQName, "pController");
for (int i = 0; i < parameters.length; i++) {
jm.addParam(parameters[i]);
}
List callParameters = new ArrayList();
callParameters.add("pController");
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
callParameters.add(", ");
callParameters.add(parameter.getName());
}
jm.addLine((void.class.equals(pMethod.getReturnType()) ? "" : " return "),
"backingObject.",
pMethod.getName(), "(", callParameters, ");");
return jm;
}
public JavaSource generate(JavaSourceFactory pImplementationFactory,
JavaQName pTargetClass,
ProxyGenerator.InterfaceDescription[] pDescription) {
JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
result.clearImplements();
result.addImplements(getChainInterface());
return result;
}
};
JavaSource proxyImplementation = proxyImplementationGenerator.generate(pFactory, getProxyClass(), interfaces);
ProxyGenerator controllerImplementationGenerator = new ProxyGenerator(){
protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
}
protected JavaConstructor getConstructor(JavaSource pJs,
InterfaceDescription[] pInterfaces) {
JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PUBLIC);
jcon.addParam(getChainInterface(), "o");
jcon.addIf("o == null");
jcon.addThrowNew(NullPointerException.class,
JavaSource.getQuoted("The supplied object must not be null."));
jcon.addEndIf();
jcon.addLine("backingObject = o;");
return jcon;
}
public JavaMethod getInterfaceMethod(JavaSource pSource,
ProxyGenerator.InterfaceDescription pDescription,
java.lang.reflect.Method pMethod) {
JavaMethod jm = pSource.newJavaMethod(pMethod);
Parameter[] parameters = jm.getParams();
List callParameters = new ArrayList();
callParameters.add("this");
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
callParameters.add(", ");
callParameters.add(parameter.getName());
}
jm.addLine((void.class.equals(pMethod.getReturnType()) ? "" : " return "),
"backingObject.",
pMethod.getName(), "(", callParameters, ");");
return jm;
}
protected JavaMethod getGetHeadOfChainMethod(JavaSource pSource) {
JavaMethod jm = pSource.newJavaMethod("getHeadOfChain",
getChainInterface(),
JavaSource.PUBLIC);
jm.addLine("return backingObject;");
return jm;
}
public JavaSource generate(JavaSourceFactory pImplementationFactory,
JavaQName pTargetClass,
ProxyGenerator.InterfaceDescription[] pDescription) {
JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
getGetHeadOfChainMethod(result);
return result;
}
};
JavaSource controllerImplementation = controllerImplementationGenerator.generate(pFactory, getImplementationClass(), interfaces);
return new JavaSource[]{controllerImplementation, proxyInterface, proxyImplementation};
}