1 7 package org.jboss.jms.server.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.aop.metadata.SimpleMetaData; 13 import org.jboss.jms.client.BrowserDelegate; 14 import org.jboss.jms.client.ConsumerDelegate; 15 import org.jboss.jms.client.ProducerDelegate; 16 import org.jboss.jms.client.SessionDelegate; 17 import org.jboss.jms.container.Container; 18 19 25 public class ServerFactoryInterceptor 26 implements Interceptor 27 { 28 30 32 34 public static final ServerFactoryInterceptor singleton = new ServerFactoryInterceptor(); 35 36 38 40 42 public String getName() 43 { 44 return "ServerFactoryInterceptor"; 45 } 46 47 public Object invoke(Invocation invocation) throws Throwable 48 { 49 Object result = invocation.invokeNext(); 50 51 MethodInvocation mi = (MethodInvocation) invocation; 52 String methodName = mi.getMethod().getName(); 53 if (methodName.equals("createSession")) 54 return createSession(mi, (SessionDelegate) result); 55 else if (methodName.equals("createBrowser")) 56 return createBrowser(mi, (BrowserDelegate) result); 57 else if (methodName.equals("createConsumer")) 58 return createConsumer(mi, (ConsumerDelegate) result); 59 else if (methodName.equals("createProducer")) 60 return createProducer(mi, (ProducerDelegate) result); 61 else 62 return result; 63 } 64 65 67 protected SessionDelegate createSession(MethodInvocation invocation, SessionDelegate target) 68 throws Throwable 69 { 70 Client client = Client.getClient(invocation); 71 SimpleMetaData metaData = client.createSession(invocation); 72 Interceptor[] interceptors = new Interceptor[] 73 { 74 singleton, 75 ServerSessionInterceptor.singleton 76 }; 77 Container connection = Container.getContainer(invocation); 78 return ServerContainerFactory.getSessionContainer(connection, interceptors, metaData); 79 } 80 81 protected BrowserDelegate createBrowser(MethodInvocation invocation, BrowserDelegate target) 82 throws Throwable 83 { 84 Client client = Client.getClient(invocation); 85 SimpleMetaData metaData = client.createBrowser(invocation); 86 Interceptor[] interceptors = new Interceptor[] 87 { 88 ServerBrowserInterceptor.singleton 89 }; 90 Container session = Container.getContainer(invocation); 91 return ServerContainerFactory.getBrowserContainer(session, interceptors, metaData); 92 } 93 94 protected ConsumerDelegate createConsumer(MethodInvocation invocation, ConsumerDelegate target) 95 throws Throwable 96 { 97 Client client = Client.getClient(invocation); 98 SimpleMetaData metaData = client.createConsumer(invocation); 99 Interceptor[] interceptors = new Interceptor[] 100 { 101 ServerConsumerInterceptor.singleton 102 }; 103 Container session = Container.getContainer(invocation); 104 return ServerContainerFactory.getConsumerContainer(session, interceptors, metaData); 105 } 106 107 protected ProducerDelegate createProducer(MethodInvocation invocation, ProducerDelegate target) 108 throws Throwable 109 { 110 Client client = Client.getClient(invocation); 111 SimpleMetaData metaData = client.createProducer(invocation); 112 Interceptor[] interceptors = new Interceptor[] 113 { 114 ServerProducerInterceptor.singleton 115 }; 116 Container session = Container.getContainer(invocation); 117 return ServerContainerFactory.getProducerContainer(session, interceptors, metaData); 118 } 119 120 122 124 126 } 127 | Popular Tags |