    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     * Original code by Michael Ward                                                 *
    009     *****************************************************************************/
    010
    011    package org.picocontainer.gems.jmx.mx4j;
    012
    013    import javax.management.DynamicMBean;
    014    import javax.management.MBeanInfo;
    015
    016    import org.picocontainer.gems.jmx.StandardMBeanFactory;
    017
    018
    019    /**
    020     * This is the a factory for creating DynamicMBean instances. However it is tied specifically to MX4J. Those not
    021     * interested in being dependent on MX4J should implement another Factory and register it to the container. The single
    022     * difference to the StandardMBeanFactory is, that it does not need a special management interface for a component to
    023     * expose.
    024     * @author Michael Ward
    025     */
    026    public class MX4JDynamicMBeanFactory extends StandardMBeanFactory {
    027
    028        /**
    029         * Create a MX4JDynamicMBean for the component. MX4J is only used, if management is <code>null</code>.
    030         * @see org.picocontainer.gems.jmx.StandardMBeanFactory#create(java.lang.Object, java.lang.Class,
    031         *      javax.management.MBeanInfo)
    032         */
    033        @Override
    034            public DynamicMBean create(final Object componentInstance, final Class management, final MBeanInfo mBeanInfo) {
    035            if (management != null || mBeanInfo == null) {
    036                return super.create(componentInstance, management, mBeanInfo);
    037            } else {
    038                return new MX4JDynamicMBean(componentInstance, mBeanInfo);
    039            }
    040        }
    041    }