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.planning.ldm.plan;
028:
029: import java.io.IOException;
030: import java.io.ObjectInputStream;
031: import java.io.ObjectOutputStream;
032:
033: import org.cougaar.core.mts.MessageAddress;
034: import org.cougaar.planning.ldm.asset.Asset;
035:
036: /**
037: * Skeleton implementation of AssetAssignment
038: */
039: public class AssetAssignmentImpl extends PlanningDirectiveImpl
040: implements AssetAssignment, NewAssetAssignment {
041:
042: private transient Asset assignedAsset; // changed to transient : Persistence
043: private transient Asset assigneeAsset;
044: private Schedule assignSchedule;
045: private byte _kind = NEW;
046:
047: //no-arg constructor
048: public AssetAssignmentImpl() {
049: super ();
050: }
051:
052: //constructor that takes one Asset
053: public AssetAssignmentImpl(Asset a) {
054: assignedAsset = a;
055: }
056:
057: //constructor that takes multiple Assets
058: /*
059: public AssetAssignmentImpl (Enumeration as) {
060: assignedAssets = new Vector();
061: while (as.hasMoreElements()) {
062: Asset asset = (Asset) as.nextElement();
063: assignedAssets.addElement(asset);
064: }
065: }
066: */
067:
068: //constructor that takes the Asset, the plan, the schedule
069: // the source agent and the destination asset
070: public AssetAssignmentImpl(Asset as, Plan p, Schedule s,
071: MessageAddress sc, Asset da) {
072: assignedAsset = as;
073: super .setPlan(p);
074: assignSchedule = s;
075: super .setSource(sc);
076:
077: assigneeAsset = da;
078: if (!assigneeAsset.hasClusterPG()) {
079: throw new IllegalArgumentException(
080: "AssetAssignmentImpl: destination asset - "
081: + assigneeAsset
082: + " - does not have a ClusterPG");
083: }
084: super .setDestination(assigneeAsset.getClusterPG()
085: .getMessageAddress());
086: }
087:
088: /** implementations of the AssetAssignment interface */
089:
090: public boolean isUpdate() {
091: return _kind == UPDATE;
092: }
093:
094: public boolean isRepeat() {
095: return _kind == REPEAT;
096: }
097:
098: public void setKind(byte value) {
099: _kind = value;
100: }
101:
102: /** @return Asset Asset that is being assigned */
103: public Asset getAsset() {
104: return assignedAsset;
105: }
106:
107: public void setAsset(Asset newAssignedAsset) {
108: assignedAsset = newAssignedAsset;
109: }
110:
111: public Schedule getSchedule() {
112: return assignSchedule;
113: }
114:
115: public void setSchedule(Schedule sched) {
116: assignSchedule = sched;
117: }
118:
119: public Asset getAssignee() {
120: return assigneeAsset;
121: }
122:
123: public void setAssignee(Asset newAssigneeAsset) {
124: assigneeAsset = newAssigneeAsset;
125: }
126:
127: public String toString() {
128: String scheduleDescr = "(Null AssignedSchedule)";
129: if (assignSchedule != null)
130: scheduleDescr = assignSchedule.toString();
131: String assetDescr = "(Null AssignedAsset)";
132: if (assignedAsset != null)
133: assetDescr = assignedAsset.toString();
134: String toAssetDescr = "(Null AssigneeAsset)";
135: if (assigneeAsset != null)
136: toAssetDescr = assigneeAsset.toString();
137: String kind;
138: switch (_kind) {
139: case UPDATE:
140: kind = "UPDATE";
141: break;
142: case NEW:
143: kind = "NEW";
144: break;
145: case REPEAT:
146: kind = "REPEAT";
147: break;
148: default:
149: kind = "BOGUS";
150: }
151:
152: return "<AssetAssignment of " + assetDescr + ", "
153: + scheduleDescr + " " + kind + " " + toAssetDescr + ">"
154: + super .toString();
155: }
156:
157: private void writeObject(ObjectOutputStream stream)
158: throws IOException {
159:
160: /** ----------
161: * WRITE handlers common to Persistence and
162: * Network serialization. NOte that these
163: * cannot be references to Persistable objects.
164: * defaultWriteObject() is likely to belong here...
165: * ---------- **/
166: stream.defaultWriteObject();
167:
168: stream.writeObject(assignedAsset);
169: stream.writeObject(assigneeAsset);
170: }
171:
172: private void readObject(ObjectInputStream stream)
173: throws ClassNotFoundException, IOException {
174:
175: stream.defaultReadObject();
176:
177: assignedAsset = (Asset) stream.readObject();
178: assigneeAsset = (Asset) stream.readObject();
179: }
180: }
|