1 7 package org.jboss.jms.client.container; 8 9 import org.jboss.aop.advice.Interceptor; 10 import org.jboss.aop.joinpoint.Invocation; 11 import org.jboss.aop.joinpoint.MethodInvocation; 12 import org.jboss.jms.client.BrowserDelegate; 13 import org.jboss.jms.client.ConsumerDelegate; 14 import org.jboss.jms.client.ProducerDelegate; 15 import org.jboss.jms.client.SessionDelegate; 16 import org.jboss.jms.container.Container; 17 import org.jboss.jms.message.standard.MessageFactoryInterceptor; 18 19 25 public class FactoryInterceptor 26 implements Interceptor 27 { 28 30 32 34 public static final FactoryInterceptor singleton = new FactoryInterceptor(); 35 36 38 40 42 public String getName() 43 { 44 return "FactoryInterceptor"; 45 } 46 47 public Object invoke(Invocation invocation) throws Throwable 48 { 49 Object result = invocation.invokeNext(); 50 String methodName = ((MethodInvocation) invocation).getMethod().getName(); 51 if (methodName.equals("createSession")) 52 return createSession(invocation, (SessionDelegate) result); 53 else if (methodName.equals("createBrowser")) 54 return createBrowser(invocation, (BrowserDelegate) result); 55 else if (methodName.equals("createConsumer")) 56 return createConsumer(invocation, (ConsumerDelegate) result); 57 else if (methodName.equals("createProducer")) 58 return createProducer(invocation, (ProducerDelegate) result); 59 else 60 return result; 61 } 62 63 65 protected SessionDelegate createSession(Invocation invocation, SessionDelegate server) 66 throws Throwable 67 { 68 Interceptor[] interceptors = new Interceptor[] 69 { 70 MessageFactoryInterceptor.singleton, 71 FactoryInterceptor.singleton 72 }; 73 Container connection = Container.getContainer(invocation); 74 return ClientContainerFactory.getSessionContainer(connection, server, interceptors, null); 75 } 76 77 protected BrowserDelegate createBrowser(Invocation invocation, BrowserDelegate server) 78 throws Throwable 79 { 80 Interceptor[] interceptors = new Interceptor[0]; 81 Container session = Container.getContainer(invocation); 82 return ClientContainerFactory.getBrowserContainer(session, server, interceptors, null); 83 } 84 85 protected ConsumerDelegate createConsumer(Invocation invocation, ConsumerDelegate server) 86 throws Throwable 87 { 88 Interceptor[] interceptors = new Interceptor[0]; 89 Container session = Container.getContainer(invocation); 90 return ClientContainerFactory.getConsumerContainer(session, server, interceptors, null); 91 } 92 93 protected ProducerDelegate createProducer(Invocation invocation, ProducerDelegate server) 94 throws Throwable 95 { 96 Interceptor[] interceptors = new Interceptor[0]; 97 Container session = Container.getContainer(invocation); 98 return ClientContainerFactory.getProducerContainer(session, server, interceptors, null); 99 } 100 101 103 105 107 } 108 | Popular Tags |