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.mts.base;
28:
29: import org.cougaar.core.component.Container;
30: import org.cougaar.core.component.ServiceBroker;
31: import org.cougaar.core.service.LoggingService;
32:
33: /**
34: * This class was originally designed to instantiate {@link
35: * LinkProtocol}s, given a list of class names. Now that LinkProtocol
36: * Components are loaded in the usual way, its only remaining function
37: * is to handle the case when none are loaded. If that happens it
38: * will create two default LinkProtocol instances, for RMI and Loopback.
39: */
40: final class LinkProtocolFactory {
41:
42: private LoggingService loggingService;
43: private Container container;
44:
45: LinkProtocolFactory(Container container, ServiceBroker sb) {
46: loggingService = (LoggingService) sb.getService(this ,
47: LoggingService.class, null);
48: this .container = container;
49: MessageTransportRegistryService reg = (MessageTransportRegistryService) sb
50: .getService(this ,
51: MessageTransportRegistryService.class, null);
52: // If any Protocols are already loaded (via CSMART), don't
53: // make the standard ones.
54: if (!reg.hasLinkProtocols()) {
55: LinkProtocol protocol = new LoopbackLinkProtocol();
56: initProtocol(protocol);
57: makeProtocol("org.cougaar.mts.rmi.RMILinkProtocol");
58: }
59: }
60:
61: private void initProtocol(LinkProtocol protocol) {
62: container.add(protocol);
63: }
64:
65: private LinkProtocol makeProtocol(String classname) {
66: LinkProtocol protocol = null;
67: try {
68: Class protocol_class = Class.forName(classname);
69: protocol = (LinkProtocol) protocol_class.newInstance();
70: } catch (Exception xxx) {
71: if (loggingService.isErrorEnabled())
72: loggingService.error(null, xxx);
73: return null;
74: }
75: initProtocol(protocol);
76: return protocol;
77: }
78:
79: }
|