KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > bean > BeanConnector


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  * BeanConnector.java
22  *
23  * This class is responsible for supplying connections to the required beans.
24  */

25
26 // package path
27
package com.rift.coad.lib.deployment.bean;
28
29 // java imports
30
import java.util.Set JavaDoc;
31
32 // coadunation imports
33
import com.rift.coad.lib.bean.BeanWrapper;
34
35 /**
36  * This class is responsible for supplying connections to the required beans.
37  *
38  * @author Brett Chaldecott
39  */

40 public class BeanConnector {
41     
42     // the classes private member variables
43
private static BeanConnector singleton = null;
44     private BeanManager beanManager = null;
45     
46     /**
47      * Creates a new instance of BeanConnector
48      *
49      * @param beanManager The reference to the bean manager.
50      */

51     private BeanConnector(BeanManager beanManager) {
52         this.beanManager = beanManager;
53     }
54     
55     
56     /**
57      * The method responsible for instanciating a new bean connector.
58      *
59      * @param beanManager The reference to the bean manager.
60      */

61     public static synchronized void init(BeanManager beanManager) {
62         if (singleton == null) {
63             singleton = new BeanConnector(beanManager);
64         }
65     }
66     
67     
68     /**
69      * This method is responsible for returning a reference to the bean
70      * bean connector.
71      *
72      * @return The reference to the bean connector.
73      */

74     public static synchronized BeanConnector getInstance() throws BeanException {
75         if (singleton == null) {
76             throw new BeanException(
77                     "The bean connector has not bean initialized.");
78         }
79         return singleton;
80     }
81     
82     
83     /**
84      * This method returns the list of keys.
85      *
86      * @return The list of beans managed by this object.
87      */

88     public Set JavaDoc getKeys() {
89         return beanManager.getKeys();
90     }
91     
92     
93     /**
94      * Retrieve the bean that matches the key
95      *
96      * @return Return the object identified by the key.
97      * @param key The key identifying the bean.
98      */

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