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.text.ParseException;
031: import java.util.TimeZone;
032: import java.util.Vector;
033:
034: import org.cougaar.core.mts.MessageAddress;
035: import org.cougaar.planning.ldm.asset.Asset;
036: import org.cougaar.planning.ldm.plan.ClusterObjectFactory;
037: import org.cougaar.planning.ldm.plan.NewPrepositionalPhrase;
038: import org.cougaar.planning.ldm.plan.NewTask;
039: import org.cougaar.planning.ldm.plan.Plan;
040: import org.cougaar.planning.ldm.plan.Schedule;
041: import org.cougaar.planning.ldm.plan.ScheduleElement;
042: import org.cougaar.planning.ldm.plan.Verb;
043: import org.cougaar.planning.plugin.legacy.PluginDelegate;
044:
045: /** Supports user input of tasks.
046: */
047:
048: public class UserInputTask {
049: NewTask task;
050: UIPlugin uiPlugin;
051: ClusterObjectFactory cof;
052: MessageAddress myClusterId;
053: String myClusterName;
054: Plan plan;
055: PluginDelegate delegate;
056:
057: /** Create a new task with the user input.
058: */
059:
060: public UserInputTask(UIPlugin uiPlugin, PluginDelegate delegate,
061: String destinationName, String objectClusterAssetName,
062: String objectPhysicalAssetName, Vector objectCapabilities,
063: int objectAssetQuantity, String phrasePreposition,
064: String phraseClusterAssetName,
065: String phrasePhysicalAssetName, Vector phraseCapabilities,
066: int phraseAssetQuantity, String verb, String startDate,
067: String endDate, String bestDate) {
068: this .uiPlugin = uiPlugin;
069: this .delegate = delegate;
070: cof = delegate.getFactory();
071: myClusterId = delegate.getMessageAddress();
072: myClusterName = myClusterId.getAddress();
073: plan = cof.getRealityPlan();
074: task = cof.newTask();
075: task.setPlan(plan);
076: task.setSource(myClusterId);
077: task.setDestination(uiPlugin
078: .getClusterIdFromName(destinationName));
079: task.setDirectObject(createAsset(objectClusterAssetName,
080: objectPhysicalAssetName, objectCapabilities,
081: objectAssetQuantity));
082: if (phrasePreposition != "") {
083: NewPrepositionalPhrase phrase = cof
084: .newPrepositionalPhrase();
085: phrase.setPreposition(phrasePreposition);
086: phrase.setIndirectObject(createAsset(
087: phraseClusterAssetName, phrasePhysicalAssetName,
088: phraseCapabilities, phraseAssetQuantity));
089: task.setPrepositionalPhrases(phrase);
090: }
091: if (verb != "")
092: task.setVerb(Verb.get(verb));
093: // set dates in penalty function
094: //if ((startDate != "") && (endDate != "") && (bestDate != ""))
095: // task.setPenaltyFunction(createPenaltyFunction(startDate, endDate,
096: // bestDate));
097: }
098:
099: /** Create a schedule from a start and end date.
100: */
101:
102: public static Schedule createSchedule(ClusterObjectFactory cof,
103: String startDate, String endDate) {
104: DateFormat dateFormat = DateFormat.getDateTimeInstance(
105: DateFormat.LONG, DateFormat.SHORT);
106: dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
107: Schedule schedule = null;
108: try {
109: //schedule = cof.newSchedule(dateFormat.parse(startDate),
110: schedule = cof.newSimpleSchedule(dateFormat
111: .parse(startDate), dateFormat.parse(endDate));
112: } catch (ParseException pe) {
113: System.out.println("Exception parsing dates: " + pe);
114: }
115: return schedule;
116: }
117:
118: /** Create a schedule element from a start and end date.
119: */
120:
121: public static ScheduleElement createScheduleElement(
122: ClusterObjectFactory cof, String startDate, String endDate) {
123: DateFormat dateFormat = DateFormat.getDateTimeInstance(
124: DateFormat.LONG, DateFormat.SHORT);
125: dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
126: ScheduleElement scheduleelement = null;
127: try {
128: scheduleelement = cof.newScheduleElement(dateFormat
129: .parse(startDate), dateFormat.parse(endDate));
130: } catch (ParseException pe) {
131: System.out.println("Exception parsing dates: " + pe);
132: }
133: return scheduleelement;
134: }
135:
136: //private PenaltyFunction createPenaltyFunction(String startDate,
137: // String endDate,
138: // String bestDate) {
139: //DateFormat dateFormat =
140: // DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
141: //dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
142: //PenaltyFunction penaltyFunction = null;
143: //try {
144: // penaltyFunction = cof.newDesiredSchedule(dateFormat.parse(startDate),
145: // dateFormat.parse(endDate),
146: // dateFormat.parse(bestDate));
147: //} catch (ParseException pe) {
148: // System.out.println("Exception parsing dates: " + pe);
149: //}
150: //return penaltyFunction;
151: //}
152:
153: private Asset createAsset(String clusterAssetName,
154: String physicalAssetName, Vector capabilities, int quantity) {
155: if (capabilities != null) {
156: System.out
157: .println("Creating asset capabilities not supported.");
158: }
159: if (clusterAssetName != "") {
160: try {
161: return (Asset) delegate.getFactory().createInstance(
162: clusterAssetName.trim(),
163: clusterAssetName.trim());
164: } catch (Exception e) {
165: System.out
166: .println("Unable to construct an organizational asset in UserInputTask.creatAsset(). Exception is "
167: + e.toString());
168: e.printStackTrace();
169: }
170: }
171:
172: if (quantity > 1) {
173: System.out
174: .println("Creating aggregate assets not supported.");
175: return null;
176: }
177:
178: if (physicalAssetName != "") {
179: System.out
180: .println("Creating physical assets not supported.");
181: return null;
182: }
183:
184: return null;
185: }
186:
187: /** Create an allocation, and a plan element, and add the task
188: being composed to the local log plan.
189: */
190:
191: public void addToLogPlan() {
192: }
193:
194: }
|