Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AbstractStandardMBean.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Marc Wick.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.jmx;
00026 
00027 import javax.management.ListenerNotFoundException;
00028 import javax.management.MBeanAttributeInfo;
00029 import javax.management.MBeanConstructorInfo;
00030 import javax.management.MBeanInfo;
00031 import javax.management.MBeanNotificationInfo;
00032 import javax.management.MBeanOperationInfo;
00033 import javax.management.MBeanParameterInfo;
00034 import javax.management.NotCompliantMBeanException;
00035 import javax.management.Notification;
00036 import javax.management.NotificationBroadcasterSupport;
00037 import javax.management.NotificationEmitter;
00038 import javax.management.NotificationFilter;
00039 import javax.management.NotificationListener;
00040 import javax.management.StandardMBean;
00041 
00042 import org.objectweb.cjdbc.common.i18n.JmxTranslate;
00043 
00044 /**
00045  * This class defines a AbstractStandardMBean
00046  * 
00047  * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
00048  * @version 1.0
00049  */
00050 public abstract class AbstractStandardMBean extends StandardMBean
00051     implements
00052       NotificationEmitter
00053 {
00054   /**
00055    * the broadcaster instance we write a wrapper for
00056    */
00057   private transient NotificationBroadcasterSupport broadcaster;
00058 
00059   /**
00060    * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
00061    *      javax.management.NotificationFilter, java.lang.Object)
00062    */
00063   public void addNotificationListener(NotificationListener listener,
00064       NotificationFilter filter, Object handback)
00065   {
00066     broadcaster.addNotificationListener(listener, filter, handback);
00067   }
00068 
00069   /**
00070    * @see javax.management.NotificationBroadcaster#getNotificationInfo()
00071    */
00072   public MBeanNotificationInfo[] getNotificationInfo()
00073   {
00074     // is the broadcaster already initialized ?
00075     if (broadcaster == null)
00076       // no we return empty array
00077       return new MBeanNotificationInfo[0];
00078 
00079     return broadcaster.getNotificationInfo();
00080   }
00081 
00082   /**
00083    * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
00084    */
00085   public void removeNotificationListener(NotificationListener listener)
00086       throws ListenerNotFoundException
00087   {
00088     broadcaster.removeNotificationListener(listener);
00089   }
00090 
00091   /**
00092    * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener,
00093    *      javax.management.NotificationFilter, java.lang.Object)
00094    */
00095   public void removeNotificationListener(NotificationListener listener,
00096       NotificationFilter filter, Object handback)
00097       throws ListenerNotFoundException
00098   {
00099     broadcaster.removeNotificationListener(listener, filter, handback);
00100   }
00101 
00102   /**
00103    * Sends a notification.
00104    * 
00105    * @param notification The notification to send.
00106    */
00107   public void sendNotification(Notification notification)
00108   {
00109     broadcaster.sendNotification(notification);
00110   }
00111 
00112   /*****************************************************************************
00113    * StandardMBean methods
00114    ****************************************************************************/
00115 
00116   /**
00117    * Creates a new <code>AbstractStandardMBean.java</code> object
00118    * 
00119    * @param mbeanInterface The Management Interface exported by this MBean.
00120    * @throws NotCompliantMBeanException - if the mbeanInterface does not follow
00121    *           JMX design patterns for Management Interfaces, or if this does
00122    *           not implement the specified interface.
00123    */
00124   public AbstractStandardMBean(Class mbeanInterface)
00125       throws NotCompliantMBeanException
00126   {
00127     super(mbeanInterface);
00128     broadcaster = new NotificationBroadcasterSupport();
00129   }
00130 
00131   /**
00132    * Allow to retrieve internationalization description on mbeans as well
00133    * 
00134    * @return part of the key to look for in the translation file.
00135    */
00136   public abstract String getAssociatedString();
00137 
00138   /**
00139    * Returns the description of the MBean.
00140    * 
00141    * @return a <code>String</code> containing the description
00142    */
00143   protected String getDescription(MBeanInfo info)
00144   {
00145     return JmxTranslate.get("mbean." + getAssociatedString() + ".description");
00146   }
00147 
00148   /**
00149    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo)
00150    */
00151   protected String getDescription(MBeanConstructorInfo ctor)
00152   {
00153     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
00154         + ctor.getSignature().length);
00155   }
00156 
00157   /**
00158    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanConstructorInfo,
00159    *      javax.management.MBeanParameterInfo, int)
00160    */
00161   protected String getParameterName(MBeanConstructorInfo ctor,
00162       MBeanParameterInfo param, int sequence)
00163   {
00164     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
00165         + ctor.getSignature().length + ".parameter.name." + sequence);
00166   }
00167 
00168   /**
00169    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo,
00170    *      javax.management.MBeanParameterInfo, int)
00171    */
00172   protected String getDescription(MBeanConstructorInfo ctor,
00173       MBeanParameterInfo param, int sequence)
00174   {
00175     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
00176         + ctor.getSignature().length + ".parameter.description." + sequence);
00177   }
00178 
00179   /**
00180    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanAttributeInfo)
00181    */
00182   protected String getDescription(MBeanAttributeInfo info)
00183   {
00184     return JmxTranslate.get("mbean." + getAssociatedString() + ".attribute."
00185         + info.getName());
00186   }
00187 
00188   /**
00189    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo)
00190    */
00191   protected String getDescription(MBeanOperationInfo info)
00192   {
00193     return JmxTranslate.get("mbean." + getAssociatedString() + "."
00194         + info.getName());
00195   }
00196 
00197   /**
00198    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanOperationInfo,
00199    *      javax.management.MBeanParameterInfo, int)
00200    */
00201   protected String getParameterName(MBeanOperationInfo op,
00202       MBeanParameterInfo param, int sequence)
00203   {
00204     return JmxTranslate.get("mbean." + getAssociatedString() + "."
00205         + op.getName() + ".parameter.name." + sequence);
00206   }
00207 
00208   /**
00209    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo,
00210    *      javax.management.MBeanParameterInfo, int)
00211    */
00212   protected String getDescription(MBeanOperationInfo op,
00213       MBeanParameterInfo param, int sequence)
00214   {
00215     return JmxTranslate.get("mbean." + getAssociatedString() + "."
00216         + op.getName() + ".parameter.description." + sequence);
00217   }
00218 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1