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: import org.picocontainer.PicoContainer;
14:
15: /**
16: * Abstract base class for MBeanInfoProvider that search MBeanInfo in the PicoContainer registered with a key that
17: * follows naming conventions.
18: * @author Jörg Schaible
19: */
20: public abstract class AbstractNamingConventionMBeanInfoProvider
21: implements MBeanInfoProvider {
22:
23: /**
24: * Locate a MBeanInfo as component in a PicoContainer. If no component is registered using the name of the MBeanInfo
25: * as key, the method turns the name into a type and searches again.
26: * @param mBeanInfoName The name of the {@link MBeanInfo} used as key.
27: * @param picoContainer The {@link PicoContainer} used for the lookup.
28: * @param classLoader The {@link ClassLoader} used to load the type of the key.
29: * @return Returns the MBeanInfo instance or <code>null</code>.
30: */
31: protected MBeanInfo instantiateMBeanInfo(
32: final String mBeanInfoName,
33: final PicoContainer picoContainer, ClassLoader classLoader) {
34: MBeanInfo mBeanInfo = null;
35: try {
36: mBeanInfo = (MBeanInfo) picoContainer
37: .getComponent(mBeanInfoName);
38: } catch (final ClassCastException e) {
39: // wrong type, search goes on
40: }
41: if (mBeanInfo == null) {
42: if (classLoader == null) {
43: classLoader = Thread.currentThread()
44: .getContextClassLoader();
45: }
46: try {
47: final Class mBeanInfoType = classLoader
48: .loadClass(mBeanInfoName);
49: if (MBeanInfo.class.isAssignableFrom(mBeanInfoType)) {
50: mBeanInfo = (MBeanInfo) picoContainer
51: .getComponent(mBeanInfoType);
52: }
53: } catch (final ClassNotFoundException e) {
54: // no such class
55: }
56: }
57: return mBeanInfo;
58: }
59:
60: }
|