Search in sources :

Example 1 with ProxyWeavingController

use of org.apache.aries.proxy.weavinghook.ProxyWeavingController 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!");
}
Also used : Bundle(org.osgi.framework.Bundle) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) ArrayList(java.util.ArrayList) WovenProxy(org.apache.aries.proxy.weaving.WovenProxy) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) ProxyWeavingController(org.apache.aries.proxy.weavinghook.ProxyWeavingController) WeavingHelper(org.apache.aries.proxy.weavinghook.WeavingHelper) Test(org.junit.Test)

Example 2 with ProxyWeavingController

use of org.apache.aries.proxy.weavinghook.ProxyWeavingController in project aries by apache.

the class ProxyWeavingHook method shouldWeave.

private boolean shouldWeave(WovenClass wovenClass) {
    // assume we weave
    boolean result = true;
    Object[] cs = controllers.getServices();
    // if we have at least 1 weaving controller
    if (cs != null && cs.length > 0) {
        // first of all set to false.
        result = false;
        for (Object obj : cs) {
            ProxyWeavingController c = (ProxyWeavingController) obj;
            if (c.shouldWeave(wovenClass, this)) {
                // exit as soon as we get told to weave, otherwise keep going.
                return true;
            }
        }
    }
    return result;
}
Also used : ProxyWeavingController(org.apache.aries.proxy.weavinghook.ProxyWeavingController)

Aggregations

ProxyWeavingController (org.apache.aries.proxy.weavinghook.ProxyWeavingController)2 ArrayList (java.util.ArrayList)1 WovenProxy (org.apache.aries.proxy.weaving.WovenProxy)1 WeavingHelper (org.apache.aries.proxy.weavinghook.WeavingHelper)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 WovenClass (org.osgi.framework.hooks.weaving.WovenClass)1