001: /*
002: * <copyright>
003: *
004: * Copyright 2001-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.servlet.data.completion;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: import org.cougaar.planning.servlet.data.xml.DeXMLable;
033: import org.cougaar.planning.servlet.data.xml.UnexpectedXMLException;
034: import org.cougaar.planning.servlet.data.xml.XMLWriter;
035: import org.xml.sax.Attributes;
036:
037: /**
038: * Represents the data leaving the Completion PSP --
039: * <code>FullCompletionData</code> captures all the <code>AbstractTask</code>s.
040: *
041: * @see SimpleCompletionData
042: * @see CompletionData
043: **/
044: public class FullCompletionData extends CompletionData {
045:
046: //Variables:
047: ////////////
048:
049: public static final String NAME_TAG = "FullCompletion";
050:
051: protected List unplannedTasks;
052: protected List unestimatedTasks;
053: protected List unconfidentTasks;
054: protected List failedTasks;
055:
056: //Constructors:
057: ///////////////
058:
059: public FullCompletionData() {
060: unplannedTasks = new ArrayList();
061: unestimatedTasks = new ArrayList();
062: unconfidentTasks = new ArrayList();
063: failedTasks = new ArrayList();
064: }
065:
066: //Setters:
067: //////////
068:
069: public void addUnplannedTask(UnplannedTask ut) {
070: unplannedTasks.add(ut);
071: }
072:
073: public void addUnestimatedTask(UnestimatedTask uet) {
074: unestimatedTasks.add(uet);
075: }
076:
077: public void addUnconfidentTask(UnconfidentTask uct) {
078: unconfidentTasks.add(uct);
079: }
080:
081: public void addFailedTask(FailedTask ft) {
082: failedTasks.add(ft);
083: }
084:
085: //Getters:
086: //////////
087:
088: public int getNumberOfUnplannedTasks() {
089: return unplannedTasks.size();
090: }
091:
092: public int getNumberOfUnestimatedTasks() {
093: return unestimatedTasks.size();
094: }
095:
096: public int getNumberOfUnconfidentTasks() {
097: return unconfidentTasks.size();
098: }
099:
100: public int getNumberOfFailedTasks() {
101: return failedTasks.size();
102: }
103:
104: public UnplannedTask getUnplannedTaskAt(int i) {
105: return (UnplannedTask) unplannedTasks.get(i);
106: }
107:
108: public UnestimatedTask getUnestimatedTaskAt(int i) {
109: return (UnestimatedTask) unestimatedTasks.get(i);
110: }
111:
112: public UnconfidentTask getUnconfidentTaskAt(int i) {
113: return (UnconfidentTask) unconfidentTasks.get(i);
114: }
115:
116: public FailedTask getFailedTaskAt(int i) {
117: return (FailedTask) failedTasks.get(i);
118: }
119:
120: //XMLable members:
121: //----------------
122:
123: /**
124: * Write this class out to the Writer in XML format
125: * @param w output Writer
126: **/
127: public void toXML(XMLWriter w) throws IOException {
128: w.optagln(NAME_TAG);
129: w.tagln(TIME_MILLIS_ATTR, getTimeMillis());
130: w.tagln(RATIO_ATTR, getRatio());
131: w.tagln(NUMBER_OF_TASKS_ATTR, getNumberOfTasks());
132: for (int i = 0; i < getNumberOfUnplannedTasks(); i++) {
133: getUnplannedTaskAt(i).toXML(w);
134: }
135: for (int i = 0; i < getNumberOfUnestimatedTasks(); i++) {
136: getUnestimatedTaskAt(i).toXML(w);
137: }
138: for (int i = 0; i < getNumberOfUnconfidentTasks(); i++) {
139: getUnconfidentTaskAt(i).toXML(w);
140: }
141: for (int i = 0; i < getNumberOfFailedTasks(); i++) {
142: getFailedTaskAt(i).toXML(w);
143: }
144: w.cltagln(NAME_TAG);
145: }
146:
147: //DeXMLable members:
148: //------------------
149:
150: /**
151: * Report a startElement that pertains to THIS object, not any
152: * sub objects. Call also provides the elements Attributes and data.
153: * Note, that unlike in a SAX parser, data is guaranteed to contain
154: * ALL of this tag's data, not just a 'chunk' of it.
155: * @param name startElement tag
156: * @param attr attributes for this tag
157: * @param data data for this tag
158: **/
159: public void openTag(String name, Attributes attr, String data)
160: throws UnexpectedXMLException {
161: try {
162: if (name.equals(NAME_TAG)) {
163: } else if (name.equals(TIME_MILLIS_ATTR)) {
164: timeMillis = Long.parseLong(data);
165: } else if (name.equals(RATIO_ATTR)) {
166: ratio = Double.parseDouble(data);
167: } else if (name.equals(NUMBER_OF_TASKS_ATTR)) {
168: numTasks = Integer.parseInt(data);
169: } else {
170: throw new UnexpectedXMLException("Unexpected tag: "
171: + name);
172: }
173: } catch (NumberFormatException e) {
174: throw new UnexpectedXMLException("Malformed Number: "
175: + name + " : " + data);
176: }
177: }
178:
179: /**
180: * Report an endElement.
181: * @param name endElement tag
182: * @return true iff the object is DONE being DeXMLized
183: **/
184: public boolean closeTag(String name) throws UnexpectedXMLException {
185: return name.equals(NAME_TAG);
186: }
187:
188: /**
189: * This function will be called whenever a subobject has
190: * completed de-XMLizing and needs to be encorporated into
191: * this object.
192: * @param name the startElement tag that caused this subobject
193: * to be created
194: * @param obj the object itself
195: **/
196: public void completeSubObject(String name, DeXMLable obj)
197: throws UnexpectedXMLException {
198: if (obj instanceof UnplannedTask) {
199: addUnplannedTask((UnplannedTask) obj);
200: } else if (obj instanceof UnestimatedTask) {
201: addUnestimatedTask((UnestimatedTask) obj);
202: } else if (obj instanceof UnconfidentTask) {
203: addUnconfidentTask((UnconfidentTask) obj);
204: } else if (obj instanceof FailedTask) {
205: addFailedTask((FailedTask) obj);
206: } else {
207: throw new UnexpectedXMLException("Unexpected object: "
208: + obj);
209: }
210: }
211:
212: //Inner Classes:
213:
214: /**
215: * Set the serialVersionUID to keep the object serializer from seeing
216: * xerces (org.xml.sax.Attributes).
217: */
218: private static final long serialVersionUID = 8898898989829387181L;
219: }
|