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: * BeanConnector.java
022: *
023: * This class is responsible for supplying connections to the required beans.
024: */
025:
026: // package path
027: package com.rift.coad.lib.deployment.bean;
028:
029: // java imports
030: import java.util.Set;
031:
032: // coadunation imports
033: import com.rift.coad.lib.bean.BeanWrapper;
034:
035: /**
036: * This class is responsible for supplying connections to the required beans.
037: *
038: * @author Brett Chaldecott
039: */
040: public class BeanConnector {
041:
042: // the classes private member variables
043: private static BeanConnector singleton = null;
044: private BeanManager beanManager = null;
045:
046: /**
047: * Creates a new instance of BeanConnector
048: *
049: * @param beanManager The reference to the bean manager.
050: */
051: private BeanConnector(BeanManager beanManager) {
052: this .beanManager = beanManager;
053: }
054:
055: /**
056: * The method responsible for instanciating a new bean connector.
057: *
058: * @param beanManager The reference to the bean manager.
059: */
060: public static synchronized void init(BeanManager beanManager) {
061: if (singleton == null) {
062: singleton = new BeanConnector(beanManager);
063: }
064: }
065:
066: /**
067: * This method is responsible for returning a reference to the bean
068: * bean connector.
069: *
070: * @return The reference to the bean connector.
071: */
072: public static synchronized BeanConnector getInstance()
073: throws BeanException {
074: if (singleton == null) {
075: throw new BeanException(
076: "The bean connector has not bean initialized.");
077: }
078: return singleton;
079: }
080:
081: /**
082: * This method returns the list of keys.
083: *
084: * @return The list of beans managed by this object.
085: */
086: public Set getKeys() {
087: return beanManager.getKeys();
088: }
089:
090: /**
091: * Retrieve the bean that matches the key
092: *
093: * @return Return the object identified by the key.
094: * @param key The key identifying the bean.
095: */
096: public Object getBean(String key) {
097: BeanWrapper beanWrapper = (BeanWrapper) beanManager
098: .getBean(key);
099: if (beanWrapper == null) {
100: return beanWrapper;
101: }
102: return beanWrapper.getProxy();
103: }
104: }
|