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.mlm.debug.ui;
028:
029: import java.text.DateFormat;
030: import java.util.Date;
031: import java.util.Enumeration;
032: import java.util.TimeZone;
033:
034: import org.cougaar.core.mts.MessageAddress;
035: import org.cougaar.planning.ldm.asset.Asset;
036: import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
037: import org.cougaar.planning.ldm.plan.Task;
038: import org.cougaar.planning.ldm.plan.Verb;
039:
040: public class UITask {
041:
042: /** Workaround for task source and destination
043: that can be strings or MessageAddresss.
044: */
045:
046: private static String getClusterIdDescription(Object o) {
047: String s = "";
048: if (o == null)
049: return s;
050: if (o instanceof MessageAddress)
051: return ((MessageAddress) o).getAddress();
052: if (o instanceof String) {
053: System.out
054: .println("Warning: task source or destination is a string: "
055: + o);
056: return (String) o;
057: } else {
058: System.out
059: .println("Warning: task source or destination is a "
060: + o.getClass().toString()
061: + " with value "
062: + o.toString());
063: return o.toString();
064: }
065: }
066:
067: /** Return representation of a task in a tree.
068: For physical objects, return the name and serial number (if non-empty)
069: and for cluster objects, return the cluster id.
070: @param task the task for which to return a description
071: @return the string Source -> Destination Verb Objects Role
072: should return Source -> Destination
073: Verb DirectOjbect PrepPhrase DesiredSchedule
074: */
075:
076: public static String getDescription(Task task) {
077: String sourceString = getClusterIdDescription(task.getSource());
078: String dstnString = getClusterIdDescription(task
079: .getDestination());
080: Verb verb = task.getVerb();
081: String verbString = "";
082: if (verb != null)
083: verbString = verb.toString();
084: String directObjectString = UIAsset.getDescription((Asset) task
085: .getDirectObject());
086:
087: Enumeration prepPhrases = task.getPrepositionalPhrases();
088: String prepPhraseString = "";
089: PrepositionalPhrase p;
090: if (prepPhrases != null) {
091: }
092: while (prepPhrases.hasMoreElements()) {
093: p = (PrepositionalPhrase) prepPhrases.nextElement();
094: if (p != null)
095: if (p.getIndirectObject() instanceof Asset) {
096: prepPhraseString = prepPhraseString
097: + " "
098: + p.getPreposition()
099: + " "
100: + UIAsset.getDescription((Asset) p
101: .getIndirectObject());
102: /*
103: } else if ( p.getIndirectObject() instanceof Requisition ) {
104: prepPhraseString = prepPhraseString + " " +
105: p.getPreposition() + " " +
106: UIAsset.getDescription((Requisition)p.getIndirectObject());
107: } else if ( p.getIndirectObject() instanceof SupplySource ) {
108: prepPhraseString = prepPhraseString + " " +
109: p.getPreposition() + " " +
110: UIAsset.getDescription((SupplySource)p.getIndirectObject());
111: */
112: }
113: }
114:
115: prepPhraseString.trim();
116:
117: String scheduleString = "";
118: //PenaltyFunction pf = task.getPenaltyFunction();
119: //if (pf != null) {
120: // Date date = pf.getDesiredScheduleBestDate();
121: // if (date != null)
122: // scheduleString = getDateString(date);
123: //}
124:
125: String description = "";
126: // if ((sourceId != null) || (dstnId != null))
127: if ((sourceString.length() != 0) || (dstnString.length() != 0))
128: description = sourceString + "->" + dstnString + " ";
129: description = description + " " + verbString + " "
130: + directObjectString + " " + prepPhraseString + " "
131: + scheduleString;
132: return description;
133: }
134:
135: public static String getDateString(Date date) {
136: DateFormat dateFormat = DateFormat.getDateTimeInstance(
137: DateFormat.LONG, DateFormat.SHORT);
138: dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
139: return dateFormat.format(date);
140: }
141:
142: }
|