Package javassist.util.proxy

Examples of javassist.util.proxy.ProxyFactory$CacheKey

Then, the following method call will be forwarded to MethodHandler mi and prints a message before executing the originally called method bar() in Foo.

The last three lines of the code shown above can be replaced with a call to the helper method create, which generates a proxy class, instantiates it, and sets the method handler of the instance:

To change the method handler during runtime, execute the following code:

You can also specify the default method handler:

The default handler is implicitly attached to an instance of the generated class c2. Calling setHandler on the instance is not necessary unless another method handler must be attached to the instance.

The following code is an example of method handler. It does not execute anything except invoking the original method:

A proxy object generated by ProxyFactory is serializable if its super class or interfaces implement a java.io.Serializable. However, a serialized proxy object will not be compatible with future releases. The serialization support should be used for short-term storage or RMI. @see MethodHandler @since 3.1


        try
        {
            Class<?> proxyClass = normalScopedBeanProxyClasses.get(bean);
            if (proxyClass == null)
            {
                ProxyFactory fact = createProxyFactory(bean);

                proxyClass = getProxyClass(fact);
                normalScopedBeanProxyClasses.putIfAbsent(bean, proxyClass);
            }
           
View Full Code Here


        try
        {
            Class<?> proxyClass = dependentScopedBeanProxyClasses.get(bean);
            if (proxyClass == null)
            {
                ProxyFactory fact = createProxyFactory(bean);
                proxyClass = getProxyClass(fact);
                dependentScopedBeanProxyClasses.putIfAbsent(bean, proxyClass);
            }
           
            result = proxyClass.newInstance();
View Full Code Here

        }

        Class<?>[] interfaceArray = new Class<?>[interfaceList.size()];
        interfaceArray = interfaceList.toArray(interfaceArray);

        ProxyFactory fact = new ProxyFactory();       
        fact.setInterfaces(interfaceArray);
        fact.setSuperclass(superClass);       
       
        return fact;
       
    }
View Full Code Here

    {
        WebBeansAnnotation result = null;

        try
        {
            ProxyFactory pf = new ProxyFactory();
            pf.setInterfaces(new Class<?>[] { annotationType, Annotation.class });
            pf.setSuperclass(WebBeansAnnotation.class);

            result = (WebBeansAnnotation) pf.create(new Class[] { Class.class }, new Object[] { annotationType });
            ((ProxyObject)result).setHandler(new WebBeansAnnotation(annotationType));
        }
        catch (Exception e)
        {
            WebBeansUtil.throwRuntimeExceptions(e);
View Full Code Here

    {
        X instance = null;
        try
        {
            //X TODO cache proxy class!
            ProxyFactory proxyFactory = JavassistProxyFactory.getInstance().createProxyFactory(this);
           
            ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
            this.actualResourceReference = resourceService.getResourceReference(this.resourceReference);

            instance = (X)(JavassistProxyFactory.getInstance().getProxyClass(proxyFactory).newInstance());
View Full Code Here

    {
       Object result = null;

        try
        {
            ProxyFactory pf = new ProxyFactory();
            pf.setInterfaces(new Class<?>[] {
                    Closable.class,
                    Serializable.class,
                    intf});
           
            pf.setHandler(new JmsProxyHandler(jmsComponent,intf));

            result = JavassistProxyFactory.getInstance().getProxyClass(pf).newInstance();

        }
        catch (Exception e)
View Full Code Here

                    if (injectionTarget.getDecoratorStack().size() > 0)
                    {
                        Class<?> proxyClass = JavassistProxyFactory.getInstance().getInterceptorProxyClasses().get(bean);
                        if (proxyClass == null)
                        {
                            ProxyFactory delegateFactory = JavassistProxyFactory.getInstance().createProxyFactory(bean);
                            proxyClass = JavassistProxyFactory.getInstance().getProxyClass(delegateFactory);
                            JavassistProxyFactory.getInstance().getInterceptorProxyClasses().put(bean, proxyClass);
                        }
                        Object delegate = proxyClass.newInstance();
                        delegateHandler = new DelegateHandler(this.bean);
View Full Code Here

                logger.debug("Obtaining a delegate");
            }
            Class<?> proxyClass = JavassistProxyFactory.getInstance().getInterceptorProxyClasses().get(injectionTarget);
            if (proxyClass == null)
            {
                ProxyFactory delegateFactory = JavassistProxyFactory.getInstance().createProxyFactory(injectionTarget);
                proxyClass = JavassistProxyFactory.getInstance().getProxyClass(delegateFactory);
                JavassistProxyFactory.getInstance().getInterceptorProxyClasses().put(injectionTarget, proxyClass);
            }
            Object delegate = proxyClass.newInstance();
            delegateHandler = new DelegateHandler(this.contextual, ejbContext);
View Full Code Here

        {
            T proxyInstance = null;           
            Class<?> clazz = JavassistProxyFactory.getInstance().getEjbBeanProxyClass(bean, iface);
            if(clazz == null)
            {
                ProxyFactory factory = new ProxyFactory();
                if (iface.isInterface())
                {
                    factory.setInterfaces(new Class[]{iface});
                }
                else
                {
                    // @LocalBean no-interface local view requested
                    factory.setSuperclass(iface);
                }
               
                clazz = JavassistProxyFactory.getInstance().defineEjbBeanProxyClass(bean, iface, factory);
            }
           
View Full Code Here

    * @throws Exception
    */
   public void testInterfaceProxy() throws Exception
   {
      log.info("+++ testInterfaceProxy");
      ProxyFactory factory = new ProxyFactory();
      AThing athing = new AThing();
      ThingMethodHandler handler = new ThingMethodHandler(athing);
      factory.setHandler(handler);
      Class[] ifaces = {IThing.class};
      factory.setInterfaces(ifaces);
      Class[] sig = {};
      Object[] args = {};
      IThing proxy = (IThing) factory.create(sig, args);
      proxy.method1();
      assertEquals("method1Count", 1, athing.getMethod1Count());
      proxy.method2("testInterfaceProxy");
      assertEquals("method2Count", 1, athing.getMethod2Count());
      proxy.method3(proxy);
View Full Code Here

TOP

Related Classes of javassist.util.proxy.ProxyFactory$CacheKey

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.