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 Joerg Schaible                                           *
009 *****************************************************************************/
010
011package org.picocontainer.gems.jmx;
012
013import javax.management.DynamicMBean;
014import javax.management.MalformedObjectNameException;
015import javax.management.ObjectName;
016
017
018/**
019 * An ObjectNameFactory, that uses the type of the {@link DynamicMBean} implementation to register. The value of the
020 * type is the name of the implementation class without the package name.
021 * @author Jörg Schaible
022 */
023public class TypedObjectNameFactory extends AbstractObjectNameFactory {
024
025    /**
026     * Construct a TypedObjectNameFactory using the default domain. Using <code>TypedObjectNameFactory(null)</code> is
027     * equivalent.
028     */
029    public TypedObjectNameFactory() {
030        this(null);
031    }
032
033    /**
034     * Construct a TypedObjectNameFactory with a predefined domain.
035     * @param domain The domain.
036     */
037    public TypedObjectNameFactory(final String domain) {
038        super(domain);
039    }
040
041    /**
042     * Create an {@link ObjectName} with the class name of the MBean implementation as key <em>type</em>.
043     * @see org.picocontainer.gems.jmx.ObjectNameFactory#create(java.lang.Object, javax.management.DynamicMBean)
044     */
045    public ObjectName create(final Object key, final DynamicMBean mBean) throws MalformedObjectNameException {
046        final String className = mBean.getMBeanInfo().getClassName();
047        return new ObjectName(getDomain(), "type", className.substring(className.lastIndexOf('.') + 1));
048    }
049
050}