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.MBeanInfo;
12:
13: /**
14: * A DynamicMBeanProvider that constructs StandardMBean instances that follow the JMX naming conventions. The name of
15: * the management interface must follow the naming conventions with an <em>MBean</em> appended to the MBean's type.
16: * The implementation will use the registered MBeanInfoProvider instances of type
17: * {@link ComponentKeyConventionMBeanInfoProvider} and {@link ComponentTypeConventionMBeanInfoProvider} to provide a
18: * {@link MBeanInfo} for the component's MBean. If a {@link MBeanInfo} was found, the MBean's type is used from the
19: * MBeanInfo otherwise the type is the implementation class of the component.
20: * @author Jörg Schaible
21: */
22: public class NamingConventionConstructingProvider extends
23: AbstractConstructingProvider {
24:
25: private final ObjectNameFactory objectNameFactory;
26: private final MBeanInfoProvider[] mBeanProviders;
27: private final StandardMBeanFactory mBeanFactory;
28:
29: /**
30: * Construct a NamingConventionConstructingProvider. Following {@link MBeanInfoProvider} instances are registered
31: * with this constructor:
32: * <ul>
33: * <li>{@link ComponentKeyConventionMBeanInfoProvider}</li>
34: * <li>{@link ComponentTypeConventionMBeanInfoProvider}</li>
35: * </ul>
36: * @param factory The ObjectNameFactory used to name the created MBeans.
37: */
38: public NamingConventionConstructingProvider(
39: final ObjectNameFactory factory) {
40: if (factory == null) {
41: throw new NullPointerException("ObjectNameFactory is null");
42: }
43: mBeanFactory = new StandardMBeanFactory();
44: objectNameFactory = factory;
45: mBeanProviders = new MBeanInfoProvider[] {
46: new ComponentKeyConventionMBeanInfoProvider(),
47: new ComponentTypeConventionMBeanInfoProvider() };
48: }
49:
50: /**
51: * Return a {@link StandardMBeanFactory}.
52: * @see org.picocontainer.gems.jmx.AbstractConstructingProvider#getMBeanFactory()
53: */
54: protected DynamicMBeanFactory getMBeanFactory() {
55: return mBeanFactory;
56: }
57:
58: /**
59: * @see org.picocontainer.gems.jmx.AbstractConstructingProvider#getObjectNameFactory()
60: */
61: public ObjectNameFactory getObjectNameFactory() {
62: return objectNameFactory;
63: }
64:
65: /**
66: * Return an array with an instance of type {@link ComponentKeyConventionMBeanInfoProvider} and
67: * {@link ComponentTypeConventionMBeanInfoProvider}.
68: * @see org.picocontainer.gems.jmx.AbstractConstructingProvider#getMBeanInfoProviders()
69: */
70: public MBeanInfoProvider[] getMBeanInfoProviders() {
71: return mBeanProviders;
72: }
73:
74: /**
75: * Determin the default management interface using naming convetions of the JMX specification.
76: * @param implementation The type of the component's implementation.
77: * @param mBeanInfo The {@link MBeanInfo} to expose the component. May be <code>null</code>.
78: * @return Returns the management interface.
79: * @throws ClassNotFoundException Thrown if no interface can be determined.
80: */
81: protected Class getManagementInterface(final Class implementation,
82: final MBeanInfo mBeanInfo) throws ClassNotFoundException {
83: return mBeanFactory.getDefaultManagementInterface(
84: implementation, mBeanInfo);
85: }
86: }
|