KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > server > container > ServerFactoryInterceptor


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 /**
20  * The interceptor to create server containers
21  *
22  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
23  * @version $Revision: 1.4 $
24  */

25 public class ServerFactoryInterceptor
26    implements Interceptor
27 {
28    // Constants -----------------------------------------------------
29

30    // Attributes ----------------------------------------------------
31

32    // Static --------------------------------------------------------
33

34    public static final ServerFactoryInterceptor singleton = new ServerFactoryInterceptor();
35
36    // Constructors --------------------------------------------------
37

38    // Public --------------------------------------------------------
39

40    // Interceptor implementation -----------------------------------
41

42    public String JavaDoc getName()
43    {
44       return "ServerFactoryInterceptor";
45    }
46
47    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
48    {
49       Object JavaDoc result = invocation.invokeNext();
50       
51       MethodInvocation mi = (MethodInvocation) invocation;
52       String JavaDoc 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    // Protected ------------------------------------------------------
66

67    protected SessionDelegate createSession(MethodInvocation invocation, SessionDelegate target)
68       throws Throwable JavaDoc
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 JavaDoc
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 JavaDoc
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 JavaDoc
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    // Package Private ------------------------------------------------
121

122    // Private --------------------------------------------------------
123

124    // Inner Classes --------------------------------------------------
125

126 }
127
Popular Tags