001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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:
027: package org.cougaar.core.node;
028:
029: import org.cougaar.core.component.ComponentDescription;
030: import org.cougaar.core.mts.Message;
031: import org.cougaar.core.mts.MessageAddress;
032:
033: /**
034: * @deprecated message to add/remove components, see {@link
035: * org.cougaar.core.service.AgentContainmentService}.
036: */
037: public class ComponentMessage extends Message {
038:
039: /** the operations */
040: public static final int ADD = 0;
041: public static final int REMOVE = 1;
042: public static final int SUSPEND = 2;
043: public static final int RESUME = 3;
044: public static final int RELOAD = 4;
045: private static final int MAX_OP = RELOAD; // last entry
046:
047: /** one of the above constants, for example <tt>ADD</tt> */
048: private int operation;
049:
050: /** @see #getComponentDescription() */
051: private ComponentDescription desc;
052:
053: /** @see #getState() */
054: private Object state;
055:
056: public ComponentMessage(MessageAddress aSource,
057: MessageAddress aTarget, int operation,
058: ComponentDescription desc, Object state) {
059: super (aSource, aTarget);
060: setOperation(operation);
061: setComponentDescription(desc);
062: setState(state);
063: }
064:
065: /**
066: * Get the specified action, such as ADD.
067: *
068: * @see ComponentDescription
069: */
070: public int getOperation() {
071: return operation;
072: }
073:
074: /**
075: * @see #getComponentDescription()
076: */
077: public void setOperation(int operation) {
078: if ((operation < 0) || (operation > MAX_OP)) {
079: throw new IllegalArgumentException(
080: "Invalid ComponentMessage \"operation\": "
081: + operation);
082: }
083: this .operation = operation;
084: }
085:
086: /**
087: * Get the component description for the Component.
088: *
089: * @see ComponentDescription
090: */
091: public ComponentDescription getComponentDescription() {
092: return desc;
093: }
094:
095: /**
096: * @see #getComponentDescription()
097: */
098: public void setComponentDescription(ComponentDescription desc) {
099: this .desc = desc;
100: }
101:
102: /**
103: * Get the state for the Component to ADD or RELOAD.
104: * <p>
105: * The state must be a <code>java.io.Serializable</code> Object.
106: * <p>
107: * Together the description and state form a <code>StateTuple</code>.
108: */
109: public Object getState() {
110: return state;
111: }
112:
113: /**
114: * @see #getState()
115: */
116: public void setState(Object state) {
117: this .state = state;
118: }
119:
120: public String toString() {
121: String sOp;
122: switch (operation) {
123: case ADD:
124: sOp = "Add";
125: break;
126: case REMOVE:
127: sOp = "Remove";
128: break;
129: case SUSPEND:
130: sOp = "Suspend";
131: break;
132: case RESUME:
133: sOp = "Resume";
134: break;
135: case RELOAD:
136: sOp = "Reload";
137: break;
138: default:
139: sOp = "Unknown";
140: break;
141: }
142: return sOp
143: + " ComponentMessage "
144: + super .toString()
145: + " ComponentDescription: "
146: + desc
147: + " State: "
148: + ((state != null) ? state.getClass().getName()
149: : "null");
150: }
151: }
|