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 org.cougaar.planning.ldm.asset.Asset;
030:
031: /**
032: * AssignedRelationshipElementImpl represents a relationship between assets.
033: * Used instead of Relationships in the AssetAssignment directive to prevent
034: * deadlock problems. Assets in the relationships represented by the
035: * ItemIdentification from their ItemIdentificationPG
036: *
037: *
038: **/
039:
040: public class AssignedRelationshipElementImpl extends
041: ScheduleElementImpl implements NewAssignedRelationshipElement {
042:
043: private String myItemIDA;
044: private String myItemIDB;
045: private Role myRoleA;
046: private Role myRoleB;
047:
048: /** constructor for factory use */
049: public AssignedRelationshipElementImpl() {
050: super ();
051: setItemIDA("");
052: setItemIDB("");
053: setRoleA(Role.BOGUS);
054: setRoleB(Role.BOGUS);
055: }
056:
057: /** constructor for factory use that takes assets, roles, start, end times
058: **/
059: public AssignedRelationshipElementImpl(Asset assetA, Role roleA,
060: Asset assetB, Role roleB, long start, long end) {
061: super (start, end);
062: setItemIDA(assetA);
063: setRoleA(roleA);
064: setItemIDB(assetB);
065: setRoleB(roleB);
066: }
067:
068: /** constructor for factory use that takes a Relationship
069: **/
070: public AssignedRelationshipElementImpl(Relationship relationship) {
071: this ((Asset) relationship.getA(), relationship.getRoleA(),
072: (Asset) relationship.getB(), relationship.getRoleB(),
073: relationship.getStartTime(), relationship.getEndTime());
074: }
075:
076: /** String identifier for the Asset mapping to HasRelationships A in the
077: * associated relationship
078: * @return String
079: **/
080: public String getItemIDA() {
081: return myItemIDA;
082: }
083:
084: /** Set the string identifier for the Asset mapping to HasRelationships A
085: * in the associated relationship
086: * @param itemID String
087: **/
088: public void setItemIDA(String itemID) {
089: myItemIDA = itemID;
090: }
091:
092: /** Set the string identifier for the Asset mapping to HasRelationships A
093: * in the associated relationship.
094: * @param asset Asset
095: **/
096: public void setItemIDA(Asset asset) {
097: myItemIDA = asset.getItemIdentificationPG()
098: .getItemIdentification();
099: }
100:
101: /** String identifier for the Asset mapping to HasRelationships B in the
102: * associated relationship
103: * @return String
104: **/
105: public String getItemIDB() {
106: return myItemIDB;
107: }
108:
109: /** Set the string identifier for the Asset mapping to HasRelationships B
110: * in the associated relationship
111: **/
112: public void setItemIDB(String itemID) {
113: myItemIDB = itemID;
114: }
115:
116: /** Set the string identifier for the Asset mapping to HasRelationships B
117: * in the associated relationship
118: **/
119: public void setItemIDB(Asset asset) {
120: myItemIDB = asset.getItemIdentificationPG()
121: .getItemIdentification();
122: }
123:
124: /** Role for the Asset identified by itemIDA
125: * @return Role
126: **/
127: public Role getRoleA() {
128: return myRoleA;
129: }
130:
131: /** Set the Role for the Asset identified by itemIDA
132: * @param role Role
133: **/
134: public void setRoleA(Role role) {
135: myRoleA = role;
136: }
137:
138: /** Role for the Asset identified by itemIDB
139: * @return Role
140: **/
141: public Role getRoleB() {
142: return myRoleB;
143: }
144:
145: /** Set the Role for the Asset identified by itemIDB
146: * @param role Role
147: **/
148: public void setRoleB(Role role) {
149: myRoleB = role;
150: }
151:
152: /**
153: * equals - performs field by field comparison
154: *
155: * @param object Object to compare
156: * @return boolean if 'same'
157: */
158: public boolean equals(Object object) {
159: if (object == this ) {
160: return true;
161: }
162:
163: if (!(object instanceof AssignedRelationshipElement)) {
164: return false;
165: }
166:
167: AssignedRelationshipElement other = (AssignedRelationshipElement) object;
168:
169: return (getItemIDA().equals(other.getItemIDA())
170: && getRoleA().equals(other.getRoleA())
171: && getItemIDB().equals(other.getItemIDB())
172: && getRoleB().equals(other.getRoleB())
173: && getStartTime() == other.getStartTime() && getEndTime() == other
174: .getEndTime());
175: }
176:
177: public String toString() {
178: return super .toString() + "::" + getItemIDA() + "/"
179: + getRoleA() + "::" + getItemIDB() + "/" + getRoleB();
180: }
181: }
|