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.logistics.ui.inventory;
028:
029: import java.util.Hashtable;
030: import java.util.Collection;
031: import java.util.Collections;
032: import java.util.Enumeration;
033: import java.util.Vector;
034:
035: import java.awt.Component;
036: import javax.swing.JOptionPane;
037:
038: import java.io.InputStream;
039: import java.io.ObjectInputStream;
040:
041: import org.cougaar.util.log.Logging;
042: import org.cougaar.util.log.Logger;
043:
044: import org.cougaar.logistics.ui.inventory.data.InventoryData;
045:
046: /**
047: * <pre>
048: *
049: * The InventoryFileManager manages all the files opened
050: * and behaves like an InventoryDataSource to serve up
051: * all the charts that have been opened.
052: *
053: *
054: * @see InventoryDataSource
055: * @see InventoryConnectionManager
056: * @see InventoryUIFrame
057: *
058: **/
059:
060: public class InventoryFileManager implements InventoryDataSource {
061:
062: final public static String[] SUPPLY_CLASS_TYPES = { "Ammunition",
063: "BulkPOL", "Subsistence", "ClassVIIIMedical",
064: "PackagedPOL", "Consumable" };
065: final public static String[] FILE_CLASS_TYPES = { "File" };
066:
067: protected Component parentComponent;
068: protected Hashtable orgToItems;
069: protected Hashtable currItemToXML;
070:
071: protected String invXMLStr;
072:
073: protected Logger logger;
074:
075: public InventoryFileManager(Component parent) {
076: parentComponent = parent;
077: logger = Logging.getLogger(this );
078: orgToItems = new Hashtable();
079: currItemToXML = null;
080: }
081:
082: public String getCurrentInventoryData() {
083: return invXMLStr;
084: }
085:
086: public static String getFullItemName(InventoryData header) {
087: String itemNomenclature = null;
088: String nomenclature = header.getNomenclature();
089: if ((nomenclature == null) || (nomenclature.trim().equals(""))) {
090: itemNomenclature = header.getItem();
091: } else {
092: if (isClassOfSupply(nomenclature)) {
093: itemNomenclature = header.getItem() + ":"
094: + nomenclature;
095: } else {
096: itemNomenclature = nomenclature + ":"
097: + header.getItem();
098: }
099: }
100: return itemNomenclature;
101: }
102:
103: public void addItem(InventoryData header, String xmlStr) {
104: String itemNomenclature = getFullItemName(header);
105: currItemToXML = (Hashtable) orgToItems.get(header.getOrg());
106: if (currItemToXML == null) {
107: currItemToXML = new Hashtable();
108: orgToItems.put(header.getOrg(), currItemToXML);
109: }
110: currItemToXML.put(itemNomenclature, xmlStr);
111: invXMLStr = xmlStr;
112: }
113:
114: public static boolean isClassOfSupply(String nomen) {
115: for (int i = 0; i < SUPPLY_CLASS_TYPES.length; i++) {
116: String aSupplyClass = SUPPLY_CLASS_TYPES[i];
117: if (nomen.equals(aSupplyClass)) {
118: return true;
119: }
120: }
121: return false;
122: }
123:
124: public String getInventoryData(String orgName, String assetName) {
125: if (logger.isDebugEnabled()) {
126: logger.debug("getInventoryData: OrgName: " + orgName
127: + " AssetName: " + assetName);
128: }
129: currItemToXML = (Hashtable) orgToItems.get(orgName);
130: invXMLStr = (String) currItemToXML.get(assetName);
131: return invXMLStr;
132: }
133:
134: public Vector getAssetNames(String orgName, String supplyType) {
135: currItemToXML = (Hashtable) orgToItems.get(orgName);
136: Enumeration keys = currItemToXML.keys();
137: Vector assetNames = new Vector();
138: while (keys.hasMoreElements()) {
139: assetNames.addElement(keys.nextElement());
140: }
141: Collections.sort(assetNames);
142: return assetNames;
143: }
144:
145: public String[] getSupplyTypes() {
146: return FILE_CLASS_TYPES;
147: }
148:
149: public String getDefaultOrganizationName() {
150: Vector orgNames = getSortedOrgNames();
151: if (orgNames == null)
152: return null;
153: return (String) orgNames.elementAt(1);
154: }
155:
156: public Vector getOrgNames(String agentPath, String orgPopMethod) {
157: logger.debug("Getting Org List");
158: return getSortedOrgNames();
159: }
160:
161: protected Vector getSortedOrgNames() {
162: Enumeration names = orgToItems.keys();
163: Vector vNames = new Vector();
164: while (names.hasMoreElements())
165: vNames.addElement(names.nextElement());
166: Collections.sort(vNames);
167: return vNames;
168: }
169:
170: protected void displayErrorString(String reply) {
171: JOptionPane.showMessageDialog(parentComponent, reply, reply,
172: JOptionPane.ERROR_MESSAGE);
173: }
174: }
|