01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by Joerg Schaible *
09: *****************************************************************************/package org.picocontainer.gems.jmx;
10:
11: import javax.management.DynamicMBean;
12: import javax.management.MalformedObjectNameException;
13: import javax.management.ObjectName;
14:
15: /**
16: * An ObjectNameFactory, that uses the type of the {@link DynamicMBean} implementation to register. The value of the
17: * type is the name of the implementation class without the package name.
18: * @author Jörg Schaible
19: */
20: public class TypedObjectNameFactory extends AbstractObjectNameFactory {
21:
22: /**
23: * Construct a TypedObjectNameFactory using the default domain. Using <code>TypedObjectNameFactory(null)</code> is
24: * equivalent.
25: */
26: public TypedObjectNameFactory() {
27: this (null);
28: }
29:
30: /**
31: * Construct a TypedObjectNameFactory with a predefined domain.
32: * @param domain The domain.
33: */
34: public TypedObjectNameFactory(final String domain) {
35: super (domain);
36: }
37:
38: /**
39: * Create an {@link ObjectName} with the class name of the MBean implementation as key <em>type</em>.
40: * @see org.picocontainer.gems.jmx.ObjectNameFactory#create(java.lang.Object, javax.management.DynamicMBean)
41: */
42: public ObjectName create(final Object key, final DynamicMBean mBean)
43: throws MalformedObjectNameException {
44: final String className = mBean.getMBeanInfo().getClassName();
45: return new ObjectName(getDomain(), "type", className
46: .substring(className.lastIndexOf('.') + 1));
47: }
48:
49: }
|