From: Scott M S. <st...@us...> - 2004-12-04 07:48:50
|
User: starksm Date: 04/12/03 23:48:41 Modified: src/main/org/jboss/proxy Tag: Branch_3_2 ClientContainer.java GenericProxyFactory.java Log: Extend the ClientContainer to provide access to the interceptors and invocation context so that clients can customize the proxy outside of the server. Revision Changes Path No revision No revision 1.5.2.2 +40 -5 jboss/src/main/org/jboss/proxy/ClientContainer.java Index: ClientContainer.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/proxy/ClientContainer.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -r1.5.2.1 -r1.5.2.2 --- ClientContainer.java 17 Apr 2003 02:41:58 -0000 1.5.2.1 +++ ClientContainer.java 4 Dec 2004 07:48:40 -0000 1.5.2.2 @@ -15,6 +15,7 @@ import java.lang.reflect.Method; import java.lang.reflect.InvocationHandler; +import java.util.ArrayList; import org.jboss.invocation.Invocation; import org.jboss.invocation.InvocationContext; @@ -26,10 +27,10 @@ * starts the invocation interceptor call chain. * * @author <a href="mailto:mar...@jb...">Marc Fleury</a> - * @version $Revision: 1.5.2.1 $ + * @version $Revision: 1.5.2.2 $ */ public class ClientContainer - implements Externalizable, InvocationHandler + implements IClientContainer, Externalizable, InvocationHandler { /** The serialVersionUID. @since 1.5 */ private static final long serialVersionUID = -4061374432170701306L; @@ -67,7 +68,12 @@ // Isn't this a bug in the proxy call?? if (args == null) args = EMPTY_ARGS; - + + if( m.getDeclaringClass() == IClientContainer.class ) + { + return m.invoke(this, args); + } + // Create the invocation object Invocation invocation = new Invocation(); @@ -84,14 +90,43 @@ // send the invocation down the client interceptor chain return next.invoke(invocation); } - + + public InvocationContext getInvocationContext() + { + return this.context; + } + public ArrayList getInterceptors() + { + ArrayList tmp = new ArrayList(); + Interceptor inext = next; + while( inext != null ) + { + tmp.add(inext); + inext = inext.nextInterceptor; + } + return tmp; + } + public void setInterceptors(ArrayList interceptors) + { + if( interceptors.size() == 0 ) + return; + next = (Interceptor) interceptors.get(0); + Interceptor i = next; + for(int n = 1; n < interceptors.size(); n ++) + { + Interceptor inext = (Interceptor) interceptors.get(n); + i.setNext(inext); + i = inext; + } + } + public Interceptor setNext(Interceptor interceptor) { next = interceptor; return interceptor; } - + /** * Externalization support. */ 1.1.2.4 +29 -24 jboss/src/main/org/jboss/proxy/GenericProxyFactory.java Index: GenericProxyFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/proxy/GenericProxyFactory.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- GenericProxyFactory.java 7 Apr 2003 08:10:28 -0000 1.1.2.3 +++ GenericProxyFactory.java 4 Dec 2004 07:48:40 -0000 1.1.2.4 @@ -6,17 +6,14 @@ */ package org.jboss.proxy; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import java.util.ArrayList; -import java.util.Iterator; +import java.util.Arrays; import javax.management.ObjectName; -import org.jboss.invocation.Invoker; import org.jboss.invocation.InvocationContext; import org.jboss.invocation.InvocationKey; -import org.jboss.proxy.Interceptor; -import org.jboss.proxy.ClientContainer; +import org.jboss.invocation.Invoker; import org.jboss.system.Registry; import org.jboss.util.NestedRuntimeException; @@ -26,20 +23,20 @@ * * @todo generalize the proxy/invoker factory object * @author Sco...@jb... - * @version $Revision: 1.1.2.3 $ + * @version $Revision: 1.1.2.4 $ */ public class GenericProxyFactory { /** Create a composite proxy for the given interfaces, invoker. - @param id, the cache id for the target object if any - @param targetName, the name of the server side service - @param invoker, the detached invoker stub to embed in the proxy - @param jndiName, the JNDI name the proxy will be bound under if not null - @param proxyBindingName, the invoker-proxy-binding name if not null - @param interceptorClasses, the Class objects for the interceptors - @param loader, the ClassLoader to associate the the Proxy - @param ifaces, the Class objects for the interfaces the Proxy implements + @param id - the cache id for the target object if any + @param targetName - the name of the server side service + @param invoker - the detached invoker stub to embed in the proxy + @param jndiName - the JNDI name the proxy will be bound under if not null + @param proxyBindingName - the invoker-proxy-binding name if not null + @param interceptorClasses - the Class objects for the interceptors + @param loader - the ClassLoader to associate the the Proxy + @param ifaces - the Class objects for the interfaces the Proxy implements */ public Object createProxy(Object id, ObjectName targetName, Invoker invoker, String jndiName, String proxyBindingName, @@ -68,24 +65,28 @@ throw new NestedRuntimeException("Failed to load interceptor chain", e); } + ArrayList tmp = new ArrayList(Arrays.asList(ifaces)); + tmp.add(IClientContainer.class); + Class[] ifaces2 = new Class[tmp.size()]; + tmp.toArray(ifaces2); return Proxy.newProxyInstance( // Classloaders loader, // Interfaces - ifaces, + ifaces2, // Client container as invocation handler client); } /** Create a composite proxy for the given interfaces, invoker. - @param id, the cache id for the target object if any - @param targetName, the name of the server side service - @param invokerName, the name of the server side JMX invoker - @param jndiName, the JNDI name the proxy will be bound under if not null - @param proxyBindingName, the invoker-proxy-binding name if not null - @param interceptorClasses, the Class objects for the interceptors - @param loader, the ClassLoader to associate the the Proxy - @param ifaces, the Class objects for the interfaces the Proxy implements + @param id - the cache id for the target object if any + @param targetName - the name of the server side service + @param invokerName - the name of the server side JMX invoker + @param jndiName - the JNDI name the proxy will be bound under if not null + @param proxyBindingName - the invoker-proxy-binding name if not null + @param interceptorClasses - the Class objects for the interceptors + @param loader - the ClassLoader to associate the the Proxy + @param ifaces - the Class objects for the interfaces the Proxy implements */ public Object createProxy(Object id, ObjectName targetName, ObjectName invokerName, String jndiName, String proxyBindingName, @@ -115,11 +116,15 @@ throw new NestedRuntimeException("Failed to load interceptor chain", e); } + ArrayList tmp = new ArrayList(Arrays.asList(ifaces)); + tmp.add(IClientContainer.class); + Class[] ifaces2 = new Class[tmp.size()]; + tmp.toArray(ifaces2); return Proxy.newProxyInstance( // Classloaders loader, // Interfaces - ifaces, + ifaces2, // Client container as invocation handler client); } |