KickJava   Java API By Example, From Geeks To Geeks.

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


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 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
25 /**
26  * A factory for server containers
27  *
28  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
29  * @version $Revision: 1.3 $
30  */

31 public class ServerContainerFactory
32 {
33    // Constants -----------------------------------------------------
34

35    // Attributes ----------------------------------------------------
36

37    // Static --------------------------------------------------------
38

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

164    // Public --------------------------------------------------------
165

166    // Protected ------------------------------------------------------
167

168    // Package Private ------------------------------------------------
169

170    // Private --------------------------------------------------------
171

172    // Inner Classes --------------------------------------------------
173

174 }
175
Popular Tags