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: /* hand generated! */
028:
029: package org.cougaar.glm.ldm.asset;
030:
031: import java.beans.IntrospectionException;
032: import java.beans.PropertyDescriptor;
033: import java.io.IOException;
034: import java.io.ObjectInputStream;
035: import java.io.ObjectOutputStream;
036: import java.util.Collection;
037: import java.util.Date;
038: import java.util.Vector;
039:
040: import org.cougaar.planning.ldm.asset.Asset;
041: import org.cougaar.planning.ldm.asset.Perturbator;
042: import org.cougaar.planning.ldm.plan.RoleSchedule;
043: import org.cougaar.planning.ldm.plan.RoleScheduleImpl;
044: import org.cougaar.planning.ldm.plan.Schedule;
045: import org.cougaar.planning.ldm.plan.ScheduleElement;
046: import org.cougaar.planning.ldm.plan.ScheduleElementImpl;
047: import org.cougaar.planning.ldm.plan.ScheduleImpl;
048: import org.cougaar.util.TimeSpan;
049:
050: public class TransportationLink extends Facility {
051:
052: public TransportationLink() {
053: this (null, null, null, "");
054: }
055:
056: public TransportationLink(TransportationLink prototype) {
057: super (prototype);
058: myNetwork = null;
059: myOrigin = null;
060: myDestination = null;
061: myName = "";
062: RoleSchedule myrolesched = getRoleSchedule();
063: ((RoleScheduleImpl) myrolesched)
064: .setAvailableSchedule(new ScheduleImpl());
065: Schedule mysched = getRoleSchedule().getAvailableSchedule();
066: ((ScheduleImpl) mysched)
067: .setScheduleElement((ScheduleElement) new ScheduleElementImpl(
068: new Date(0), new Date(TimeSpan.MAX_VALUE)));
069: }
070:
071: public TransportationLink(TransportationNetwork network,
072: TransportationNode origin, TransportationNode destination,
073: String name) {
074: myOrigin = origin;
075: myDestination = destination;
076: myNetwork = network;
077: myName = name;
078: RoleSchedule myrolesched = getRoleSchedule();
079: ((RoleScheduleImpl) myrolesched)
080: .setAvailableSchedule(new ScheduleImpl());
081: Schedule mysched = getRoleSchedule().getAvailableSchedule();
082: ((ScheduleImpl) mysched)
083: .setScheduleElement((ScheduleElement) new ScheduleElementImpl(
084: new Date(0), new Date(TimeSpan.MAX_VALUE)));
085: }
086:
087: /** For infrastructure only - use LdmFactory.copyInstance instead. **/
088: public Object clone() throws CloneNotSupportedException {
089: TransportationLink _thing = (TransportationLink) super .clone();
090: if (myOrigin != null)
091: _thing.setOrigin(myOrigin);
092: if (myDestination != null)
093: _thing.setDestination(myDestination);
094: if (myName != null)
095: _thing.setName(myName);
096: if (myNetwork != null)
097: _thing.setNetwork(myNetwork);
098: return _thing;
099: }
100:
101: /** create an instance of the right class for copy operations **/
102: public Asset instanceForCopy() {
103: return new TransportationLink();
104: }
105:
106: /** create an instance of this prototype **/
107: public Asset createInstance() {
108: return new TransportationLink(this );
109: }
110:
111: protected void fillAllPropertyGroups(Vector v) {
112: super .fillAllPropertyGroups(v);
113: }
114:
115: protected transient TransportationNetwork myNetwork;
116:
117: public TransportationNetwork getNetwork() {
118: if (myNetwork == null) {
119: if (myPrototype != null) {
120: return ((TransportationLink) myPrototype).getNetwork();
121: } else {
122: myNetwork = null;
123: }
124: }
125: return myNetwork;
126: }
127:
128: public void setNetwork(TransportationNetwork arg_Network) {
129: myNetwork = arg_Network;
130: }
131:
132: protected transient TransportationNode myOrigin;
133:
134: public TransportationNode getOrigin() {
135: if (myOrigin == null) {
136: if (myPrototype != null) {
137: return ((TransportationLink) myPrototype).getOrigin();
138: } else {
139: myOrigin = null;
140: }
141: }
142: return myOrigin;
143: }
144:
145: public void setOrigin(TransportationNode arg_Origin) {
146: myOrigin = arg_Origin;
147: }
148:
149: protected transient TransportationNode myDestination;
150:
151: public TransportationNode getDestination() {
152: if (myDestination == null) {
153: if (myPrototype != null) {
154: return ((TransportationLink) myPrototype)
155: .getDestination();
156: } else {
157: myDestination = null;
158: }
159: }
160: return myDestination;
161: }
162:
163: public void setDestination(TransportationNode arg_Destination) {
164: myDestination = arg_Destination;
165: }
166:
167: protected transient String myName;
168:
169: public String getName() {
170: if (myName == null) {
171: if (myPrototype != null) {
172: return ((TransportationLink) myPrototype).getName();
173: } else {
174: myName = null;
175: }
176: }
177: return myName;
178: }
179:
180: public void setName(String arg_Name) {
181: myName = arg_Name;
182: }
183:
184: // get
185:
186: public Schedule getSchedule() {
187: return getRoleSchedule().getAvailableSchedule();
188: }
189:
190: // Perturbator myPerturbator = new Perturbator();
191: Perturbator myPerturbator = null;
192:
193: public void setPerturbator(Perturbator p) {
194: myPerturbator = p;
195: }
196:
197: /**
198: * The get Perturbator call as a "side-effect" changes
199: * the availability of the link to be only available
200: * between the java begining of time and 20 seconds
201: * after that, making the link effectively unavailable.
202: *
203: * This is necessary because the perturbation mechanism
204: * currently doesn't allow changing availabilities directly.
205: */
206: public Perturbator getPerturbator() {
207: Schedule sched = getSchedule();
208: ScheduleElement y = (ScheduleElement) new ScheduleElementImpl(
209: new Date(0), new Date(20000));
210: ((ScheduleImpl) sched).setScheduleElement(y);
211: return myPerturbator;
212: }
213:
214: // methods
215:
216: public boolean available(Date start, Date end) {
217: Date tstart = start;
218: Schedule avail = getRoleSchedule().getAvailableSchedule();
219:
220: Collection c = avail.getOverlappingScheduleElements(start
221: .getTime(), end.getTime());
222: return c.isEmpty();
223: }
224:
225: public TransportationNode otherEnd(TransportationNode end) {
226: if (end == myOrigin)
227: return myDestination;
228: if (end == myDestination)
229: return myOrigin;
230: // Error Condition
231: return null;
232: }
233:
234: private void writeObject(ObjectOutputStream out) throws IOException {
235: out.defaultWriteObject();
236: out.writeObject(myOrigin);
237: out.writeObject(myDestination);
238: out.writeObject(myName);
239: out.writeObject(myNetwork);
240: }
241:
242: private void readObject(ObjectInputStream in)
243: throws ClassNotFoundException, IOException {
244: in.defaultReadObject();
245: myOrigin = (TransportationNode) in.readObject();
246: myDestination = (TransportationNode) in.readObject();
247: myName = (String) in.readObject();
248: myNetwork = (TransportationNetwork) in.readObject();
249: }
250:
251: // beaninfo support
252: private static PropertyDescriptor properties[];
253: static {
254: try {
255: properties = new PropertyDescriptor[5];
256: properties[0] = new PropertyDescriptor("FacilityPG",
257: TransportationLink.class, "getFacilityPG", null);
258: properties[1] = new PropertyDescriptor("Origin",
259: TransportationLink.class, "getOrigin", null);
260: properties[2] = new PropertyDescriptor("Destination",
261: TransportationLink.class, "getDestination", null);
262: properties[3] = new PropertyDescriptor("Name",
263: TransportationLink.class, "getName", null);
264: properties[4] = new PropertyDescriptor("Network",
265: TransportationLink.class, "getNetwork", null);
266: } catch (IntrospectionException ie) {
267: }
268: }
269:
270: public PropertyDescriptor[] getPropertyDescriptors() {
271: PropertyDescriptor[] pds = super .getPropertyDescriptors();
272: PropertyDescriptor[] ps = new PropertyDescriptor[pds.length + 5];
273: System.arraycopy(pds, 0, ps, 0, pds.length);
274: System.arraycopy(properties, 0, ps, pds.length, 5);
275: return ps;
276: }
277: }
|