01: /*
02: * <copyright>
03: *
04: * Copyright 1997-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:
27: package org.cougaar.core.node;
28:
29: import org.cougaar.core.component.Component;
30: import org.cougaar.core.component.ServiceBroker;
31: import org.cougaar.core.component.ServiceProvider;
32: import org.cougaar.util.GenericStateModelAdapter;
33: import org.cougaar.util.log.Logger;
34: import org.cougaar.util.log.Logging;
35:
36: /**
37: * This component advertises the XML-based {@link
38: * ComponentInitializerService}.
39: *
40: * @see XMLComponentInitializerServiceProvider
41: */
42: public class XMLComponentInitializerServiceComponent extends
43: GenericStateModelAdapter implements Component {
44: private ServiceBroker sb;
45:
46: private ServiceProvider theSP;
47:
48: public void setServiceBroker(ServiceBroker sb) {
49: // this is the *node* service broker! The NodeControlService
50: // is not available until the node-agent is created...
51: this .sb = sb;
52: }
53:
54: public void load() {
55: super .load();
56:
57: Logger logger = Logging.getLogger(getClass());
58:
59: if (sb.hasService(ComponentInitializerService.class)) {
60: // already have a ComponentInitializer?
61: // Leave the existing one in place
62: if (logger.isInfoEnabled()) {
63: logger
64: .info("Not loading the XMLComponentInitializer service");
65: }
66: } else {
67: try {
68: theSP = new XMLComponentInitializerServiceProvider();
69: } catch (Exception e) {
70: logger
71: .error(
72: "Unable to load XMLComponentInitializer service",
73: e);
74: }
75: if (theSP != null) {
76: if (logger.isDebugEnabled())
77: logger.debug("Providing XML Init service");
78: sb.addService(ComponentInitializerService.class, theSP);
79: }
80: }
81: }
82:
83: public void unload() {
84: if (theSP != null) {
85: sb.revokeService(ComponentInitializerService.class, theSP);
86: theSP = null;
87: }
88: super.unload();
89: }
90: }
|