01: /*
02: * <copyright>
03: *
04: * Copyright 2001-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26: package org.cougaar.planning.servlet.data.completion;
27:
28: import org.cougaar.planning.servlet.data.Failure;
29: import org.cougaar.planning.servlet.data.xml.DeXMLable;
30: import org.cougaar.planning.servlet.data.xml.DeXMLableFactory;
31: import org.cougaar.planning.servlet.data.xml.UnexpectedXMLException;
32: import org.xml.sax.Attributes;
33:
34: /**
35: * Factory that produces sub-objects based on tags and attributes
36: * for CompletionData
37: **/
38: public class CompletionDataFactory implements DeXMLableFactory {
39:
40: //Variables:
41: ////////////
42:
43: //Members:
44: //////////
45:
46: /**
47: * This is a look ahead to see if we should start a sub object.
48: * The caller will first call this function on startElement. If
49: * this function returns null, the startElement will be reported
50: * to the current object with a call to openTag(...). Otherwise
51: * this function should return a new DeXMLable subobject that
52: * further output will be deligated to, until the subobject returns
53: * true from a call to endElement().
54: *
55: * @param curObj the current object
56: * @param name startElement tag
57: * @param attr startElement attributes
58: * @return a new DeXMLable subobject if a subobject should be created,
59: * otherwise null.
60: **/
61: public DeXMLable beginSubObject(DeXMLable curObj, String name,
62: Attributes attr) throws UnexpectedXMLException {
63: if (curObj == null) {
64: if (name.equals(FullCompletionData.NAME_TAG)) {
65: return new FullCompletionData();
66: } else if (name.equals(SimpleCompletionData.NAME_TAG)) {
67: return new SimpleCompletionData();
68: } else if (name.equals(Failure.NAME_TAG)) {
69: return new Failure();
70: }
71: } else if (curObj instanceof CompletionData) {
72: if (name.equals(UnplannedTask.NAME_TAG)) {
73: return new UnplannedTask();
74: } else if (name.equals(UnestimatedTask.NAME_TAG)) {
75: return new UnestimatedTask();
76: } else if (name.equals(UnconfidentTask.NAME_TAG)) {
77: return new UnconfidentTask();
78: } else if (name.equals(FailedTask.NAME_TAG)) {
79: return new FailedTask();
80: }
81: }
82: return null;
83: }
84: }
|