1 7 package org.jboss.jms.server.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 25 31 public class ServerContainerFactory 32 { 33 35 37 39 public static ConnectionDelegate getConnectionContainer 40 ( 41 ImplementationDelegate delegate, 42 Interceptor[] interceptors, 43 SimpleMetaData metadata 44 ) 45 throws JMSException 46 { 47 return (ConnectionDelegate) getContainer 48 ( 49 ConnectionDelegate.class, 50 null, 51 interceptors, 52 metadata 53 ); 54 } 55 56 public static SessionDelegate getSessionContainer 57 ( 58 Container parent, 59 Interceptor[] interceptors, 60 SimpleMetaData metadata 61 ) 62 throws JMSException 63 { 64 return (SessionDelegate) getContainer 65 ( 66 SessionDelegate.class, 67 parent, 68 interceptors, 69 metadata 70 ); 71 } 72 73 public static BrowserDelegate getBrowserContainer 74 ( 75 Container parent, 76 Interceptor[] interceptors, 77 SimpleMetaData metadata 78 ) 79 throws JMSException 80 { 81 return (BrowserDelegate) getContainer 82 ( 83 BrowserDelegate.class, 84 parent, 85 interceptors, 86 metadata 87 ); 88 } 89 90 public static ConsumerDelegate getConsumerContainer 91 ( 92 Container parent, 93 Interceptor[] interceptors, 94 SimpleMetaData metadata 95 ) 96 throws JMSException 97 { 98 return (ConsumerDelegate) getContainer 99 ( 100 ConsumerDelegate.class, 101 parent, 102 interceptors, 103 metadata 104 ); 105 } 106 107 public static ProducerDelegate getProducerContainer 108 ( 109 Container parent, 110 Interceptor[] interceptors, 111 SimpleMetaData metadata 112 ) 113 throws JMSException 114 { 115 return (ProducerDelegate) getContainer 116 ( 117 ProducerDelegate.class, 118 parent, 119 interceptors, 120 metadata 121 ); 122 } 123 124 public static Object getContainer 125 ( 126 Class clazz, 127 Container parent, 128 Interceptor[] interceptors, 129 SimpleMetaData metadata 130 ) 131 throws JMSException 132 { 133 Interceptor[] standard = getStandard(); 134 135 Object target = metadata.getMetaData("JMS", "Target"); 136 137 int stackSize = standard.length + interceptors.length + 1; 138 Interceptor[] stack = new Interceptor[stackSize]; 139 System.arraycopy(standard, 0, stack, 0, standard.length); 140 System.arraycopy(interceptors, 0, stack, standard.length, interceptors.length); 141 stack[stackSize-1] = new DispatchInterceptor(target); 142 143 Container container = new Container(parent, stack, metadata); 144 Object result = Proxy.newProxyInstance 145 ( 146 Thread.currentThread().getContextClassLoader(), 147 new Class [] { clazz }, 148 container 149 ); 150 container.setProxy(result); 151 return result; 152 } 153 154 public static Interceptor[] getStandard() 155 { 156 return new Interceptor[] 157 { 158 ContainerObjectOverridesInterceptor.singleton 159 }; 160 } 161 162 164 166 168 170 172 174 } 175 | Popular Tags |