X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fgeneral%2FLookupProxyFactory.java;h=286e5f5651ead211874d53773753be89a7a56431;hb=66d09690a9c113766d63df4e7623534fb278f265;hp=5315186259443eadc8dae4ad73cf2858e664f63e;hpb=8e20b580861e4aec9cdce7968db2f65e6bff99ca;p=utils diff --git a/support/general/src/main/java/org/wamblee/general/LookupProxyFactory.java b/support/general/src/main/java/org/wamblee/general/LookupProxyFactory.java index 53151862..286e5f56 100644 --- a/support/general/src/main/java/org/wamblee/general/LookupProxyFactory.java +++ b/support/general/src/main/java/org/wamblee/general/LookupProxyFactory.java @@ -15,6 +15,7 @@ */ package org.wamblee.general; +import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -25,7 +26,7 @@ import javax.naming.NamingException; /** * Proxy factory that can provide contextual references to objects retrieved - * through a lookup mechanism. + * through a lookup mechanism. The returned proxies are serializable. * * @param T * Interface to proxy. @@ -39,7 +40,7 @@ public class LookupProxyFactory { * * @author Erik Brakkee */ - public static interface Lookup { + public static interface Lookup extends Serializable { /** * Looks up the object. * @return Object (non-null) @@ -69,7 +70,19 @@ public class LookupProxyFactory { * * @author Erik Brakkee */ - private class LookupInvocationHandler implements InvocationHandler { + private static class LookupInvocationHandler implements InvocationHandler, Serializable { + + private Class clazz; + private Lookup lookup; + + /** + * Constructs the invocation handler. + * @param aLookup Lookup class. + */ + public LookupInvocationHandler(Class aClass, Lookup aLookup) { + clazz = aClass; + lookup = aLookup; + } @Override /** @@ -85,7 +98,7 @@ public class LookupProxyFactory { "Error looking up object", e); } if (svcObj == null) { - throw new LookupException("Object at is null"); + throw new LookupException("Object is null"); } if (!clazz.isInstance(svcObj)) { throw new LookupException("Object '" + svcObj + "' is not of type " + clazz.getName() + @@ -130,7 +143,7 @@ public class LookupProxyFactory { * @return Proxy. */ public T getProxy() { - InvocationHandler handler = new LookupInvocationHandler(); + InvocationHandler handler = new LookupInvocationHandler(clazz, lookup); Class proxyClass = Proxy.getProxyClass(clazz.getClassLoader(), new Class[] { clazz }); T proxy;