KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > server > RawDynamicInvoker


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.server;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.AttributeList JavaDoc;
26 import javax.management.AttributeNotFoundException JavaDoc;
27 import javax.management.DynamicMBean JavaDoc;
28 import javax.management.InvalidAttributeValueException JavaDoc;
29 import javax.management.MBeanException JavaDoc;
30 import javax.management.MBeanInfo JavaDoc;
31 import javax.management.MBeanRegistration JavaDoc;
32 import javax.management.MBeanServer JavaDoc;
33 import javax.management.NotCompliantMBeanException JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35 import javax.management.ReflectionException JavaDoc;
36
37
38 /**
39  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
40  * @version $Revision: 37459 $
41  *
42  */

43 public class RawDynamicInvoker
44    extends AbstractMBeanInvoker
45 {
46    
47    private DynamicMBean JavaDoc typedRes = null;
48    
49    public RawDynamicInvoker(DynamicMBean JavaDoc resource)
50    {
51       super(resource);
52       this.typedRes = resource;
53    }
54    
55    // DynamicMBean overrides ----------------------------------------
56

57    public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc,
58       InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
59    {
60       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
61       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
62       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
63       if(setCl)
64       {
65          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
66       }
67
68       try
69       {
70          typedRes.setAttribute(attribute);
71       }
72       finally
73       {
74          if(setCl)
75          {
76             TCLAction.UTIL.setContextClassLoader(ccl);
77          }
78       }
79    }
80    
81    public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
82    {
83       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
84       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
85       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
86       if(setCl)
87       {
88          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
89       }
90
91       try
92       {
93          return typedRes.setAttributes(attributes);
94       }
95       finally
96       {
97          if(setCl)
98          {
99             TCLAction.UTIL.setContextClassLoader(ccl);
100          }
101       }
102    }
103    
104    public Object JavaDoc getAttribute(String JavaDoc name) throws AttributeNotFoundException JavaDoc,
105          MBeanException JavaDoc, ReflectionException JavaDoc
106    {
107       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
108       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
109       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
110       if(setCl)
111       {
112          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
113       }
114
115       try
116       {
117          return typedRes.getAttribute(name);
118       }
119       finally
120       {
121          if(setCl)
122          {
123             TCLAction.UTIL.setContextClassLoader(ccl);
124          }
125       }
126    }
127    
128    public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
129    {
130       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
131       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
132       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
133       if(setCl)
134       {
135          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
136       }
137
138       try
139       {
140          return typedRes.getAttributes(attributes);
141       }
142       finally
143       {
144          if(setCl)
145          {
146             TCLAction.UTIL.setContextClassLoader(ccl);
147          }
148       }
149    }
150    
151    public Object JavaDoc invoke(String JavaDoc name, Object JavaDoc[] args, String JavaDoc[] signature) throws
152          MBeanException JavaDoc, ReflectionException JavaDoc
153    {
154       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
155       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
156       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
157       if(setCl)
158       {
159          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
160       }
161
162       try
163       {
164          return typedRes.invoke(name, args, signature);
165       }
166       finally
167       {
168          if(setCl)
169          {
170             TCLAction.UTIL.setContextClassLoader(ccl);
171          }
172       }
173    }
174    
175    public MBeanInfo JavaDoc getMBeanInfo()
176    {
177       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
178       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
179       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
180       if(setCl)
181       {
182          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
183       }
184
185       try
186       {
187          return typedRes.getMBeanInfo();
188       }
189       finally
190       {
191          if(setCl)
192          {
193             TCLAction.UTIL.setContextClassLoader(ccl);
194          }
195       }
196    }
197    
198    // MBeanRegistration overrides -----------------------------------
199
public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc oname) throws Exception JavaDoc
200    {
201       this.resourceEntry = AbstractMBeanInvoker.getMBeanEntry();
202
203       try
204       {
205          this.info = getMBeanInfo();
206       }
207       catch (Exception JavaDoc e)
208       {
209          throw new NotCompliantMBeanException JavaDoc("Cannot obtain MBeanInfo, for: " + oname);
210       }
211
212       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
213       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
214       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
215       if(setCl)
216       {
217          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
218       }
219
220       try
221       {
222          if (getResource() instanceof MBeanRegistration JavaDoc)
223             return ((MBeanRegistration JavaDoc)getResource()).preRegister(server, oname);
224          else
225             return oname;
226       }
227       finally
228       {
229          if(setCl)
230          {
231             TCLAction.UTIL.setContextClassLoader(ccl);
232          }
233       }
234    }
235    
236    public void postRegister(Boolean JavaDoc b)
237    {
238       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
239       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
240       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
241       if(setCl)
242       {
243          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
244       }
245
246       try
247       {
248          if (getResource() instanceof MBeanRegistration JavaDoc)
249             ((MBeanRegistration JavaDoc)getResource()).postRegister(b);
250       }
251       finally
252       {
253          TCLAction.UTIL.setContextClassLoader(ccl);
254       }
255    }
256    
257    public void preDeregister() throws Exception JavaDoc
258    {
259       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
260       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
261       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
262       if(setCl)
263       {
264          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
265       }
266
267       try
268       {
269          if (getResource() instanceof MBeanRegistration JavaDoc)
270             ((MBeanRegistration JavaDoc)getResource()).preDeregister();
271       }
272       finally
273       {
274          if(setCl)
275          {
276             TCLAction.UTIL.setContextClassLoader(ccl);
277          }
278       }
279    }
280    
281    public void postDeregister()
282    {
283       ClassLoader JavaDoc mbeanTCL = resourceEntry.getClassLoader();
284       final ClassLoader JavaDoc ccl = TCLAction.UTIL.getContextClassLoader();
285       boolean setCl = ccl != mbeanTCL && mbeanTCL != null;
286       if(setCl)
287       {
288          TCLAction.UTIL.setContextClassLoader(mbeanTCL);
289       }
290
291       try
292       {
293          if (getResource() instanceof MBeanRegistration JavaDoc)
294             ((MBeanRegistration JavaDoc)getResource()).postDeregister();
295       }
296       finally
297       {
298          if(setCl)
299          {
300             TCLAction.UTIL.setContextClassLoader(ccl);
301          }
302       }
303    }
304 }
305
Popular Tags