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.logistics.plugin.utils;
029:
030: import java.util.Date;
031: import java.util.Vector;
032:
033: import org.cougaar.core.mts.MessageAddress;
034: import org.cougaar.glm.ldm.Constants;
035: import org.cougaar.glm.xml.parser.TaskParser;
036: import org.cougaar.glm.parser.GLMTaskParser;
037: import org.cougaar.logistics.plugin.inventory.MaintainedItem;
038: import org.cougaar.lib.xml.parser.DateParser;
039: import org.cougaar.lib.xml.parser.DirectObjectParser;
040: import org.cougaar.lib.xml.parser.PreferencesParser;
041: import org.cougaar.lib.xml.parser.VerbParser;
042: import org.cougaar.planning.ldm.LDMServesPlugin;
043: import org.cougaar.planning.ldm.PlanningFactory;
044: import org.cougaar.planning.ldm.asset.Asset;
045: import org.cougaar.planning.ldm.asset.NewTypeIdentificationPG;
046: import org.cougaar.planning.ldm.plan.NewPrepositionalPhrase;
047: import org.cougaar.planning.ldm.plan.NewTask;
048: import org.cougaar.planning.ldm.plan.Preference;
049: import org.cougaar.planning.ldm.plan.Schedule;
050: import org.cougaar.planning.ldm.plan.Task;
051: import org.cougaar.planning.ldm.plan.Verb;
052: import org.cougaar.util.log.Logger;
053: import org.w3c.dom.Node;
054: import org.w3c.dom.NodeList;
055:
056: /**
057: * Understands "maintaining" tag in xml task input file.
058: *
059: * An example would be:
060: *
061: * <maintaining>
062: * <class>class org.cougaar.logistics.plugin.inventory.MaintainedItem</class>
063: * <itemID>FCS-C2V-0.MCG1.1-UA.ARMY.MIL</itemID>
064: * <type>Asset</type>
065: * <nomen>Command and Control Vehicle</nomen>
066: * <typeID>NSN/FCS-C2V</typeID>
067: * </maintaining>
068: *
069: *
070: * Copyright (c) 1999-2002 BBN Technologies
071: */
072: public class ALTaskParserWrapper extends GLMTaskParser {
073:
074: protected TaskParser makeTaskParser() {
075: return new ALTaskParser(logger);
076: }
077:
078: public class ALTaskParser extends TaskParser {
079: public ALTaskParser(Logger logger) {
080: super (logger);
081: }
082:
083: protected boolean handleTag(NewTask task, Vector prep_phrases,
084: LDMServesPlugin ldm, PlanningFactory ldmf, Node child) {
085: boolean didSomethingWithTag = false;
086: String childname = child.getNodeName();
087: if (childname.equals("maintaining")) {
088: // same as with
089: NewPrepositionalPhrase newpp = ldmf
090: .newPrepositionalPhrase();
091: newpp.setPreposition(Constants.Preposition.MAINTAINING);
092: newpp
093: .setIndirectObject(getMaintainingObject(ldm,
094: child));
095: prep_phrases.addElement(newpp);
096: didSomethingWithTag = true;
097: } else {
098: return super .handleTag(task, prep_phrases, ldm, ldmf,
099: child);
100: }
101:
102: return didSomethingWithTag;
103: }
104:
105: protected Object getMaintainingObject(LDMServesPlugin ldm,
106: Node node) {
107: String type = null, typeID = null, itemID = null, nomen = null;
108:
109: NodeList nlist = node.getChildNodes();
110: int nlength = nlist.getLength();
111:
112: for (int i = 0; i < nlength; i++) {
113: Node child = nlist.item(i);
114: String childname = child.getNodeName();
115: if (child.getNodeType() == Node.ELEMENT_NODE) {
116: if (childname.equals("type"))
117: type = getTagContents(child);
118: else if (childname.equals("typeID"))
119: typeID = getTagContents(child);
120: else if (childname.equals("nomen"))
121: nomen = getTagContents(child);
122: else if (childname.equals("itemID"))
123: itemID = getTagContents(child);
124: }
125: }
126:
127: return new MaintainedItem(type, typeID, itemID, nomen, null);
128: }
129: }
130: }
|