Package org.apache.webbeans.proxy

Examples of org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory


        defineLifecycleInterceptors(bean, annotatedType, webBeansContext);

        if (needsProxy())
        {
            // we only need to create a proxy class for intercepted or decorated Beans
            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();

            ClassLoader classLoader = annotatedType.getJavaClass().getClassLoader();

            Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
            Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);

            proxyClass = (Class<? extends T>) pf.createProxyClass(bean, classLoader, annotatedType.getJavaClass(), businessMethods, nonInterceptedMethods);

            // now we collect the post-construct and pre-destroy interceptors

        }
    }
View Full Code Here


        defineLifecycleInterceptors(bean, annotatedType, webBeansContext);

        if (needsProxy())
        {
            // we only need to create a proxy class for intercepted or decorated Beans
            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();

            ClassLoader classLoader = annotatedType.getJavaClass().getClassLoader();

            Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
            Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);

            proxyClass = (Class<? extends T>) pf.createProxyClass(bean, classLoader, annotatedType.getJavaClass(), businessMethods, nonInterceptedMethods);

            // now we collect the post-construct and pre-destroy interceptors

        }
    }
View Full Code Here

        Map<Interceptor<?>, ?> interceptorInstances = null;
        T internalInstance = instance;

        if (getInterceptorInfo() != null && instance instanceof OwbInterceptorProxy)
        {
            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
            InterceptorHandler ih = pf.getInterceptorHandler((OwbInterceptorProxy) instance);
            if (ih instanceof DefaultInterceptorHandler)
            {
                DefaultInterceptorHandler dih = (DefaultInterceptorHandler) ih;
                interceptorInstances = dih.getInstances();
                internalInstance = (T) dih.getTarget();
View Full Code Here

        Map instances = new HashMap();
        instances.put(interceptorBean, interceptor);
        InterceptorHandler interceptorHandler
                = new DefaultInterceptorHandler<RuntimeExceptionBindingTypeBean>(target, target, interceptors, instances, null);
       
        InterceptorDecoratorProxyFactory factory = new InterceptorDecoratorProxyFactory(getWebBeansContext());
        Class<RuntimeExceptionBindingTypeBean> proxyClass
                = factory.createProxyClass(bean, Thread.currentThread().getContextClassLoader(), RuntimeExceptionBindingTypeBean.class, interceptedMethods, null);

        RuntimeExceptionBindingTypeBean instance = factory.createProxyInstance(proxyClass, target, interceptorHandler);
        int result = instance.business();
        Assert.assertEquals(42, result);

        Assert.assertEquals(1, interceptor.invoked);
       
View Full Code Here

{

    @Test
    public void testSimpleProxyCreation() throws Exception
    {
        InterceptorDecoratorProxyFactory pf = new InterceptorDecoratorProxyFactory(new WebBeansContext());

        // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes.
        ClassLoader classLoader = new URLClassLoader(new URL[0]);

        List<Method> methods = ClassUtil.getNonPrivateMethods(ClassInterceptedClass.class, true);

        Method[] interceptedMethods = methods.toArray(new Method[methods.size()]);
        Method[] nonInterceptedMethods = null;

        Bean dummyBean = new DummyBean();

        Class<ClassInterceptedClass> proxyClass = pf.createProxyClass(dummyBean, classLoader, ClassInterceptedClass.class, interceptedMethods, nonInterceptedMethods);
        Assert.assertNotNull(proxyClass);

        ClassInterceptedClass internalInstance = new ClassInterceptedClass();
        internalInstance.init();

        TestInterceptorHandler testInvocationHandler = new TestInterceptorHandler(internalInstance);

        ClassInterceptedClass proxy = pf.createProxyInstance(proxyClass, internalInstance, testInvocationHandler);
        Assert.assertNotNull(proxy);

        Assert.assertTrue(proxy instanceof OwbInterceptorProxy);

        proxy.setMeaningOfLife(42);
View Full Code Here

    }

    @Test
    public void testGenericProxyGeneration()
    {
        InterceptorDecoratorProxyFactory pf = new InterceptorDecoratorProxyFactory(new WebBeansContext());

        // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes.
        ClassLoader classLoader = new URLClassLoader(new URL[0]);

        List<Method> methods = ClassUtil.getNonPrivateMethods(ExtendedSpecificClass.class, true);
        for (Iterator<Method> i = methods.iterator(); i.hasNext();)
        {
            if (i.next().isBridge())
            {
                i.remove();
            }
        }

        Method[] interceptedMethods = methods.toArray(new Method[methods.size()]);
        Method[] nonInterceptedMethods = null;

        Bean dummyBean = new DummyBean();

        Class<ExtendedSpecificClass> proxyClass = pf.createProxyClass(dummyBean, classLoader, ExtendedSpecificClass.class, interceptedMethods, nonInterceptedMethods);
        Assert.assertNotNull(proxyClass);

        ExtendedSpecificClass internalInstance = new ExtendedSpecificClass();
        internalInstance.init();

        TestInterceptorHandler testInvocationHandler = new TestInterceptorHandler(internalInstance);

        ExtendedSpecificClass extendedSpecificProxyInstance = pf.createProxyInstance(proxyClass, internalInstance, testInvocationHandler);
        SpecificClass<CustomType> specificProxyInstance = extendedSpecificProxyInstance;
        GenericInterface<CustomBaseType> interfaceProxyInstance = extendedSpecificProxyInstance;
        Assert.assertNotNull(extendedSpecificProxyInstance.newInstance());
        Assert.assertNotNull(specificProxyInstance.newInstance());
        Assert.assertNotNull(interfaceProxyInstance.newInstance());
View Full Code Here

            }
        }

        // step 2.
        // creating the Proxy Class itself
        InterceptorDecoratorProxyFactory pf = new InterceptorDecoratorProxyFactory(getWebBeansContext());

        // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes.
        ClassLoader classLoader = this.getClass().getClassLoader(); // new URLClassLoader(new URL[0]);

        Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
        Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);

        Class<? extends ClassMultiInterceptedClass> proxyClass = pf.createProxyClass(bean, classLoader, ClassMultiInterceptedClass.class, businessMethods, nonInterceptedMethods);
        Assert.assertNotNull(proxyClass);


        // step 3.
        // creating the InterceptorHandler for each intercepted instance later at runtime
        Map<Interceptor<?>,Object> interceptorInstances  = new HashMap<Interceptor<?>, Object>();
        for (Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
        {
            Object interceptorInstance = interceptorBean.create(cc);
            interceptorInstances.put(interceptorBean, interceptorInstance);
        }
        InterceptorHandler interceptorHandler
                = new DefaultInterceptorHandler<ClassMultiInterceptedClass>(internalInstance, internalInstance, methodInterceptors, interceptorInstances, null);

        ClassMultiInterceptedClass proxyInstance = pf.createProxyInstance(proxyClass, internalInstance, interceptorHandler);
        Assert.assertNotNull(proxyInstance);

        Assert.assertEquals(internalInstance, proxyInstance.getSelf());

        proxyInstance.setMeaningOfLife(42);
View Full Code Here

TOP

Related Classes of org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.