001: /*
002: * <copyright>
003: *
004: * Copyright 2001-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: package org.cougaar.core.component;
027:
028: /** BinderBase contains logic for the parent link (ContainerAPI) but not the
029: * child link. BinderSupport extends the api for standard Binders and BinderWrapper
030: * extends it for "Wrapping" Binders.
031: **/
032: public abstract class BinderBase implements Binder {
033: private BinderFactory binderFactory;
034: private ServiceBroker servicebroker;
035: private ContainerAPI parent;
036:
037: protected BinderBase(BinderFactory bf, Object child) {
038: binderFactory = bf;
039: attachChild(child);
040: }
041:
042: protected void setServiceBroker(ServiceBroker sb) {
043: servicebroker = sb;
044: }
045:
046: public void setBindingSite(BindingSite bs) {
047: if (bs instanceof ContainerAPI) {
048: parent = (ContainerAPI) bs;
049: setServiceBroker(parent.getServiceBroker());
050: } else {
051: throw new RuntimeException(
052: "Help: BindingSite of Binder not a ContainerAPI!");
053: }
054: }
055:
056: protected abstract void attachChild(Object child);
057:
058: protected ComponentFactory getComponentFactory() {
059: if (binderFactory != null) {
060: return binderFactory.getComponentFactory();
061: } else {
062: throw new RuntimeException("No ComponentFactory");
063: }
064: }
065:
066: public ServiceBroker getServiceBroker() {
067: return servicebroker;
068: }
069:
070: protected final ContainerAPI getContainer() {
071: return parent;
072: }
073:
074: //
075: // child services initialization
076: //
077:
078: public abstract void initialize();
079:
080: public abstract void load();
081:
082: public abstract void start();
083:
084: public abstract void suspend();
085:
086: public abstract void resume();
087:
088: public abstract void stop();
089:
090: public abstract void halt();
091:
092: public abstract void unload();
093:
094: public abstract int getModelState();
095:
096: public abstract Object getState();
097:
098: public abstract void setState(Object state);
099:
100: public String toString() {
101: String s = this .getClass().toString();
102: int i = s.lastIndexOf(".");
103: return s.substring(i + 1);
104: }
105:
106: }
|