use of org.apache.aries.proxy.weaving.WovenProxy in project aries by apache.
the class AbstractWovenProxyAdapter method visit.
public final void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
LOGGER.debug(Constants.LOG_ENTRY, "visit", new Object[] { version, access, name, signature, superName, interfaces });
// always update to the most recent version of the JVM
version = JAVA_CLASS_VERSION;
superType = Type.getType("L" + superName + ";");
try {
// we only want to implement WovenProxy once in the hierarchy.
// It's best to do this as high up as possible so we check the
// super. By loading it we may end up weaving it, but that's a good thing!
Class<?> superClass = Class.forName(superName.replace('/', '.'), false, loader);
isSerializable = Serializable.class.isAssignableFrom(superClass) || Arrays.asList(interfaces).contains(Type.getInternalName(Serializable.class)) || checkInterfacesForSerializability(interfaces);
if (!!!WovenProxy.class.isAssignableFrom(superClass)) {
// We have found a type we need to add WovenProxy information to
implementWovenProxy = true;
if (superClass != Object.class) {
//If our superclass isn't Object, it means we didn't weave all the way
//to the top of the hierarchy. This means we need to override all the
//methods defined on our parent so that they can be intercepted!
nonObjectSupers.add(superClass);
Class<?> nextSuper = superClass.getSuperclass();
while (nextSuper != Object.class) {
nonObjectSupers.add(nextSuper);
nextSuper = nextSuper.getSuperclass();
}
//Don't use reflection - it can be dangerous
superHasNoArgsConstructor = superHasNoArgsConstructor(superName, name);
} else {
superHasNoArgsConstructor = true;
}
// re-work the interfaces list to include WovenProxy
String[] interfacesPlusWovenProxy = new String[interfaces.length + 1];
System.arraycopy(interfaces, 0, interfacesPlusWovenProxy, 0, interfaces.length);
interfacesPlusWovenProxy[interfaces.length] = WOVEN_PROXY_IFACE_TYPE.getInternalName();
// Write the class header including WovenProxy.
cv.visit(version, access, name, signature, superName, interfacesPlusWovenProxy);
} else {
// Already has a woven proxy parent, but we still need to write the
// header!
cv.visit(version, access, name, signature, superName, interfaces);
}
} catch (ClassNotFoundException e) {
// If this happens we're about to hit bigger trouble on verify, so we
// should stop weaving and fail. Make sure we don't cause the hook to
// throw an error though.
UnableToProxyException u = new UnableToProxyException(name, e);
cannotLoadSuperClassException(superName, u);
}
}
use of org.apache.aries.proxy.weaving.WovenProxy in project aries by apache.
the class WeavingProxyTest method checkProxyController.
@Test(expected = FinalModifierException.class)
public void checkProxyController() throws Exception {
bundleContext.registerService(ProxyWeavingController.class.getName(), new ProxyWeavingController() {
public boolean shouldWeave(WovenClass arg0, WeavingHelper arg1) {
return false;
}
}, null);
Bundle b = bundleContext.getBundle();
Callable<Object> c = new TestCallable();
Collection<Class<?>> classes = new ArrayList<Class<?>>();
// Don't use anonymous inner class in this test as IBM and Sun load it at a different time
// For IBM JDK, the anonymous inner class will be loaded prior to the controller is registered.
Callable<?> callable = new TestFinalDelegate();
classes.add(callable.getClass());
Object o = mgr.createDelegatingProxy(b, classes, c, callable);
if (o instanceof WovenProxy)
fail("Proxy should not have been woven!");
}
use of org.apache.aries.proxy.weaving.WovenProxy in project aries by apache.
the class WeavingProxyTest method checkProxyFinalClass.
/**
* This test does two things. First of all it checks that we can proxy a final
* class. It also validates that the class implements WovenProxy, and that the
* delegation still works
*/
@Test
public void checkProxyFinalClass() throws Exception {
Bundle b = bundleContext.getBundle();
TestCallable dispatcher = new TestCallable();
TestCallable template = new TestCallable();
Collection<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(TestCallable.class);
@SuppressWarnings("unchecked") Callable<Object> o = (Callable<Object>) mgr.createDelegatingProxy(b, classes, dispatcher, template);
if (!!!(o instanceof WovenProxy))
fail("Proxy should be woven!");
Object inner = new Integer(3);
dispatcher.setReturn(new TestCallable());
((TestCallable) dispatcher.call()).setReturn(inner);
assertSame("Should return the same object", inner, o.call());
}
use of org.apache.aries.proxy.weaving.WovenProxy in project aries by apache.
the class WovenProxyPlusSubclassGeneratorTest method getProxyInstance.
@Override
protected Object getProxyInstance(Class<?> proxyClass, InvocationListener listener) {
WovenProxy proxy = (WovenProxy) getProxyInstance(proxyClass);
proxy = proxy.org_apache_aries_proxy_weaving_WovenProxy_createNewProxyInstance(new SingleInstanceDispatcher(proxy), listener);
return proxy;
}
use of org.apache.aries.proxy.weaving.WovenProxy in project aries by apache.
the class WovenProxyGeneratorTest method getProxyInstance.
@Override
protected Object getProxyInstance(Class<?> proxyClass, InvocationListener listener) {
WovenProxy proxy = (WovenProxy) getProxyInstance(proxyClass);
proxy = proxy.org_apache_aries_proxy_weaving_WovenProxy_createNewProxyInstance(new SingleInstanceDispatcher(proxy), listener);
return proxy;
}
Aggregations