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.asset;
028:
029: import org.cougaar.planning.ldm.plan.HasRelationships;
030: import org.cougaar.planning.ldm.plan.RelationshipScheduleImpl;
031:
032: import java.io.IOException;
033: import java.io.ObjectInputStream;
034: import java.io.ObjectOutputStream;
035:
036: public class RelationshipBG implements PGDelegate {
037: protected transient NewRelationshipPG myPG;
038:
039: public PGDelegate copy(PropertyGroup pg) {
040: if (!(pg instanceof NewRelationshipPG)) {
041: throw new java.lang.IllegalArgumentException(
042: "Property group must be a RelationshipPG");
043: }
044:
045: NewRelationshipPG relationshipPG = (NewRelationshipPG) pg;
046:
047: HasRelationships x = null;
048: if (relationshipPG.getRelationshipSchedule() != null) {
049: x = relationshipPG.getRelationshipSchedule()
050: .getHasRelationships();
051: }
052: RelationshipBG bg = new RelationshipBG();
053: bg.init(relationshipPG, x);
054: return bg;
055: }
056:
057: public void readObject(ObjectInputStream in) {
058: try {
059: in.defaultReadObject();
060:
061: if (in instanceof org.cougaar.core.persist.PersistenceInputStream) {
062: myPG = (NewRelationshipPG) in.readObject();
063: } else {
064: // If not persistence, need to initialize the relationship schedule
065: myPG = (NewRelationshipPG) in.readObject();
066: init(myPG, myPG.getRelationshipSchedule()
067: .getHasRelationships());
068: }
069: } catch (IOException ioe) {
070: ioe.printStackTrace();
071: throw new RuntimeException();
072: } catch (ClassNotFoundException cnfe) {
073: cnfe.printStackTrace();
074: throw new RuntimeException();
075: }
076: }
077:
078: public void writeObject(ObjectOutputStream out) {
079: try {
080: // Make sure that it agrees with schedule
081: out.defaultWriteObject();
082:
083: if (out instanceof org.cougaar.core.persist.PersistenceOutputStream) {
084: out.writeObject(myPG);
085: } else {
086: // Clear schedule before writing out
087: myPG.getRelationshipSchedule().clear();
088: out.writeObject(myPG);
089: }
090: } catch (IOException ioe) {
091: ioe.printStackTrace();
092: throw new RuntimeException();
093: }
094: }
095:
096: public void init(NewRelationshipPG pg,
097: HasRelationships hasRelationships) {
098: myPG = (NewRelationshipPG) pg;
099:
100: RelationshipScheduleImpl pgSchedule = (RelationshipScheduleImpl) pg
101: .getRelationshipSchedule();
102: if ((pgSchedule == null) || (pgSchedule.isEmpty())) {
103: myPG.setRelationshipSchedule(new RelationshipScheduleImpl(
104: hasRelationships));
105: } else if (!pgSchedule.getHasRelationships().equals(
106: hasRelationships)) {
107: throw new java.lang.IllegalArgumentException("");
108: }
109:
110: pg.setRelationshipBG(this );
111: }
112:
113: public boolean isSelf() {
114: return isLocal();
115: }
116:
117: public boolean isLocal() {
118: return myPG.getLocal();
119: }
120: }
|