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.logistics.plugin.trans;
027:
028: import java.util.Date;
029:
030: import org.cougaar.planning.ldm.asset.AggregateAsset;
031: import org.cougaar.planning.ldm.asset.Asset;
032: import org.cougaar.planning.ldm.measure.Distance;
033: import org.cougaar.planning.ldm.plan.Task;
034:
035: import org.cougaar.glm.ldm.asset.Container;
036: import org.cougaar.glm.ldm.asset.GLMAsset;
037:
038: import org.cougaar.lib.util.UTILPreference;
039: import org.cougaar.lib.util.UTILPrepPhrase;
040:
041: import org.cougaar.logistics.plugin.trans.GLMTransConst;
042: import org.cougaar.util.log.Logger;
043:
044: /**
045: * Create XML document in the Vishnu Data format, directly from ALP objects.
046: * <p>
047: * Create and return xml for log plan objects.
048: * <p>
049: */
050:
051: public class SeaDataXMLize extends GenericDataXMLize {
052: public static final String TRUE = "true";
053: public static final String FALSE = "false";
054:
055: public SeaDataXMLize(boolean direct, Logger logger) {
056: super (direct, logger);
057: prefHelper = new UTILPreference(logger);
058: prepHelper = new UTILPrepPhrase(logger);
059: }
060:
061: /**
062: * Create XML for asset, subclass to add fields
063: *
064: * @param object node representing asset
065: * @param taskOrAsset asset being translated
066: * @return true if should add object to list of new objects
067: */
068: protected boolean processAsset(Object object, Object taskOrAsset) {
069: if (!super .processAsset(object, taskOrAsset))
070: return false;
071:
072: GLMAsset asset = (GLMAsset) taskOrAsset;
073:
074: dataHelper.createField(object, "Asset", "containerCapacity", ""
075: + getContainerCapacity(asset));
076: dataHelper.createField(object, "Asset", "isAmmoShip",
077: isAmmoShip(asset) ? TRUE : FALSE);
078:
079: return true;
080: }
081:
082: /**
083: * Create XML for task, subclass to add fields
084: *
085: * @param object node representing task
086: * @param taskOrAsset task being translated
087: * @return true if should add object to list of new objects
088: */
089: protected boolean processTask(Object object, Object taskOrAsset) {
090: super .processTask(object, taskOrAsset);
091: Task task = (Task) taskOrAsset;
092: Asset directObject = task.getDirectObject();
093: GLMAsset baseAsset;
094:
095: if (directObject instanceof AggregateAsset) {
096: baseAsset = (GLMAsset) ((AggregateAsset) directObject)
097: .getAsset();
098: } else {
099: baseAsset = (GLMAsset) directObject;
100: }
101:
102: boolean isContainer = isContainer(baseAsset);
103: dataHelper.createField(object, "Transport", "isContainer",
104: isContainer(baseAsset) ? TRUE : FALSE);
105: // dataHelper.createField(object, "Transport", "isAmmo", (isContainer ? (isAmmo (baseAsset) ? TRUE : FALSE) : FALSE));
106:
107: Date earliestArrival = new Date(prefHelper.getEarlyDate(task)
108: .getTime());
109: dataHelper.createDateField(object, "earliestArrival",
110: earliestArrival);
111: Date latestArrival = new Date(prefHelper.getLateDate(task)
112: .getTime());
113: dataHelper.createDateField(object, "latestArrival",
114: latestArrival);
115:
116: return true;
117: }
118:
119: /** don't send the isPerson field */
120: protected void addTaskPersonField(Object object, GLMAsset baseAsset) {
121: }
122:
123: /** don't send the passengerCapacity field */
124: protected void addPassengerCapacity(Object object, GLMAsset asset) {
125: }
126:
127: protected boolean isContainer(GLMAsset asset) {
128: LowFidelityAssetPG currentLowFiAssetPG = (LowFidelityAssetPG) asset
129: .resolvePG(LowFidelityAssetPG.class);
130:
131: if (currentLowFiAssetPG != null) {
132: return currentLowFiAssetPG.getCCCDim().getIsContainer();
133: } else {
134: return asset instanceof Container;
135: }
136: }
137:
138: /**
139: * An asset is an ammo container if it has a contents pg, since
140: * only the Ammo Packer put a contents pg on a container.
141: *
142: * NOTE : should call isContainer first!
143: */
144: protected boolean isAmmo(GLMAsset asset) {
145: return asset.hasContentsPG();
146: }
147:
148: protected double getContainerCapacity(GLMAsset asset) {
149: return (asset.hasContainPG()) ? asset.getContainPG()
150: .getMaximumContainers() : 0.0d;
151: }
152:
153: protected boolean isAmmoShip(GLMAsset asset) {
154: String typeid = asset.getTypeIdentificationPG()
155: .getNomenclature();
156: return typeid.equals("Ammo");
157: }
158:
159: protected UTILPreference prefHelper;
160: protected UTILPrepPhrase prepHelper;
161: }
|