KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Proxy JavaDoc;
10
11 import javax.jms.JMSException JavaDoc;
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 import org.jboss.jms.container.ForwardInterceptor;
25 import org.jboss.jms.container.LogInterceptor;
26
27 /**
28  * The in jvm implementation
29  *
30  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
31  * @version $Revision: 1.4 $
32  */

33 public class ClientContainerFactory
34 {
35    // Constants -----------------------------------------------------
36

37    // Attributes ----------------------------------------------------
38

39    // Static --------------------------------------------------------
40

41    public static ConnectionDelegate getConnectionContainer
42    (
43       ImplementationDelegate delegate,
44       ConnectionDelegate server,
45       Interceptor[] interceptors,
46       SimpleMetaData metadata
47    )
48       throws JMSException JavaDoc
49    {
50       return (ConnectionDelegate) getContainer
51       (
52          ConnectionDelegate.class,
53          null,
54          server,
55          interceptors,
56          metadata
57       );
58    }
59
60    public static SessionDelegate getSessionContainer
61    (
62       Container parent,
63       SessionDelegate server,
64       Interceptor[] interceptors,
65       SimpleMetaData metadata
66    )
67       throws JMSException JavaDoc
68    {
69       return (SessionDelegate) getContainer
70       (
71          SessionDelegate.class,
72          parent,
73          server,
74          interceptors,
75          metadata
76       );
77    }
78
79    public static BrowserDelegate getBrowserContainer
80    (
81       Container parent,
82       BrowserDelegate server,
83       Interceptor[] interceptors,
84       SimpleMetaData metadata
85    )
86       throws JMSException JavaDoc
87    {
88       return (BrowserDelegate) getContainer
89       (
90          BrowserDelegate.class,
91          parent,
92          server,
93          interceptors,
94          metadata
95       );
96    }
97
98    public static ConsumerDelegate getConsumerContainer
99    (
100       Container parent,
101       ConsumerDelegate server,
102       Interceptor[] interceptors,
103       SimpleMetaData metadata
104    )
105       throws JMSException JavaDoc
106    {
107       return (ConsumerDelegate) getContainer
108       (
109          ConsumerDelegate.class,
110          parent,
111          server,
112          interceptors,
113          metadata
114       );
115    }
116
117    public static ProducerDelegate getProducerContainer
118    (
119       Container parent,
120       ProducerDelegate server,
121       Interceptor[] interceptors,
122       SimpleMetaData metadata
123    )
124       throws JMSException JavaDoc
125    {
126       return (ProducerDelegate) getContainer
127       (
128          ProducerDelegate.class,
129          parent,
130          server,
131          interceptors,
132          metadata
133       );
134    }
135    
136    public static Object JavaDoc getContainer(
137       Class JavaDoc clazz,
138       Container parent,
139       Object JavaDoc delegate,
140       Interceptor[] interceptors,
141       SimpleMetaData metadata
142    )
143       throws JMSException JavaDoc
144    {
145        Interceptor[] standard = getStandard();
146     
147       int stackSize = standard.length + interceptors.length + 1;
148       Interceptor[] stack = new Interceptor[stackSize];
149     System.arraycopy(standard, 0, stack, 0, standard.length);
150        System.arraycopy(interceptors, 0, stack, standard.length, interceptors.length);
151
152       if (delegate instanceof Proxy JavaDoc)
153       {
154          try
155          {
156             stack[stackSize-1] = new ForwardInterceptor(Container.getContainer(delegate));
157          }
158          catch (Throwable JavaDoc ignored)
159          {
160          }
161       }
162       if (stack[stackSize-1] == null)
163          stack[stackSize-1] = new DispatchInterceptor(delegate);
164
165        Container container = new Container(parent, stack, metadata);
166        Object JavaDoc result = Proxy.newProxyInstance
167       (
168             Thread.currentThread().getContextClassLoader(),
169             new Class JavaDoc[] { clazz },
170             container
171       );
172        container.setProxy(result);
173        return result;
174    }
175
176    public static Interceptor[] getStandard()
177    {
178       return new Interceptor[]
179       {
180          ContainerObjectOverridesInterceptor.singleton,
181          JMSExceptionInterceptor.singleton,
182          LogInterceptor.singleton,
183          new ClosedInterceptor()
184       };
185    }
186
187    // Constructors --------------------------------------------------
188

189    // Public --------------------------------------------------------
190

191    // Protected ------------------------------------------------------
192

193    // Package Private ------------------------------------------------
194

195    // Private --------------------------------------------------------
196

197    // Inner Classes --------------------------------------------------
198

199 }
200
Popular Tags