001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * XMLConfigurationException.java
020: *
021: * JMXBeanConnector.java
022: *
023: * This object is responsible for retrieving a reference to the JMX bean when
024: * requested.
025: */
026:
027: // package path
028: package com.rift.coad.lib.deployment.jmxbean;
029:
030: // java imports
031: import java.util.Set;
032:
033: // coadunation imports
034: import com.rift.coad.lib.bean.BeanWrapper;
035:
036: /**
037: * This object is responsible for retrieving a reference to the JMX bean when
038: * requested.
039: *
040: * @author Brett Chaldecott
041: */
042: public class JMXBeanConnector {
043:
044: // the classes private member variables
045: private static JMXBeanConnector singleton = null;
046: private JMXBeanManager beanManager = null;
047:
048: /**
049: * Creates a new instance of JMXBeanConnector
050: */
051: private JMXBeanConnector(JMXBeanManager beanManager) {
052: this .beanManager = beanManager;
053: }
054:
055: /**
056: * This method will be responsible for initializing the jmx bean connector.
057: *
058: * @param beanManager The reference to the bean manager.
059: */
060: public static synchronized void init(JMXBeanManager beanManager) {
061: if (singleton == null) {
062: singleton = new JMXBeanConnector(beanManager);
063: }
064: }
065:
066: /**
067: * This method returns the JMXBean connector instance.
068: *
069: * @return The reference to the jmx bean connector.
070: * @exception JMXException
071: */
072: public static synchronized JMXBeanConnector getInstance()
073: throws JMXException {
074: if (singleton == null) {
075: throw new JMXException(
076: "The JMX Bean connector has not been initialized.");
077: }
078: return singleton;
079: }
080:
081: /**
082: * Retrieve the bind keys. These are the standard lookup keys.
083: *
084: * @return The list of beans managed by this object.
085: */
086: public Set getJMXBeanKeys() {
087: return beanManager.getBindKeys();
088: }
089:
090: /**
091: * This method will return the reference to the wrapper object using the
092: * bind key identifier.
093: *
094: * @return The object identified by the bind key.
095: * @param key The bind key to retrieve the object for.
096: */
097: public Object getJMXBean(String key) {
098: BeanWrapper beanWrapper = (BeanWrapper) beanManager
099: .getBindObject(key);
100: if (beanWrapper == null) {
101: return beanWrapper;
102: }
103: return beanWrapper.getProxy();
104: }
105: }
|