use of org.apache.aries.proxy.InvocationListener in project aries by apache.
the class AbstractWovenProxyAdapter method writeFinalWovenProxyMethods.
/**
* Write the methods we need for wovenProxies on the highest supertype
*/
private final void writeFinalWovenProxyMethods() {
// add private fields for the Callable<Object> dispatcher
// and InvocationListener. These aren't static because we can have
// multiple instances of the same proxy class. These should not be
// serialized, or used in JPA or any other thing we can think of,
// so we annotate them as necessary
generateField(DISPATCHER_FIELD, Type.getDescriptor(Callable.class));
generateField(LISTENER_FIELD, Type.getDescriptor(InvocationListener.class));
// a general methodAdapter field that we will use to with GeneratorAdapters
// to create the methods required to implement WovenProxy
GeneratorAdapter methodAdapter;
// add a method for unwrapping the dispatcher
methodAdapter = getMethodGenerator(PUBLIC_GENERATED_METHOD_ACCESS, new Method("org_apache_aries_proxy_weaving_WovenProxy_unwrap", DISPATCHER_TYPE, NO_ARGS));
// /////////////////////////////////////////////////////
// Implement the method
// load this to get the field
methodAdapter.loadThis();
// get the dispatcher field and return
methodAdapter.getField(typeBeingWoven, DISPATCHER_FIELD, DISPATCHER_TYPE);
methodAdapter.returnValue();
methodAdapter.endMethod();
// /////////////////////////////////////////////////////
// add a method for checking if the dispatcher is set
methodAdapter = getMethodGenerator(PUBLIC_GENERATED_METHOD_ACCESS, new Method("org_apache_aries_proxy_weaving_WovenProxy_isProxyInstance", Type.BOOLEAN_TYPE, NO_ARGS));
// /////////////////////////////////////////////////////
// Implement the method
// load this to get the field
methodAdapter.loadThis();
// make a label for return true
Label returnTrueLabel = methodAdapter.newLabel();
// get the dispatcher field for the stack
methodAdapter.getField(typeBeingWoven, DISPATCHER_FIELD, DISPATCHER_TYPE);
// check if the dispatcher was non-null and goto return true if it was
methodAdapter.ifNonNull(returnTrueLabel);
methodAdapter.loadThis();
// get the listener field for the stack
methodAdapter.getField(typeBeingWoven, LISTENER_FIELD, LISTENER_TYPE);
// check if the listener field was non-null and goto return true if it was
methodAdapter.ifNonNull(returnTrueLabel);
// return false if we haven't jumped anywhere
methodAdapter.push(false);
methodAdapter.returnValue();
// mark the returnTrueLable
methodAdapter.mark(returnTrueLabel);
methodAdapter.push(true);
methodAdapter.returnValue();
// end the method
methodAdapter.endMethod();
// ///////////////////////////////////////////////////////
}
use of org.apache.aries.proxy.InvocationListener in project aries by apache.
the class ReferencesTest method testWiring.
public void testWiring() throws Exception {
ComponentDefinitionRegistryImpl registry = parse("/test-references.xml");
ProxyManager proxyManager = new AbstractProxyManager() {
@Override
protected Object createNewProxy(Bundle bundle, Collection<Class<?>> classes, Callable<Object> objectCallable, InvocationListener invocationListener) throws UnableToProxyException {
return new Object();
}
@Override
protected InvocationHandler getInvocationHandler(Object o) {
return null;
}
@Override
protected boolean isProxyClass(Class<?> aClass) {
return false;
}
};
Repository repository = new TestBlueprintContainer(registry, proxyManager).getRepository();
repository.create("refItf");
try {
repository.create("refClsErr");
fail("Should have failed");
} catch (ComponentDefinitionException e) {
}
repository.create("refClsOk");
}
Aggregations