classFab.addInterface(Serializable.class);
// This is the "magic" signature that allows an object to substitute some other
// object for itself.
MethodSignature writeReplaceSig = new MethodSignature(Object.class, "writeReplace", null, new Class[]
{ ObjectStreamException.class });
classFab.addMethod(Modifier.PRIVATE, writeReplaceSig, "return token;");
// Now delegate all the methods.
String body = format("return (%s) creator.createObject();", serviceInterface.getName());
MethodSignature sig = new MethodSignature(serviceInterface, "delegate", null, null);
classFab.addMethod(Modifier.PRIVATE, sig, body);
classFab.proxyMethodsToDelegate(serviceInterface, "delegate()", description);