001: /*
002: * <copyright>
003: *
004: * Copyright 2002-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.wp.bootstrap;
028:
029: import java.util.Collection;
030: import java.util.Iterator;
031: import java.util.Map;
032: import org.cougaar.core.component.Component;
033: import org.cougaar.core.component.ServiceBroker;
034: import org.cougaar.core.component.ServiceProvider;
035: import org.cougaar.util.GenericStateModelAdapter;
036:
037: /**
038: * This component provides the {@link ConfigService} that loads the
039: * static {@link ConfigReader} contents.
040: * <p>
041: * The ConfigService supports changes and removals, but for now
042: * we don't use these methods.
043: */
044: public class ConfigManager extends GenericStateModelAdapter implements
045: Component {
046:
047: private ServiceBroker sb;
048:
049: private ConfigSP configSP;
050:
051: public void setServiceBroker(ServiceBroker sb) {
052: this .sb = sb;
053: }
054:
055: public void load() {
056: super .load();
057:
058: // advertise our service
059: configSP = new ConfigSP();
060: sb.addService(ConfigService.class, configSP);
061: }
062:
063: public void unload() {
064: if (configSP != null) {
065: sb.revokeService(ConfigService.class, configSP);
066: configSP = null;
067: }
068:
069: super .unload();
070: }
071:
072: protected Map getBundles() {
073: return ConfigReader.getBundles();
074: }
075:
076: private class ConfigSP implements ServiceProvider {
077: private final ConfigService INSTANCE = new ConfigService() {
078: public Map getBundles() {
079: return ConfigManager.this .getBundles();
080: }
081: };
082:
083: public Object getService(ServiceBroker sb, Object requestor,
084: Class serviceClass) {
085: if (!ConfigService.class.isAssignableFrom(serviceClass)) {
086: return null;
087: }
088: if (requestor instanceof ConfigService.Client) {
089: // initialize client
090: ConfigService.Client csc = (ConfigService.Client) requestor;
091: Map m = ConfigManager.this .getBundles();
092: if (m != null) {
093: for (Iterator iter = m.values().iterator(); iter
094: .hasNext();) {
095: Bundle b = (Bundle) iter.next();
096: csc.add(b);
097: }
098: }
099: }
100: return INSTANCE;
101: }
102:
103: public void releaseService(ServiceBroker sb, Object requestor,
104: Class serviceClass, Object service) {
105: }
106: }
107: }
|