KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > jmxbean > JMXBeanConnector


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLConfigurationException.java
20  *
21  * JMXBeanConnector.java
22  *
23  * This object is responsible for retrieving a reference to the JMX bean when
24  * requested.
25  */

26
27 // package path
28
package com.rift.coad.lib.deployment.jmxbean;
29
30 // java imports
31
import java.util.Set JavaDoc;
32
33 // coadunation imports
34
import com.rift.coad.lib.bean.BeanWrapper;
35
36 /**
37  * This object is responsible for retrieving a reference to the JMX bean when
38  * requested.
39  *
40  * @author Brett Chaldecott
41  */

42 public class JMXBeanConnector {
43     
44     // the classes private member variables
45
private static JMXBeanConnector singleton = null;
46     private JMXBeanManager beanManager = null;
47     
48     /**
49      * Creates a new instance of JMXBeanConnector
50      */

51     private JMXBeanConnector(JMXBeanManager beanManager) {
52         this.beanManager = beanManager;
53     }
54     
55     
56     /**
57      * This method will be responsible for initializing the jmx bean connector.
58      *
59      * @param beanManager The reference to the bean manager.
60      */

61     public static synchronized void init(JMXBeanManager beanManager) {
62         if (singleton == null) {
63             singleton = new JMXBeanConnector(beanManager);
64         }
65     }
66     
67     
68     /**
69      * This method returns the JMXBean connector instance.
70      *
71      * @return The reference to the jmx bean connector.
72      * @exception JMXException
73      */

74     public static synchronized JMXBeanConnector getInstance()
75             throws JMXException {
76         if (singleton == null) {
77             throw new JMXException (
78                     "The JMX Bean connector has not been initialized.");
79         }
80         return singleton;
81     }
82     
83     
84     /**
85      * Retrieve the bind keys. These are the standard lookup keys.
86      *
87      * @return The list of beans managed by this object.
88      */

89     public Set JavaDoc getJMXBeanKeys() {
90         return beanManager.getBindKeys();
91     }
92     
93     
94     /**
95      * This method will return the reference to the wrapper object using the
96      * bind key identifier.
97      *
98      * @return The object identified by the bind key.
99      * @param key The bind key to retrieve the object for.
100      */

101     public Object JavaDoc getJMXBean(String JavaDoc key) {
102         BeanWrapper beanWrapper = (BeanWrapper)beanManager.getBindObject(key);
103         if (beanWrapper == null) {
104             return beanWrapper;
105         }
106         return beanWrapper.getProxy();
107     }
108 }
109
Popular Tags