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.io.Serializable;
030:
031: import org.cougaar.planning.servlet.data.xml.DeXMLable;
032: import org.cougaar.planning.servlet.data.xml.UnexpectedXMLException;
033: import org.cougaar.planning.servlet.data.xml.XMLWriter;
034: import org.cougaar.planning.servlet.data.xml.XMLable;
035: import org.xml.sax.Attributes;
036:
037: /**
038: * Abstract representation of the data leaving the Completion PSP.
039: *
040: * @see FullCompletionData
041: * @see SimpleCompletionData
042: **/
043: public abstract class CompletionData implements XMLable, DeXMLable,
044: Serializable {
045:
046: //Variables:
047: ////////////
048:
049: public static final String NAME_TAG = "Completion";
050:
051: public static final String TIME_MILLIS_ATTR = "TimeMillis";
052: public static final String RATIO_ATTR = "Ratio";
053: public static final String NUMBER_OF_TASKS_ATTR = "NumTasks";
054:
055: protected long timeMillis;
056: protected double ratio;
057: protected int numTasks;
058: protected int numRootProjectSupplyTasks;
059: protected int numRootSupplyTasks;
060: protected int numRootTransportTasks;
061:
062: //Constructors:
063: ///////////////
064:
065: public CompletionData() {
066: }
067:
068: //Setters:
069: //////////
070:
071: public void setTimeMillis(long timeMillis) {
072: this .timeMillis = timeMillis;
073: }
074:
075: public void setRatio(double ratio) {
076: // assert (0.0 <= ratio && ratio <= 1.0);
077: this .ratio = ratio;
078: }
079:
080: public void setNumberOfTasks(int numTasks) {
081: this .numTasks = numTasks;
082: }
083:
084: public void setNumberOfRootProjectSupplyTasks(int numTasks) {
085: numRootProjectSupplyTasks = numTasks;
086: }
087:
088: public void setNumberOfRootTransportTasks(int numTasks) {
089: numRootTransportTasks = numTasks;
090: }
091:
092: public void setNumberOfRootSupplyTasks(int numTasks) {
093: numRootSupplyTasks = numTasks;
094: }
095:
096: //Getters:
097: //////////
098:
099: public long getTimeMillis() {
100: return timeMillis;
101: }
102:
103: /** number between 0.0 and 1.0, inclusive. */
104: public double getRatio() {
105: return ratio;
106: }
107:
108: public int getNumberOfTasks() {
109: return numTasks;
110: }
111:
112: public int getNumberOfRootProjectSupplyTasks() {
113: return numRootProjectSupplyTasks;
114: }
115:
116: public int getNumberOfRootSupplyTasks() {
117: return numRootSupplyTasks;
118: }
119:
120: public int getNumberOfRootTransportTasks() {
121: return numRootTransportTasks;
122: }
123:
124: public abstract int getNumberOfUnplannedTasks();
125:
126: public abstract int getNumberOfUnestimatedTasks();
127:
128: public abstract int getNumberOfUnconfidentTasks();
129:
130: public abstract int getNumberOfFailedTasks();
131:
132: public int getNumberOfFullySuccessfulTasks() {
133: return (getNumberOfTasks() - (getNumberOfUnplannedTasks()
134: + getNumberOfUnestimatedTasks()
135: + getNumberOfUnconfidentTasks() + getNumberOfFailedTasks()));
136: }
137:
138: public abstract UnplannedTask getUnplannedTaskAt(int i);
139:
140: public abstract UnestimatedTask getUnestimatedTaskAt(int i);
141:
142: public abstract UnconfidentTask getUnconfidentTaskAt(int i);
143:
144: public abstract FailedTask getFailedTaskAt(int i);
145:
146: //XMLable members:
147: //----------------
148:
149: /**
150: * Write this class out to the Writer in XML format
151: * @param w output Writer
152: **/
153: public abstract void toXML(XMLWriter w) throws IOException;
154:
155: //DeXMLable members:
156: //------------------
157:
158: /**
159: * Report a startElement that pertains to THIS object, not any
160: * sub objects. Call also provides the elements Attributes and data.
161: * Note, that unlike in a SAX parser, data is guaranteed to contain
162: * ALL of this tag's data, not just a 'chunk' of it.
163: * @param name startElement tag
164: * @param attr attributes for this tag
165: * @param data data for this tag
166: **/
167: public abstract void openTag(String name, Attributes attr,
168: String data) throws UnexpectedXMLException;
169:
170: /**
171: * Report an endElement.
172: * @param name endElement tag
173: * @return true iff the object is DONE being DeXMLized
174: **/
175: public abstract boolean closeTag(String name)
176: throws UnexpectedXMLException;
177:
178: /**
179: * This function will be called whenever a subobject has
180: * completed de-XMLizing and needs to be encorporated into
181: * this object.
182: * @param name the startElement tag that caused this subobject
183: * to be created
184: * @param obj the object itself
185: **/
186: public abstract void completeSubObject(String name, DeXMLable obj)
187: throws UnexpectedXMLException;
188:
189: //Inner Classes:
190:
191: /**
192: * Set the serialVersionUID to keep the object serializer from seeing
193: * xerces (org.xml.sax.Attributes).
194: */
195: private static final long serialVersionUID = 1234679540398212345L;
196: }
|