001: /*
002: * <copyright>
003: *
004: * Copyright 2003-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.node;
028:
029: import java.io.File;
030: import java.io.FileNotFoundException;
031: import java.io.IOException;
032: import java.io.InputStream;
033: import java.io.InputStreamReader;
034: import java.net.MalformedURLException;
035: import java.net.URL;
036: import java.util.Iterator;
037: import java.util.List;
038:
039: import org.w3c.dom.Document;
040:
041: import org.cougaar.core.service.ConfigurationService;
042:
043: import org.cougaar.bootstrap.SystemProperties;
044: import org.cougaar.core.agent.Agent;
045: import org.cougaar.core.component.*;
046: import org.cougaar.util.log.*;
047: import org.cougaar.util.ConfigFinder;
048:
049: /**
050: * This component advertises the {@link ConfigurationService},
051: * wrapping the {@link ConfigFinder}.
052: */
053: public class ConfigurationServiceComponent extends ComponentSupport {
054: private final ConfigurationService cs;
055:
056: public ConfigurationServiceComponent() {
057: cs = new CFAdapter(ConfigFinder.getInstance());
058: }
059:
060: private ServiceBroker rootsb; /*the whole-node broker*/
061:
062: private ServiceProvider sp; /*our service provider*/
063:
064: public void setNodeControlService(NodeControlService ncs) {
065: if (ncs != null) {
066: rootsb = ncs.getRootServiceBroker();
067: } else {
068: rootsb = null;
069: }
070: }
071:
072: public void load() {
073: super .load();
074: sp = new SP();
075: rootsb.addService(ConfigurationService.class, sp);
076: }
077:
078: public void unload() {
079: super .unload();
080: rootsb.revokeService(ConfigurationService.class, sp);
081: sp = null;
082: }
083:
084: private class SP implements ServiceProvider {
085: public Object getService(ServiceBroker sb, Object requestor,
086: Class serviceClass) {
087: return (ConfigurationService.class.equals(serviceClass) ? cs
088: : null);
089: }
090:
091: public void releaseService(ServiceBroker sb, Object requestor,
092: Class serviceClass, Object service) {
093: // ignore
094: }
095: }
096:
097: private class CFAdapter implements ConfigurationService {
098: private final ConfigFinder cf;
099:
100: private CFAdapter(ConfigFinder cf) {
101: this .cf = cf;
102: }
103:
104: public List getConfigurationPath() {
105: return cf.getConfigPath();
106: }
107:
108: public File locateFile(String filename) {
109: return cf.locateFile(filename);
110: }
111:
112: public URL resolveName(String name)
113: throws MalformedURLException {
114: return cf.resolveName(name);
115: }
116:
117: public InputStream open(String u) throws IOException {
118: return cf.open(u);
119: }
120:
121: public URL find(String u) throws IOException {
122: return cf.find(u);
123: }
124:
125: public Document parseXMLConfigFile(String f) throws IOException {
126: return cf.parseXMLConfigFile(f);
127: }
128: }
129: }
|