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