Package org.shiftone.cache

Source Code of org.shiftone.cache.CacheProxy

package org.shiftone.cache;

import org.shiftone.cache.util.CacheInvocationHandler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

* Static class CacheProxy can be used to create cache proxy objects of
* instances of objects that implement an interface.
* <pre>
* Thing thing = new ThingImpl();
* Thing cachedThing =
*         (Thing)CacheProxy.newProxyInstance(thing, Thing.class, cache);
* cachedThing.doThing();
* </pre>
* @author <a href="">Jeff Drost</a>
* @version $Revision: 1.6 $
public class CacheProxy

    private static final ClassLoader DEFAULT_CLASS_LOADER = CacheProxy.class.getClassLoader();

    public static Object newProxyInstance(ClassLoader loader, Object target, Class iface, Cache cache) throws IllegalArgumentException

        InvocationHandler handler = null;
        Class[]           ifaces  = new Class[]{ iface };

        handler = new CacheInvocationHandler(target, cache);

        return Proxy.newProxyInstance(loader, ifaces, handler);

    public static Object newProxyInstance(Object target, Class iface, Cache cache) throws IllegalArgumentException
        return newProxyInstance(DEFAULT_CLASS_LOADER, target, iface, cache);

Related Classes of org.shiftone.cache.CacheProxy

Copyright © 2018 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