KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > mxbean > MXBeanSupport


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.mxbean;
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.ListenerNotFoundException JavaDoc;
30 import javax.management.MBeanException JavaDoc;
31 import javax.management.MBeanInfo JavaDoc;
32 import javax.management.MBeanNotificationInfo JavaDoc;
33 import javax.management.MBeanRegistration JavaDoc;
34 import javax.management.MBeanServer JavaDoc;
35 import javax.management.NotificationEmitter JavaDoc;
36 import javax.management.NotificationFilter JavaDoc;
37 import javax.management.NotificationListener JavaDoc;
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.ReflectionException JavaDoc;
40
41 /**
42  * MXBeanSupport.
43  *
44  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
45  * @version $Revision: 1.1 $
46  */

47 public class MXBeanSupport implements DynamicMBean JavaDoc, MBeanRegistration JavaDoc, NotificationEmitter JavaDoc
48 {
49    /** No notifications */
50    private static final MBeanNotificationInfo JavaDoc[] NO_NOTIFICATIONS = new MBeanNotificationInfo JavaDoc[0];
51    
52    /** The delegate */
53    private DynamicMBean JavaDoc delegate;
54    
55    /** The mbean registration delegate */
56    private MBeanRegistration JavaDoc registration;
57    
58    /** The emitter delegate */
59    private NotificationEmitter JavaDoc emitter;
60    
61    /**
62     * Create a new MXBeanSupport.
63     */

64    protected MXBeanSupport()
65    {
66       init(MXBeanUtils.createMXBean(this, null));
67    }
68
69    /**
70     * Create a new MXBeanSupport.
71     *
72     * @param mxbeanInterface the interface
73     */

74    protected MXBeanSupport(Class JavaDoc<?> mxbeanInterface)
75    {
76       init(MXBeanUtils.createMXBean(this, mxbeanInterface));
77    }
78    
79    public MBeanInfo JavaDoc getMBeanInfo()
80    {
81       return delegate.getMBeanInfo();
82    }
83
84    public Object JavaDoc getAttribute(String JavaDoc attribute) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
85    {
86       return delegate.getAttribute(attribute);
87    }
88
89    public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
90    {
91       return delegate.getAttributes(attributes);
92    }
93
94    public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
95    {
96       delegate.setAttribute(attribute);
97    }
98
99    public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
100    {
101       return delegate.setAttributes(attributes);
102    }
103
104    public Object JavaDoc invoke(String JavaDoc actionName, Object JavaDoc[] params, String JavaDoc[] signature) throws MBeanException JavaDoc, ReflectionException JavaDoc
105    {
106       return delegate.invoke(actionName, params, signature);
107    }
108
109    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws Exception JavaDoc
110    {
111       return registration.preRegister(server, name);
112    }
113
114    public void postRegister(Boolean JavaDoc registrationDone)
115    {
116       registration.postDeregister();
117    }
118
119    public void preDeregister() throws Exception JavaDoc
120    {
121       registration.preDeregister();
122    }
123
124    public void postDeregister()
125    {
126       registration.postDeregister();
127    }
128
129    public MBeanNotificationInfo JavaDoc[] getNotificationInfo()
130    {
131       return NO_NOTIFICATIONS;
132    }
133
134    public void addNotificationListener(NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback) throws IllegalArgumentException JavaDoc
135    {
136       emitter.addNotificationListener(listener, filter, handback);
137       
138    }
139
140    public void removeNotificationListener(NotificationListener JavaDoc listener) throws ListenerNotFoundException JavaDoc
141    {
142       emitter.removeNotificationListener(listener);
143    }
144    
145    public void removeNotificationListener(NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback) throws ListenerNotFoundException JavaDoc
146    {
147       emitter.removeNotificationListener(listener, filter, handback);
148    }
149
150    /**
151     * Initialise the delegates
152     *
153     * @param delegate the delegate
154     */

155    private void init(DynamicMBean JavaDoc delegate)
156    {
157       this.delegate = delegate;
158       this.registration = (MBeanRegistration JavaDoc) delegate;
159       this.emitter = (NotificationEmitter JavaDoc) delegate;
160    }
161 }
162
Popular Tags