001: //
002: /*
003: * <copyright>
004: *
005: * Copyright 1997-2004 BBNT Solutions, LLC
006: * under sponsorship of the Defense Advanced Research Projects
007: * Agency (DARPA).
008: *
009: * You can redistribute this software and/or modify it under the
010: * terms of the Cougaar Open Source License as published on the
011: * Cougaar Open Source Website (www.cougaar.org).
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: *
025: * </copyright>
026: */
027:
028: package org.cougaar.glm.xml.parser;
029:
030: import java.util.Vector;
031:
032: import org.cougaar.lib.xml.parser.DateParser;
033: import org.cougaar.lib.xml.parser.VerbParser;
034: import org.cougaar.planning.ldm.LDMServesPlugin;
035: import org.cougaar.planning.ldm.plan.ItineraryElement;
036: import org.cougaar.planning.ldm.plan.NewItineraryElement;
037: import org.cougaar.planning.ldm.plan.Schedule;
038: import org.w3c.dom.Node;
039: import org.w3c.dom.NodeList;
040:
041: /**
042: * Copyright (c) 1999 BBN Technologies
043: */
044: public class ItineraryParser {
045: public ItineraryParser() {
046: dateParser = new DateParser();
047: verbParser = new VerbParser();
048: locationParser = new LocationParser();
049: }
050:
051: public Schedule getItinerary(LDMServesPlugin ldm, Node node) {
052: NodeList nlist = node.getChildNodes();
053: int nlength = nlist.getLength();
054:
055: Vector elements = new Vector(10);
056: for (int i = 0; i < nlength; i++) {
057: Node child = nlist.item(i);
058: String childname = child.getNodeName();
059:
060: if (childname.equals("ItineraryElement")) {
061: elements.addElement(getItineraryElement(ldm, child));
062: }
063: }
064: Schedule sched = ldm.getFactory().newSchedule(
065: elements.elements());
066: return sched;
067: }
068:
069: private ItineraryElement getItineraryElement(LDMServesPlugin ldm,
070: Node node) {
071: NodeList nlist = node.getChildNodes();
072: int nlength = nlist.getLength();
073:
074: NewItineraryElement element = ldm.getFactory()
075: .newItineraryElement();
076: for (int i = 0; i < nlength; i++) {
077: Node child = nlist.item(i);
078: String childname = child.getNodeName();
079:
080: if (childname.equals("StartLocation")) {
081: element.setStartLocation(locationParser.getLocation(
082: ldm, child));
083: } else if (childname.equals("EndLocation")) {
084: element.setEndLocation(locationParser.getLocation(ldm,
085: child));
086: } else if (childname.equals("StartDate")) {
087: element.setStartDate(dateParser.getDate(child));
088: } else if (childname.equals("EndDate")) {
089: element.setEndDate(dateParser.getDate(child));
090: } else if (childname.equals("Role")) {
091: element.setRole(verbParser.getVerb(child));
092: }
093: }
094: return element;
095: }
096:
097: DateParser dateParser;
098: VerbParser verbParser;
099: LocationParser locationParser;
100: }
|