1 7 package org.jboss.jms.client.container; 8 9 import java.lang.reflect.Proxy ; 10 11 import javax.jms.JMSException ; 12 13 import org.jboss.aop.advice.Interceptor; 14 import org.jboss.aop.metadata.SimpleMetaData; 15 import org.jboss.jms.client.BrowserDelegate; 16 import org.jboss.jms.client.ConnectionDelegate; 17 import org.jboss.jms.client.ConsumerDelegate; 18 import org.jboss.jms.client.ImplementationDelegate; 19 import org.jboss.jms.client.ProducerDelegate; 20 import org.jboss.jms.client.SessionDelegate; 21 import org.jboss.jms.container.Container; 22 import org.jboss.jms.container.ContainerObjectOverridesInterceptor; 23 import org.jboss.jms.container.DispatchInterceptor; 24 import org.jboss.jms.container.ForwardInterceptor; 25 import org.jboss.jms.container.LogInterceptor; 26 27 33 public class ClientContainerFactory 34 { 35 37 39 41 public static ConnectionDelegate getConnectionContainer 42 ( 43 ImplementationDelegate delegate, 44 ConnectionDelegate server, 45 Interceptor[] interceptors, 46 SimpleMetaData metadata 47 ) 48 throws JMSException 49 { 50 return (ConnectionDelegate) getContainer 51 ( 52 ConnectionDelegate.class, 53 null, 54 server, 55 interceptors, 56 metadata 57 ); 58 } 59 60 public static SessionDelegate getSessionContainer 61 ( 62 Container parent, 63 SessionDelegate server, 64 Interceptor[] interceptors, 65 SimpleMetaData metadata 66 ) 67 throws JMSException 68 { 69 return (SessionDelegate) getContainer 70 ( 71 SessionDelegate.class, 72 parent, 73 server, 74 interceptors, 75 metadata 76 ); 77 } 78 79 public static BrowserDelegate getBrowserContainer 80 ( 81 Container parent, 82 BrowserDelegate server, 83 Interceptor[] interceptors, 84 SimpleMetaData metadata 85 ) 86 throws JMSException 87 { 88 return (BrowserDelegate) getContainer 89 ( 90 BrowserDelegate.class, 91 parent, 92 server, 93 interceptors, 94 metadata 95 ); 96 } 97 98 public static ConsumerDelegate getConsumerContainer 99 ( 100 Container parent, 101 ConsumerDelegate server, 102 Interceptor[] interceptors, 103 SimpleMetaData metadata 104 ) 105 throws JMSException 106 { 107 return (ConsumerDelegate) getContainer 108 ( 109 ConsumerDelegate.class, 110 parent, 111 server, 112 interceptors, 113 metadata 114 ); 115 } 116 117 public static ProducerDelegate getProducerContainer 118 ( 119 Container parent, 120 ProducerDelegate server, 121 Interceptor[] interceptors, 122 SimpleMetaData metadata 123 ) 124 throws JMSException 125 { 126 return (ProducerDelegate) getContainer 127 ( 128 ProducerDelegate.class, 129 parent, 130 server, 131 interceptors, 132 metadata 133 ); 134 } 135 136 public static Object getContainer( 137 Class clazz, 138 Container parent, 139 Object delegate, 140 Interceptor[] interceptors, 141 SimpleMetaData metadata 142 ) 143 throws JMSException 144 { 145 Interceptor[] standard = getStandard(); 146 147 int stackSize = standard.length + interceptors.length + 1; 148 Interceptor[] stack = new Interceptor[stackSize]; 149 System.arraycopy(standard, 0, stack, 0, standard.length); 150 System.arraycopy(interceptors, 0, stack, standard.length, interceptors.length); 151 152 if (delegate instanceof Proxy ) 153 { 154 try 155 { 156 stack[stackSize-1] = new ForwardInterceptor(Container.getContainer(delegate)); 157 } 158 catch (Throwable ignored) 159 { 160 } 161 } 162 if (stack[stackSize-1] == null) 163 stack[stackSize-1] = new DispatchInterceptor(delegate); 164 165 Container container = new Container(parent, stack, metadata); 166 Object result = Proxy.newProxyInstance 167 ( 168 Thread.currentThread().getContextClassLoader(), 169 new Class [] { clazz }, 170 container 171 ); 172 container.setProxy(result); 173 return result; 174 } 175 176 public static Interceptor[] getStandard() 177 { 178 return new Interceptor[] 179 { 180 ContainerObjectOverridesInterceptor.singleton, 181 JMSExceptionInterceptor.singleton, 182 LogInterceptor.singleton, 183 new ClosedInterceptor() 184 }; 185 } 186 187 189 191 193 195 197 199 } 200 | Popular Tags |