001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: J2EEManagedObjectMBean.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.jsr77;
025:
026: import javax.management.InstanceNotFoundException;
027: import javax.management.MBeanException;
028: import javax.management.RuntimeOperationsException;
029: import javax.management.modelmbean.InvalidTargetObjectTypeException;
030:
031: import org.apache.commons.modeler.BaseModelMBean;
032: import org.ow2.util.log.Log;
033: import org.ow2.util.log.LogFactory;
034:
035: /**
036: * J2EEManagedObject MBean Base.
037: * @author Guillaume Sauthier
038: * @param <T> ManagedObject type
039: */
040: public class J2EEManagedObjectMBean<T> extends BaseModelMBean {
041:
042: /**
043: * Logger.
044: */
045: private static Log logger = LogFactory
046: .getLog(J2EEManagedObjectMBean.class);
047:
048: /**
049: * Is the MBean an Event Provider ? (Optionnal support)
050: */
051: private static final boolean IS_EVENT_PROVIDER = false;
052:
053: /**
054: * Is the MBean a Statistics Provider ? (Optionnal support)
055: */
056: private static final boolean IS_STATISTICS_PROVIDER = false;
057:
058: /**
059: * Is the MBean State Manageable ? (Optionnal support)
060: */
061: private static final boolean IS_STATE_MANAGEABLE = false;
062:
063: /**
064: * Create the mbean.
065: * @throws MBeanException if the super constructor fails.
066: */
067: public J2EEManagedObjectMBean() throws MBeanException {
068: super ();
069: }
070:
071: /**
072: * @return the deployer (managed object)
073: */
074: @SuppressWarnings("unchecked")
075: protected T getManagedComponent() {
076: T deployer = null;
077: try {
078: deployer = (T) getManagedResource();
079: } catch (InstanceNotFoundException e) {
080: throw new IllegalStateException(
081: "Cannot get the managed resource of the MBean", e);
082: } catch (RuntimeOperationsException e) {
083: throw new IllegalStateException(
084: "Cannot get the managed resource of the MBean", e);
085: } catch (MBeanException e) {
086: throw new IllegalStateException(
087: "Cannot get the managed resource of the MBean", e);
088: } catch (InvalidTargetObjectTypeException e) {
089: throw new IllegalStateException(
090: "Cannot get the managed resource of the MBean", e);
091: }
092: return deployer;
093: }
094:
095: /**
096: * @return Returns true is the MBean can manage its state.
097: */
098: public boolean isStateManageable() {
099: return IS_STATE_MANAGEABLE;
100: }
101:
102: /**
103: * @return Returns true if this MBean can provides JSR77 Statistics.
104: */
105: public boolean isStatisticsProvider() {
106: return IS_STATISTICS_PROVIDER;
107: }
108:
109: /**
110: * @return Returns true if this MBean can provides JSR77 Events.
111: */
112: public boolean isEventProvider() {
113: return IS_EVENT_PROVIDER;
114: }
115:
116: /**
117: * @return Returns the logger.
118: */
119: protected static final Log getLogger() {
120: return logger;
121: }
122:
123: }
|