001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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:
027: package org.cougaar.mlm.debug.ui;
028:
029: import org.cougaar.glm.ldm.asset.Organization;
030: import org.cougaar.glm.ldm.asset.PhysicalAsset;
031: import org.cougaar.planning.ldm.asset.AbstractAsset;
032: import org.cougaar.planning.ldm.asset.AggregateAsset;
033: import org.cougaar.planning.ldm.asset.Asset;
034: import org.cougaar.planning.ldm.asset.ItemIdentificationPG;
035: import org.cougaar.planning.ldm.asset.TypeIdentificationPG;
036:
037: /** Return a string description of a physical asset or cluster; used
038: * to display asset information in log plans, etc.
039: */
040:
041: public class UIAsset {
042:
043: /** Return a name for this asset:
044: if typeIdentificationProperty is non-null
045: then if nomenclature is defined, use it, else use typeIdentification
046: else use toString
047: For Requisition, use documentNumber
048: For SupplySource, use vendorName
049: */
050:
051: public static String getName(Asset asset) {
052: TypeIdentificationPG tip = asset.getTypeIdentificationPG();
053: String s = null;
054:
055: if (tip != null) {
056: s = tip.getNomenclature();
057: if (s == null || s.equals("")
058: || s.equals("RuntimePrototype"))
059: s = tip.getTypeIdentification();
060: }
061:
062: // if it is null or looks like: org.cougaar.planning.ldm.asset.Asset@1394...
063: // then use toString() for the object
064: if ((s == null) || (s.indexOf("@") != -1))
065: s = asset.toString();
066: return s;
067: }
068:
069: /*
070: public static String getName(Requisition req) {
071: return req.getDocumentNumber();
072: }
073: */
074: /** Return an asset description:
075: For PhysicalAsset,
076: return name (from above) and ItemIdentificationPG.ItemIdentification
077: For OrganizationAsset, return ItemIdentificationPG.AlternateItemId
078: For AggregateAsset, return name (from above) and quantity
079: For all other assets, return toString
080: */
081: public static String getDescription(Asset asset) {
082: if (asset == null)
083: return "";
084: String s = "";
085: String sn = "";
086: if (asset instanceof PhysicalAsset
087: || asset instanceof AbstractAsset) {
088: s = getName(asset);
089: ItemIdentificationPG itemIdProp = asset
090: .getItemIdentificationPG();
091: if (itemIdProp != null) {
092: sn = itemIdProp.getItemIdentification();
093: }
094: if ((sn != null) && (sn != ""))
095: s = s + " " + sn;
096: } else if (asset instanceof Organization) {
097: ItemIdentificationPG itemIdProp = ((Organization) asset)
098: .getItemIdentificationPG();
099: if (itemIdProp != null)
100: s = itemIdProp.getAlternateItemIdentification();
101: } else if (asset instanceof AggregateAsset) {
102: AggregateAsset aa = (AggregateAsset) asset;
103: Asset a = aa.getAsset();
104: String nomen = "";
105: String tid = "";
106: // TypeIdentificationPG typeIdProp =
107: // asset.getTypeIdentificationPG();
108: TypeIdentificationPG typeIdProp = a
109: .getTypeIdentificationPG();
110: if (typeIdProp != null) {
111: nomen = typeIdProp.getNomenclature();
112: tid = typeIdProp.getTypeIdentification();
113:
114: if ((nomen != null) && (nomen != "") && (tid != null)
115: && (tid != "")) {
116: if (tid.compareTo(nomen) != 0) {
117: s = nomen + " " + tid;
118: } else {
119: s = nomen;
120: }
121: } else if ((nomen != null) && (nomen != "")) {
122: s = nomen;
123: } else if ((tid != null) && (tid != "")) {
124: s = tid;
125: }
126: // s = typeIdProp.getNomenclature() + " " +
127: // typeIdProp.getTypeIdentification();
128: }
129: // s = getName(a);
130: /*
131: Schedule sch = aa.getSchedule();
132: Enumeration e = sch.getAllScheduleElements();
133: int nElements = 0;
134: while (e.hasMoreElements()) {
135: nElements++;
136: Object o = e.nextElement();
137: if (o instanceof QuantityRangeScheduleElement) {
138: double d = ((QuantityRangeScheduleElement)o).getStartQuantity();
139: s = s + " Start Quantity: " + d;
140: } else if (o instanceof QuantityScheduleElement) {
141: double d = ((QuantityScheduleElement)o).getQuantity();
142: s = s + " Quantity: " + d;
143: }
144: }
145: s = s + " Number of ScheduleElements: " + nElements;
146: */
147: } else {
148: s = getName(asset);
149: }
150: return s;
151: }
152:
153: /** Return a requisition (FGI) description which is:
154: Document Number: documentNumber
155: */
156:
157: /*
158: public static String getDescription(Requisition req) {
159: if (req == null)
160: return "";
161: String s = "";
162: s = getName(req);
163: return s;
164: }
165: */
166:
167: /**
168: Return a SupplySource (FGI) description which is vendorName.
169: */
170:
171: /*
172: public static String getDescription(SupplySource suppSrc) {
173: String s = "";
174: if (suppSrc == null) {
175: return s;
176: } else if (suppSrc instanceof DepotSupplySource) {
177: return "Depot SS";
178: } else if (suppSrc instanceof DRMSSupplySource) {
179: return "DRMS SS";
180: } else if (suppSrc instanceof VendorSupplySource) {
181: Vendor vend = ((VendorSupplySource)suppSrc).getVendor();
182: if (vend != null) {
183: s = vend.getVendorName();
184: if (s != null && (!s.equals("")))
185: return s;
186: }
187: }
188: return "";
189: }
190: */
191: }
|