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.mlm.plugin.organization;
027:
028: import java.io.Serializable;
029:
030: import java.util.Set;
031: import java.util.Collections;
032:
033: import org.cougaar.core.relay.*;
034: import org.cougaar.core.mts.MessageAddress;
035: import org.cougaar.core.util.*;
036:
037: import org.cougaar.util.log.Logger;
038: import org.cougaar.util.log.Logging;
039:
040: /**
041: * Relay for subordinates to report to their operational
042: * superior. The subordinate needs to obtain the ItemId
043: * and TypeId of their OpCon (operational superior) in
044: * order to generate the ReportForDuty task.
045: * Used by the OrgDataPlugin
046: **/
047: public class OpConInfoRelay implements Relay.Source, Relay.Target,
048: UniqueObject {
049:
050: private static Logger myLogger = Logging
051: .getLogger(OpConInfoRelay.class);
052:
053: private MessageAddress source = null;
054: private MessageAddress target = null;
055: private UID uid = null;
056:
057: private Object content = null;
058: private Object response = null;
059:
060: private transient Set targets = null;
061:
062: public OpConInfoRelay(UID uid, MessageAddress source,
063: MessageAddress target, Object content, Object response) {
064: this .uid = uid;
065: this .source = source;
066: this .target = target;
067: this .content = content;
068: this .response = response;
069: }
070:
071: // UniqueObject interface
072:
073: public void setUID(UID uid) {
074: throw new RuntimeException("Attempt to change UID");
075: }
076:
077: public UID getUID() {
078: return uid;
079: }
080:
081: /**
082: * Address of the agent that was contacted.
083: * @return The address of the agent.
084: */
085: public MessageAddress getTarget() {
086: return target;
087: }
088:
089: // Source interface
090:
091: public Set getTargets() {
092: if (targets == null) {
093: targets = ((target != null) ? Collections.singleton(target)
094: : Collections.EMPTY_SET);
095: }
096:
097: return targets;
098: }
099:
100: public Object getContent() {
101: return content;
102: }
103:
104: private static final class SimpleRelayFactory implements
105: TargetFactory, Serializable {
106:
107: public static final SimpleRelayFactory _instance = new SimpleRelayFactory();
108:
109: private SimpleRelayFactory() {
110: }
111:
112: public Relay.Target create(UID uid, MessageAddress source,
113: Object content, Token token) {
114: return new OpConInfoRelay(uid, source, null, content, null);
115: }
116:
117: private Object readResolve() {
118: return _instance;
119: }
120: }
121:
122: public TargetFactory getTargetFactory() {
123: return SimpleRelayFactory._instance;
124: }
125:
126: public int updateResponse(MessageAddress t, Object response) {
127: // assert response != null
128: if (!(response.equals(this .response))) {
129: this .response = response;
130: return Relay.RESPONSE_CHANGE;
131: }
132: return Relay.NO_CHANGE;
133: }
134:
135: // Target interface
136:
137: public MessageAddress getSource() {
138: return source;
139: }
140:
141: public Object getResponse() {
142: return response;
143: }
144:
145: public int updateContent(Object content, Token token) {
146: // assert content != null
147: if (!(content.equals(this .content))) {
148: this .content = content;
149: return CONTENT_CHANGE;
150: }
151: return NO_CHANGE;
152: }
153:
154: public boolean equals(Object o) {
155: if (o == this ) {
156: return true;
157: } else if (!(o instanceof OpConInfoRelay)) {
158: return false;
159: } else {
160: UID u = ((OpConInfoRelay) o).getUID();
161: return uid.equals(u);
162: }
163: }
164:
165: public int hashCode() {
166: return uid.hashCode();
167: }
168:
169: public String toString() {
170: return "(" + uid + ", " + content + ", " + response + ")";
171: }
172:
173: }
|