01: /*
02: * <copyright>
03: *
04: * Copyright 2002-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.examples;
28:
29: import java.util.*;
30: import org.cougaar.util.*;
31: import org.cougaar.core.component.*;
32: import org.cougaar.core.agent.*;
33: import org.cougaar.core.domain.*;
34: import org.cougaar.core.blackboard.*;
35: import org.cougaar.core.mts.Message;
36: import org.cougaar.core.persist.*;
37: import org.cougaar.core.blackboard.*;
38: import org.cougaar.core.service.BlackboardService;
39:
40: /** A plugin's view of its parent component (Container).
41: * Print a message when instantiated, and then report whenever someone
42: * requests a service through its filter.
43: * <p>
44: * Add a line like the following to a cluster.ini file:
45: * <pre>
46: * Node.AgentManager.Agent.PluginManager.Binder = org.cougaar.core.examples.DummyBinder
47: * </pre>
48:
49: **/
50: public class DummyBinder // PluginServiceFilter
51: extends ServiceFilter {
52: public DummyBinder() {
53: System.err.println("DummyBinder instantiated");
54: }
55:
56: public void setParameter(Object o) {
57: }
58:
59: // This method specifies the Binder to use (defined later)
60: protected Class getBinderClass(Object child) {
61: return PluginServiceFilterBinder.class;
62: }
63:
64: // This is a "Wrapper" binder which installs a service filter for plugins
65: public static class PluginServiceFilterBinder extends
66: ServiceFilterBinder {
67: public PluginServiceFilterBinder(BinderFactory bf, Object child) {
68: super (bf, child);
69: }
70:
71: // this method specifies a binder proxy to use, so as to avoid exposing the binder
72: // itself to the lower level objects.
73: protected ContainerAPI createContainerProxy() {
74: return new ServiceFilterContainerProxy();
75: }
76:
77: // this method installs the "filtering" service broker
78: protected ServiceBroker createFilteringServiceBroker(
79: ServiceBroker sb) {
80: return new PluginFilteringServiceBroker(sb);
81: }
82:
83: // this class catches requests for blackboard services, and
84: // installs its own service proxy.
85: protected class PluginFilteringServiceBroker extends
86: FilteringServiceBroker {
87: public PluginFilteringServiceBroker(ServiceBroker sb) {
88: super (sb);
89: }
90:
91: protected Object getServiceProxy(Object service,
92: Class serviceClass, Object client) {
93: System.err.println("DummyBinder: " + serviceClass
94: + " requested by " + client);
95: return null;
96: }
97: }
98: }
99: }
|