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.planning.ldm.plan;
027:
028: import org.cougaar.core.util.UID;
029:
030: /** Alert Implementation
031: *
032: *
033: * Open issues -
034: * what happens when no one is subscribed to listen for this alert
035: * need an Alert type, otherwise all Alerts will go to all subscribers
036: */
037:
038: public class AlertImpl implements Alert, NewAlert {
039:
040: protected String myDisplayText; // answers the question "Right, what's all this, then?"
041: protected AlertParameter[] myParameters; //description, object pairs
042: protected Object myResponse; //option chosen
043: protected boolean myAcknowledged; // true if this Alert has been acted upon
044: protected int mySeverity;
045: protected int myType;
046: protected boolean myResponseRequired;
047:
048: private UID myUID;
049:
050: /**
051: * Constructor - takes no args
052: */
053: public AlertImpl() {
054: myDisplayText = null;
055: myParameters = null;
056: myResponse = null;
057: myAcknowledged = false;
058: mySeverity = Alert.UNDEFINED_SEVERITY;
059: myType = Alert.UNDEFINED_TYPE;
060: myResponseRequired = false;
061: myUID = null;
062: }
063:
064: /**
065: * Constructor -
066: *
067: * @param text String
068: * @param operatorResponseRequired boolean
069: * @param parameterOptions AlertParameter[]
070: * @param severity int
071: * @param uid UID
072: */
073: public AlertImpl(String text, boolean operatorResponseRequired,
074: AlertParameter[] parameterOptions, int severity, int type,
075: UID uid) {
076: myDisplayText = text;
077: myResponseRequired = operatorResponseRequired;
078: myParameters = parameterOptions;
079: mySeverity = severity;
080: myType = type;
081: myUID = uid;
082: }
083:
084: /**
085: * setAlertText - sets display text for the alert
086: */
087: public void setAlertText(String alertText) {
088: myDisplayText = alertText;
089: }
090:
091: /**
092: * getAlertText - returns the display text for the alert
093: */
094: public String getAlertText() {
095: return myDisplayText;
096: }
097:
098: /**
099: * getAlertParameters - returns alert parameters associated with the alert
100: *
101: * @return AlertParameter[]
102: */
103: public AlertParameter[] getAlertParameters() {
104: return myParameters;
105: }
106:
107: /**
108: * setAlertParameters - sets the alert parameters associated with the alert
109: *
110: * @param params AlertParameter[]
111: */
112: public void setAlertParameters(AlertParameter[] params) {
113: myParameters = params;
114: }
115:
116: /**
117: * getOperatorResponse - return the operator response to the alert
118: *
119: * @return Object - operator response to the alert. May be null.
120: */
121: public Object getOperatorResponse() {
122: return myResponse;
123: }
124:
125: /**
126: * setOperatorResponse - set the operator response to the alert
127: *
128: * @param response Object
129: */
130: public void setOperatorResponse(Object response) {
131: myResponse = response;
132: }
133:
134: /**
135: * getOperatorResponseRequired - return boolean indicating whether alert requires an
136: * operator response.
137: *
138: * @return boolean
139: */
140: public boolean getOperatorResponseRequired() {
141: return myResponseRequired;
142: }
143:
144: /**
145: * setOperatorResponseRequired - sets boolean indicating whether alert requires an
146: * operator response.
147: *
148: * @return boolean
149: */
150: public void setOperatorResponseRequired(boolean req) {
151: myResponseRequired = req;
152: }
153:
154: /**
155: * getSeverity - returns severity associated with the alert
156: *
157: * @return int
158: */
159: public int getSeverity() {
160: return mySeverity;
161: }
162:
163: /**
164: * setSeverity - sets severity associated with the alert
165: * BOZO - This should be checking against defined severity values.
166: *
167: * @param severity int
168: */
169: public void setSeverity(int severity) {
170: if (!validSeverity(severity)) {
171: //BOZO - how are we logging errors?
172: System.out
173: .println("AlertImpl.setSeverity(): unrecognized severity "
174: + severity);
175: }
176: mySeverity = severity;
177: }
178:
179: /**
180: * validSeverity - checks whether severity is valid.
181: * MIN_SEVERITY and MAX_SEVERITY used to check for valid severity values.
182: * Simple minded but works so long as we can keep a contiguous set of severities.
183: * @param severity int to be tested
184: * @return boolean true if valid severity, else false
185: */
186: public boolean validSeverity(int severity) {
187: if ((severity < MIN_SEVERITY)
188: || (severity > Alert.MAX_SEVERITY)) {
189: return false;
190: } else {
191: return true;
192: }
193: }
194:
195: /**
196: * getType - returns alert type
197: *
198: * @return int
199: */
200: public int getType() {
201: return myType;
202: }
203:
204: /**
205: * setType - sets alert type
206: * BOZO - Should be checking against some set of valid types.
207: *
208: * @param type int
209: */
210: public void setType(int type) {
211: myType = type;
212: }
213:
214: /**
215: * setAcknowledged - sets boolean indicating whether alert has been acknowleged
216: * BOZO - Definition of 'acknowledged' is fuzzy. I assume that an alert which
217: * requires an operator response can not acknowledged without the response. I see
218: * no code enforcing this behaviour.
219: *
220: * @param ack boolean
221: */
222: public void setAcknowledged(boolean ack) {
223: myAcknowledged = ack;
224: }
225:
226: /**
227: * getAcknowledged - returns boolean indicating whether alert has been acknowledged
228: *
229: * @return boolean
230: */
231: public boolean getAcknowledged() {
232: return myAcknowledged;
233: }
234:
235: /**
236: * setUID - set uid for the object
237: * Why is this public? Does it make sense to allow random changes to
238: * UID?
239: *
240: * @param uid UID assigned to object
241: */
242: public void setUID(UID uid) {
243: myUID = uid;
244: }
245:
246: /**
247: * getUID - get uid for the object
248: *
249: * @return UID assigned to object
250: */
251: public UID getUID() {
252: return myUID;
253: }
254: }
|