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: package org.cougaar.glm.ldm.oplan;
027:
028: import java.beans.PropertyChangeListener;
029: import java.beans.PropertyChangeSupport;
030: import java.io.Serializable;
031:
032: import org.cougaar.core.util.OwnedUniqueObject;
033: import org.cougaar.core.util.UID;
034: import org.cougaar.core.util.UniqueObject;
035: import org.cougaar.planning.ldm.plan.Transferable;
036:
037: /**
038: * OrgRelation
039: * The OrgRelation method is a LDM Object that contains organizational data.
040: * The OrgRelation object includes information such as role, timespan, relationType,
041: * and the organizations related to each other.
042: * Subordinate clusters can subscribe to changes in the ForcePackage in order to
043: * react to changes accordingly. The OrgRelations are initially created in the J3 cluster
044: * and then is transferred to other clusters by the Propagation Plugin.
045: * Subordinate clusters should not modify (set) OrgRelation information.
046: **/
047: public class OrgRelation extends OwnedUniqueObject implements
048: OplanContributor, Transferable, UniqueObject, Serializable,
049: Cloneable {
050: private String role;
051: private String relationType;
052: private String orgID = "";
053: private String otherOrgID = "";
054: private String forcePackageID = "";
055: private UID oplanUID = null;
056: private TimeSpan timeSpan;
057:
058: public OrgRelation() {
059:
060: }//OrgRelation
061:
062: public OrgRelation(String orgID, UID oplanUID) {
063: this .orgID = unique(orgID);
064: this .oplanUID = oplanUID;
065:
066: }// OrgRelation
067:
068: // public void setUID(UID uid) {
069: // orgRelationId = uid;
070: // }
071: // public UID getUID() {
072: // return orgRelationId;
073: // }
074: public void setOrgRelationId(UID uid) {
075: setUID(uid);
076: }
077:
078: public UID getOrgRelationId() {
079: return getUID();
080: }
081:
082: public void setOrgID(String orgID) {
083: this .orgID = unique(orgID);
084: }
085:
086: public String getOrgID() {
087: return orgID;
088: }
089:
090: public void setForcePackageId(String forcePackageID) {
091: this .forcePackageID = unique(forcePackageID);
092: }
093:
094: public String getForcePackageId() {
095: return forcePackageID;
096: }
097:
098: /** @deprecated Use getOplanUID */
099: public UID getOplanID() {
100: return oplanUID;
101: }
102:
103: public UID getOplanUID() {
104: return oplanUID;
105: }
106:
107: public void setOtherOrgId(String otherOrgID) {
108: this .otherOrgID = unique(otherOrgID);
109: }//setOtherOrgID
110:
111: public void setRelationType(String relationType) {
112: this .relationType = unique(relationType);
113: }//setRelationType
114:
115: public void setAssignedRole(String role) {
116: this .role = unique(role);
117: }//setAssignedRole
118:
119: public void setTimeSpan(TimeSpan ts) {
120: timeSpan = ts;
121: }//setTimeSpan
122:
123: public TimeSpan getTimeSpan() {
124: return timeSpan;
125: }//getTimeSpan
126:
127: public String getOtherOrgId() {
128: return otherOrgID;
129: }//getOtherOrgID
130:
131: public String getRelationType() {
132: return relationType;
133: }//relationType
134:
135: public String getAssignedRole() {
136: return role;
137: }//getAssignedRole
138:
139: public Object clone() {
140: OrgRelation or = new OrgRelation(orgID, oplanUID);
141: or.setForcePackageId(forcePackageID);
142: or.setRelationType(relationType);
143: or.setAssignedRole(role);
144: or.setOtherOrgId(otherOrgID);
145: or.setUID(getUID());
146: or.setOwner(getOwner());
147:
148: if (timeSpan != null)
149: or.setTimeSpan((TimeSpan) timeSpan.clone());
150: return or;
151: }//clone
152:
153: public void setAll(Transferable other) {
154:
155: if (!(other instanceof OrgRelation)) {
156: throw new IllegalArgumentException(
157: "Parameter is not an OrgRelation.");
158: } else {
159: OrgRelation or = (OrgRelation) other;
160: relationType = or.getRelationType();
161: orgID = or.getOrgID();
162: forcePackageID = or.getForcePackageId();
163: oplanUID = or.getOplanUID();
164: timeSpan = or.getTimeSpan();
165: otherOrgID = or.getOtherOrgId();
166: role = or.getAssignedRole();
167: setUID(or.getUID());
168: setOwner(or.getOwner());
169:
170: }// else set everything
171: }// setAll
172:
173: public boolean same(Transferable other) {
174: if (other instanceof OrgRelation) {
175: OrgRelation or = (OrgRelation) other;
176: return (getUID().equals(or.getUID()));
177: }
178: return false;
179: }
180:
181: private boolean matches(Object a, Object b) {
182: return (a == null) ? (b == null) : (a.equals(b));
183: }
184:
185: public boolean equals(Object o) {
186: if (o instanceof OrgRelation) {
187: OrgRelation or = (OrgRelation) o;
188:
189: return matches(getAssignedRole(), or.getAssignedRole())
190: && matches(getRelationType(), or.getRelationType())
191: && matches(getUID(), or.getUID())
192: && matches(getOrgID(), or.getOrgID())
193: && matches(getOtherOrgId(), or.getOtherOrgId())
194: && matches(getForcePackageId(), or
195: .getForcePackageId())
196: && matches(getOplanUID(), or.getOplanUID())
197: && matches(getTimeSpan(), or.getTimeSpan());
198: } else
199: return false;
200: }
201:
202: //dummy PropertyChangeSupport for the Jess Interpreter.
203: protected transient PropertyChangeSupport pcs = new PropertyChangeSupport(
204: this );
205:
206: public void addPropertyChangeListener(PropertyChangeListener pcl) {
207: pcs.addPropertyChangeListener(pcl);
208: }
209:
210: public void removePropertyChangeListener(PropertyChangeListener pcl) {
211: pcs.removePropertyChangeListener(pcl);
212: }
213:
214: public static final String unique(String s) {
215: return (s == null) ? null : (s.intern());
216: }
217:
218: }
|