KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > jmx > AbstractStandardMBean


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.jmx;
26
27 import javax.management.ListenerNotFoundException JavaDoc;
28 import javax.management.MBeanAttributeInfo JavaDoc;
29 import javax.management.MBeanConstructorInfo JavaDoc;
30 import javax.management.MBeanInfo JavaDoc;
31 import javax.management.MBeanNotificationInfo JavaDoc;
32 import javax.management.MBeanOperationInfo JavaDoc;
33 import javax.management.MBeanParameterInfo JavaDoc;
34 import javax.management.NotCompliantMBeanException JavaDoc;
35 import javax.management.Notification JavaDoc;
36 import javax.management.NotificationBroadcasterSupport JavaDoc;
37 import javax.management.NotificationEmitter JavaDoc;
38 import javax.management.NotificationFilter JavaDoc;
39 import javax.management.NotificationListener JavaDoc;
40 import javax.management.StandardMBean JavaDoc;
41
42 import org.objectweb.cjdbc.common.i18n.JmxTranslate;
43
44 /**
45  * This class defines a AbstractStandardMBean
46  *
47  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
48  * @version 1.0
49  */

50 public abstract class AbstractStandardMBean extends StandardMBean JavaDoc
51     implements
52       NotificationEmitter JavaDoc
53 {
54   /**
55    * the broadcaster instance we write a wrapper for
56    */

57   private transient NotificationBroadcasterSupport JavaDoc broadcaster;
58
59   /**
60    * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
61    * javax.management.NotificationFilter, java.lang.Object)
62    */

63   public void addNotificationListener(NotificationListener JavaDoc listener,
64       NotificationFilter JavaDoc filter, Object JavaDoc handback)
65   {
66     broadcaster.addNotificationListener(listener, filter, handback);
67   }
68
69   /**
70    * @see javax.management.NotificationBroadcaster#getNotificationInfo()
71    */

72   public MBeanNotificationInfo JavaDoc[] getNotificationInfo()
73   {
74     // is the broadcaster already initialized ?
75
if (broadcaster == null)
76       // no we return empty array
77
return new MBeanNotificationInfo JavaDoc[0];
78
79     return broadcaster.getNotificationInfo();
80   }
81
82   /**
83    * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
84    */

85   public void removeNotificationListener(NotificationListener JavaDoc listener)
86       throws ListenerNotFoundException JavaDoc
87   {
88     broadcaster.removeNotificationListener(listener);
89   }
90
91   /**
92    * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener,
93    * javax.management.NotificationFilter, java.lang.Object)
94    */

95   public void removeNotificationListener(NotificationListener JavaDoc listener,
96       NotificationFilter JavaDoc filter, Object JavaDoc handback)
97       throws ListenerNotFoundException JavaDoc
98   {
99     broadcaster.removeNotificationListener(listener, filter, handback);
100   }
101
102   /**
103    * Sends a notification.
104    *
105    * @param notification The notification to send.
106    */

107   public void sendNotification(Notification JavaDoc notification)
108   {
109     broadcaster.sendNotification(notification);
110   }
111
112   /*****************************************************************************
113    * StandardMBean methods
114    ****************************************************************************/

115
116   /**
117    * Creates a new <code>AbstractStandardMBean.java</code> object
118    *
119    * @param mbeanInterface The Management Interface exported by this MBean.
120    * @throws NotCompliantMBeanException - if the mbeanInterface does not follow
121    * JMX design patterns for Management Interfaces, or if this does
122    * not implement the specified interface.
123    */

124   public AbstractStandardMBean(Class JavaDoc mbeanInterface)
125       throws NotCompliantMBeanException JavaDoc
126   {
127     super(mbeanInterface);
128     broadcaster = new NotificationBroadcasterSupport JavaDoc();
129   }
130
131   /**
132    * Allow to retrieve internationalization description on mbeans as well
133    *
134    * @return part of the key to look for in the translation file.
135    */

136   public abstract String JavaDoc getAssociatedString();
137
138   /**
139    * Returns the description of the MBean.
140    *
141    * @return a <code>String</code> containing the description
142    */

143   protected String JavaDoc getDescription(MBeanInfo JavaDoc info)
144   {
145     return JmxTranslate.get("mbean." + getAssociatedString() + ".description");
146   }
147
148   /**
149    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo)
150    */

151   protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc ctor)
152   {
153     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
154         + ctor.getSignature().length);
155   }
156
157   /**
158    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanConstructorInfo,
159    * javax.management.MBeanParameterInfo, int)
160    */

161   protected String JavaDoc getParameterName(MBeanConstructorInfo JavaDoc ctor,
162       MBeanParameterInfo JavaDoc param, int sequence)
163   {
164     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
165         + ctor.getSignature().length + ".parameter.name." + sequence);
166   }
167
168   /**
169    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo,
170    * javax.management.MBeanParameterInfo, int)
171    */

172   protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc ctor,
173       MBeanParameterInfo JavaDoc param, int sequence)
174   {
175     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
176         + ctor.getSignature().length + ".parameter.description." + sequence);
177   }
178
179   /**
180    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanAttributeInfo)
181    */

182   protected String JavaDoc getDescription(MBeanAttributeInfo JavaDoc info)
183   {
184     return JmxTranslate.get("mbean." + getAssociatedString() + ".attribute."
185         + info.getName());
186   }
187
188   /**
189    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo)
190    */

191   protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc info)
192   {
193     return JmxTranslate.get("mbean." + getAssociatedString() + "."
194         + info.getName());
195   }
196
197   /**
198    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanOperationInfo,
199    * javax.management.MBeanParameterInfo, int)
200    */

201   protected String JavaDoc getParameterName(MBeanOperationInfo JavaDoc op,
202       MBeanParameterInfo JavaDoc param, int sequence)
203   {
204     return JmxTranslate.get("mbean." + getAssociatedString() + "."
205         + op.getName() + ".parameter.name." + sequence);
206   }
207
208   /**
209    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo,
210    * javax.management.MBeanParameterInfo, int)
211    */

212   protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc op,
213       MBeanParameterInfo JavaDoc param, int sequence)
214   {
215     return JmxTranslate.get("mbean." + getAssociatedString() + "."
216         + op.getName() + ".parameter.description." + sequence);
217   }
218 }
Popular Tags