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: * Represents an abstract Task entry within the COMPLETION PSP.
039: **/
040: public abstract class AbstractTask implements XMLable, DeXMLable,
041: Serializable {
042:
043: //Variables:
044: ////////////
045:
046: protected final static String UID_TAG = "UID";
047: protected final static String UID_URL_TAG = "UID_URL";
048: protected final static String PARENT_UID_TAG = "ParentUID";
049: protected final static String PARENT_UID_URL_TAG = "ParentUID_URL";
050: protected final static String CONFIDENCE_TAG = "Confidence";
051: protected final static String PLAN_ELEMENT_TAG = "PlanElement";
052:
053: protected String uid;
054: protected String uid_url;
055: protected String parentUID;
056: protected String parentUID_url;
057: protected double confidence;
058: protected String planElement;
059: protected String verb;
060:
061: //Constructors:
062: ///////////////
063:
064: public AbstractTask() {
065: }
066:
067: //Tag override:
068: ///////////////
069: protected abstract String getNameTag();
070:
071: //Setters:
072: //////////
073:
074: public void setUID(String uid) {
075: this .uid = uid;
076: }
077:
078: public void setUID_URL(String uid_url) {
079: this .uid_url = uid_url;
080: }
081:
082: public void setParentUID(String parentUID) {
083: this .parentUID = parentUID;
084: }
085:
086: public void setParentUID_URL(String parentUID_url) {
087: this .parentUID_url = parentUID_url;
088: }
089:
090: public void setConfidence(double confidence) {
091: this .confidence = confidence;
092: }
093:
094: public void setPlanElement(String planElement) {
095: this .planElement = planElement;
096: }
097:
098: public void setVerb(String verb) {
099: this .verb = verb;
100: }
101:
102: //Getters:
103: //////////
104:
105: public String getUID() {
106: return uid;
107: }
108:
109: public String getUID_URL() {
110: return uid_url;
111: }
112:
113: public String getParentUID() {
114: return parentUID;
115: }
116:
117: public String getParentUID_URL() {
118: return parentUID_url;
119: }
120:
121: public double getConfidence() {
122: return confidence;
123: }
124:
125: public String getPlanElement() {
126: return planElement;
127: }
128:
129: public String getVerb() {
130: return verb;
131: }
132:
133: //XMLable members:
134: //----------------
135:
136: /**
137: * Write this class out to the Writer in XML format
138: * @param w output Writer
139: **/
140: public void toXML(XMLWriter w) throws IOException {
141: w.optagln(getNameTag());
142:
143: w.tagln(UID_TAG, getUID());
144: w.tagln(UID_URL_TAG, getUID_URL());
145: w.tagln(PARENT_UID_TAG, getParentUID());
146: w.tagln(PARENT_UID_URL_TAG, getParentUID_URL());
147: w.tagln(CONFIDENCE_TAG, getConfidence());
148: w.tagln(PLAN_ELEMENT_TAG, getPlanElement());
149:
150: w.cltagln(getNameTag());
151: }
152:
153: //DeXMLable members:
154: //------------------
155:
156: /**
157: * Report a startElement that pertains to THIS object, not any
158: * sub objects. Call also provides the elements Attributes and data.
159: * Note, that unlike in a SAX parser, data is guaranteed to contain
160: * ALL of this tag's data, not just a 'chunk' of it.
161: * @param name startElement tag
162: * @param attr attributes for this tag
163: * @param data data for this tag
164: **/
165: public void openTag(String name, Attributes attr, String data)
166: throws UnexpectedXMLException {
167: if (name.equals(getNameTag())) {
168: } else if (name.equals(UID_TAG)) {
169: setUID(data);
170: } else if (name.equals(UID_URL_TAG)) {
171: setUID_URL(data);
172: } else if (name.equals(PARENT_UID_TAG)) {
173: setParentUID(data);
174: } else if (name.equals(PARENT_UID_URL_TAG)) {
175: setParentUID_URL(data);
176: } else if (name.equals(CONFIDENCE_TAG)) {
177: try {
178: setConfidence(Double.parseDouble(data));
179: } catch (NumberFormatException e) {
180: throw new UnexpectedXMLException("Malformed Number: "
181: + name + " : " + data);
182: }
183: } else if (name.equals(PLAN_ELEMENT_TAG)) {
184: setPlanElement(data);
185: } else {
186: throw new UnexpectedXMLException("Unexpected tag: " + name);
187: }
188: }
189:
190: /**
191: * Report an endElement.
192: * @param name endElement tag
193: * @return true iff the object is DONE being DeXMLized
194: **/
195: public boolean closeTag(String name) throws UnexpectedXMLException {
196: return name.equals(getNameTag());
197: }
198:
199: /**
200: * This function will be called whenever a subobject has
201: * completed de-XMLizing and needs to be encorporated into
202: * this object.
203: * @param name the startElement tag that caused this subobject
204: * to be created
205: * @param obj the object itself
206: **/
207: public void completeSubObject(String name, DeXMLable obj)
208: throws UnexpectedXMLException {
209: }
210:
211: /**
212: * Set the serialVersionUID to keep the object serializer from seeing
213: * xerces (org.xml.sax.Attributes).
214: */
215: private static final long serialVersionUID = 728328929999383874L;
216: }
|