1 22 package org.jboss.proxy; 23 24 import java.io.Externalizable ; 25 26 import java.io.IOException ; 27 import java.io.ObjectInput ; 28 import java.io.ObjectOutput ; 29 30 import java.lang.reflect.Method ; 31 import java.lang.reflect.InvocationHandler ; 32 import java.util.ArrayList ; 33 34 import org.jboss.invocation.Invocation; 35 import org.jboss.invocation.InvocationContext; 36 import org.jboss.invocation.InvocationKey; 37 import org.jboss.invocation.PayloadKey; 38 39 47 public class ClientContainer 48 implements Externalizable , InvocationHandler 49 { 50 51 private static final long serialVersionUID = -4061374432170701306L; 52 53 54 protected static final Object [] EMPTY_ARGS = {}; 55 56 59 public InvocationContext context; 60 61 62 public Interceptor next; 63 64 67 public ClientContainer() 68 { 69 super(); 70 } 71 72 public ClientContainer(final InvocationContext context) 73 { 74 this.context = context; 75 } 76 77 public Object invoke(final Object proxy, 78 final Method m, 79 Object [] args) 80 throws Throwable 81 { 82 if (args == null) 85 args = EMPTY_ARGS; 86 87 Invocation invocation = new Invocation(); 89 90 invocation.setInvocationContext(context); 92 invocation.setId(context.getCacheId()); 93 invocation.setObjectName(context.getObjectName()); 94 invocation.setMethod(m); 95 invocation.setArguments(args); 96 invocation.setValue(InvocationKey.INVOKER_PROXY_BINDING, 97 context.getInvokerProxyBinding(), 98 PayloadKey.AS_IS); 99 100 Object obj = next.invoke(invocation); 102 return obj; 103 } 104 105 public InvocationContext getInvocationContext() 106 { 107 return this.context; 108 } 109 public ArrayList getInterceptors() 110 { 111 ArrayList tmp = new ArrayList (); 112 Interceptor inext = next; 113 while( inext != null ) 114 { 115 tmp.add(inext); 116 inext = inext.nextInterceptor; 117 } 118 return tmp; 119 } 120 public void setInterceptors(ArrayList interceptors) 121 { 122 if( interceptors.size() == 0 ) 123 return; 124 next = (Interceptor) interceptors.get(0); 125 Interceptor i = next; 126 for(int n = 1; n < interceptors.size(); n ++) 127 { 128 Interceptor inext = (Interceptor) interceptors.get(n); 129 i.setNext(inext); 130 i = inext; 131 } 132 } 133 134 public Interceptor setNext(Interceptor interceptor) 135 { 136 next = interceptor; 137 138 return interceptor; 139 } 140 141 144 public void writeExternal(final ObjectOutput out) 145 throws IOException 146 { 147 out.writeObject(next); 148 out.writeObject(context); 149 } 150 151 154 public void readExternal(final ObjectInput in) 155 throws IOException , ClassNotFoundException 156 { 157 next = (Interceptor) in.readObject(); 158 context = (InvocationContext) in.readObject(); 159 } 160 } 161 162 | Popular Tags |