KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > client > container > FactoryInterceptor


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.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 /**
20  * An interceptor for creating delegates
21  *
22  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
23  * @version $Revision: 1.5 $
24  */

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

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

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

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

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

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

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

65    protected SessionDelegate createSession(Invocation invocation, SessionDelegate server)
66       throws Throwable JavaDoc
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 JavaDoc
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 JavaDoc
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 JavaDoc
95    {
96       Interceptor[] interceptors = new Interceptor[0];
97       Container session = Container.getContainer(invocation);
98       return ClientContainerFactory.getProducerContainer(session, server, interceptors, null);
99    }
100
101    // Package Private ------------------------------------------------
102

103    // Private --------------------------------------------------------
104

105    // Inner Classes --------------------------------------------------
106

107 }
108
Popular Tags