KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > container > Container


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.container;
8
9 import java.lang.reflect.InvocationHandler JavaDoc;
10 import java.lang.reflect.Method JavaDoc;
11 import java.lang.reflect.Proxy JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import javax.jms.JMSException JavaDoc;
17
18 import org.jboss.aop.Advised;
19 import org.jboss.aop.InstanceAdvisor;
20 import org.jboss.aop.MethodInfo;
21 import org.jboss.aop.advice.Interceptor;
22 import org.jboss.aop.joinpoint.Invocation;
23 import org.jboss.aop.joinpoint.MethodInvocation;
24 import org.jboss.aop.metadata.MetaDataResolver;
25 import org.jboss.aop.metadata.SimpleMetaData;
26
27 /**
28  * A JMS container
29  *
30  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
31  * @version $Revision: 1.6 $
32  */

33 public class Container implements InvocationHandler JavaDoc
34 {
35    // Constants -----------------------------------------------------
36

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

39    protected Interceptor[] interceptors;
40
41    protected SimpleMetaData metadata = new SimpleMetaData();
42
43    /**
44     * The frontend proxy
45     */

46    private Object JavaDoc proxy;
47
48    /**
49     * The parent
50     */

51    private Container parent;
52    
53    /**
54     * The children
55     */

56    private Set JavaDoc children = Collections.synchronizedSet(new HashSet JavaDoc());
57
58    // Static --------------------------------------------------------
59

60    /**
61     * Get the container from a proxy
62     *
63     * @param object the proxy
64     * @returns the container
65     * @throws Throwable for any error
66     */

67    public static Container getContainer(Object JavaDoc object)
68       throws Throwable JavaDoc
69    {
70       Proxy JavaDoc proxy = (Proxy JavaDoc) object;
71       return (Container) Proxy.getInvocationHandler(proxy);
72    }
73
74    /**
75     * Get the container from an invocation
76     *
77     * @param invocation the conatiner
78     * @returns the container
79     */

80    public static Container getContainer(Invocation invocation)
81    {
82       return (Container) invocation.getMetaData("JMS", "Container");
83    }
84
85    /**
86     * Get the proxy from an invocation
87     *
88     * @param invocation the conatiner
89     * @returns the proxy
90     */

91    public static Object JavaDoc getProxy(Invocation invocation)
92    {
93       return getContainer(invocation).getProxy();
94    }
95
96    // Constructors --------------------------------------------------
97

98    /**
99     * Create a new container
100     *
101     * @param interceptors the interceptors
102     * @param metadata the meta data
103     * @throws JMSException for any error
104     */

105    public Container(Container parent, Interceptor[] interceptors, SimpleMetaData metadata)
106       throws JMSException JavaDoc
107    {
108       this.interceptors = interceptors;
109       this.parent = parent;
110       if (metadata != null)
111          this.metadata = metadata;
112       this.metadata.addMetaData("JMS", "Container", this);
113
114       if (parent != null)
115          parent.children.add(this);
116    }
117
118    // Public --------------------------------------------------------
119

120    public Object JavaDoc getProxy()
121    {
122       return proxy;
123    }
124
125    public void setProxy(Object JavaDoc proxy)
126    {
127       this.proxy = proxy;
128    }
129    
130    public Container getParent()
131    {
132       return parent;
133    }
134    
135    public Set JavaDoc getChildren()
136    {
137       return children;
138    }
139    
140    public void addChild(Container child)
141    {
142       children.add(child);
143    }
144    
145    public void removeChild(Container child)
146    {
147       children.remove(child);
148    }
149
150    public Object JavaDoc invoke (Invocation invocation)
151       throws Throwable JavaDoc
152    {
153       //MetaDataResolver oldMetaData = invocation.instanceResolver;
154
//invocation.instanceResolver = getMetaData();
155
try
156       {
157          return invocation.invokeNext(interceptors);
158       }
159       finally
160       {
161          //invocation.instanceResolver = oldMetaData;
162
}
163    }
164
165    public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
166    {
167       MethodInfo info = new MethodInfo();
168       MethodInvocation invocation = new MethodInvocation(info, interceptors);
169       //invocation.instanceResolver = getMetaData();
170
//invocation.method = m;
171
//invocation.arguments = args;
172
return invocation.invokeNext();
173    }
174
175    // Protected ------------------------------------------------------
176

177    // Package Private ------------------------------------------------
178

179    // Private --------------------------------------------------------
180

181    // Inner Classes --------------------------------------------------
182
}
183
Popular Tags