01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: *
20: */
21:
22: package org.jacorb.notification.jmx;
23:
24: import javax.management.MalformedObjectNameException;
25: import javax.management.NotCompliantMBeanException;
26: import javax.management.ObjectName;
27:
28: import org.jacorb.notification.interfaces.JMXManageable;
29: import org.nanocontainer.remoting.jmx.DynamicMBeanProvider;
30: import org.nanocontainer.remoting.jmx.JMXRegistrationException;
31: import org.nanocontainer.remoting.jmx.JMXRegistrationInfo;
32: import org.picocontainer.ComponentAdapter;
33: import org.picocontainer.PicoContainer;
34:
35: public class JMXManageableMBeanProvider implements DynamicMBeanProvider {
36: private final String domain_;
37:
38: public JMXManageableMBeanProvider(String domain) {
39: super ();
40:
41: domain_ = domain;
42: }
43:
44: public JMXRegistrationInfo provide(PicoContainer picoContainer,
45: ComponentAdapter componentAdapter) {
46: final Object _componentInstance = componentAdapter
47: .getComponentInstance(picoContainer);
48:
49: try {
50: final JMXManageable _manageable = (JMXManageable) _componentInstance;
51:
52: Exception _exception = null;
53:
54: try {
55: return new JMXRegistrationInfo(ObjectName
56: .getInstance(domain_ + ":"
57: + _manageable.getJMXObjectName()),
58: new BroadcastSupportMBeanDecorator(_manageable));
59: } catch (MalformedObjectNameException e) {
60: _exception = e;
61: } catch (NotCompliantMBeanException e) {
62: _exception = e;
63: } catch (ClassNotFoundException e) {
64: _exception = e;
65: }
66:
67: throw new JMXRegistrationException(
68: "Cannot create MBean for component '"
69: + componentAdapter.getComponentKey() + "'",
70: _exception);
71:
72: } catch (ClassCastException e) {
73: return null;
74: }
75: }
76: }
|