01: /*
02: * <copyright>
03: *
04: * Copyright 2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26: package org.cougaar.core.node;
27:
28: import org.cougaar.core.component.Component;
29: import org.cougaar.core.component.ServiceBroker;
30: import org.cougaar.core.component.ServiceProvider;
31: import org.cougaar.core.service.LoggingService;
32: import org.cougaar.util.GenericStateModelAdapter;
33:
34: /**
35: * This component advertises the INI-based {@link
36: * ComponentInitializerService}.
37: *
38: * @see FileComponentInitializerServiceProvider
39: */
40: public class FileComponentInitializerServiceComponent extends
41: GenericStateModelAdapter implements Component {
42: private ServiceBroker sb;
43:
44: private ServiceProvider theSP;
45: private LoggingService log;
46:
47: public void setServiceBroker(ServiceBroker sb) {
48: // this is the *node* service broker! The NodeControlService
49: // is not available until the node-agent is created...
50: this .sb = sb;
51: }
52:
53: public void load() {
54: super .load();
55: log = (LoggingService) sb.getService(this ,
56: LoggingService.class, null);
57: if (log == null) {
58: log = LoggingService.NULL;
59: }
60:
61: if (sb.hasService(ComponentInitializerService.class)) {
62: // already have a ComponentInitializer?
63: // Leave the existing one in place
64: if (log.isInfoEnabled()) {
65: log
66: .info("Not loading the FileComponentInitializer service");
67: }
68: } else {
69: try {
70: theSP = new FileComponentInitializerServiceProvider();
71: } catch (Exception e) {
72: log
73: .error(
74: "Unable to load FileComponentInitializerService",
75: e);
76: }
77: if (log.isDebugEnabled())
78: log.debug("Providing File (INI) Init service");
79: sb.addService(ComponentInitializerService.class, theSP);
80: }
81:
82: if (log != LoggingService.NULL) {
83: sb.releaseService(this , LoggingService.class, log);
84: log = null;
85: }
86: }
87:
88: public void unload() {
89: if (theSP != null) {
90: sb.revokeService(ComponentInitializerService.class, theSP);
91: theSP = null;
92: }
93: super.unload();
94: }
95: }
|