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.plugin.ldm;
028:
029: import org.cougaar.planning.ldm.PlanningFactory;
030: import org.cougaar.planning.ldm.asset.Asset;
031: import org.cougaar.planning.ldm.asset.AssetFactory;
032: import org.cougaar.planning.ldm.asset.NewTypeIdentificationPG;
033:
034: /** A QueryHandler which can convert a TypeIdentification code
035: * into an Asset Prototype.
036: **/
037:
038: public class SQLAssetPrototypeProvider
039: //extends QueryHandler
040: extends org.cougaar.mlm.plugin.ldm.PrototypeProvider {
041:
042: private AssetFactory theAssetFactory = null;
043:
044: public SQLAssetPrototypeProvider() {
045: theAssetFactory = new AssetFactory();
046: }
047:
048: /** Called to decide if this QueryHandler can provide
049: * type resolution for this type id code.
050: **/
051: public boolean canHandle(String typeid) {
052: if (!(NSNtoAssetClass(typeid).equals("ClassVIIMajorEndItem")))
053: return true;
054: return false;
055: }
056:
057: /** Turn a typeid into an Asset Prototype, presumably
058: * by looking it up in a database.
059: **/
060: public Asset getAssetPrototype(String typeid) {
061: //public Asset getPrototype( String typeid ) {
062: PlanningFactory ldmfactory = getLDM().getFactory();
063:
064: String protoname = typeid;
065:
066: try {
067: //try {
068: //if (!ldmfactory.isRegistered(protoname)) {
069: //if (!getLDM().isPrototypeCached(protoname)) {
070: String assetClass = NSNtoAssetClass(typeid);
071: //System.err.println( "Trying to register prototype " + assetClass );
072: Asset tmp_asset = (Asset) theAssetFactory.create(Class
073: .forName("org.cougaar.planning.ldm.asset."
074: + assetClass), typeid);
075: //System.err.println( "\ncachePrototype( " + protoname + "," + tmp_asset + ")" );
076: getLDM().cachePrototype(protoname, tmp_asset);
077: //System.err.println("Registered proto for "+assetClass);
078: //}
079: //} catch (org.cougaar.data.RegistryException ex) {
080: //System.out.println("warning: prototype name already in registry \n");
081: //}
082:
083: //System.err.println( "\nGetting prototype " + protoname );
084: Asset pr = (Asset) getLDM().getPrototype(protoname);
085: NewTypeIdentificationPG p1 = (NewTypeIdentificationPG) pr
086: .getTypeIdentificationPG();
087: String tmptypeid = p1.getTypeIdentification();
088: //System.out.println("\n *****AssetPrototypeProvider typeid is: " + tmptypeid);
089: p1.setTypeIdentification(typeid);
090: p1.setNomenclature(typeid);
091: //System.err.println( "\nNOW, typeid = " + pr.getTypeIdentificationPG().getTypeIdentification() );
092: p1.setAlternateTypeIdentification(typeid);
093:
094: System.err.println("Created PrototypeAsset for " + typeid
095: + " = " + pr);
096:
097: myLDMPlugin.fillProperties(pr);
098:
099: return pr;
100: } catch (Exception ee) {
101: System.out.println(ee.toString());
102: ee.printStackTrace();
103: }
104: return null;
105: }
106:
107: private String NSNtoAssetClass(String nsn) {
108: // hel
109: if (nsn.equals("NSN/1520011069519") || // Helicopter: AH-64A
110: nsn.equals("NSN/1520010820686") || // Helicopter: EH-60A
111: nsn.equals("NSN/1520011255476")) // Helicopter: OH-58D
112: return "RotaryWingAircraftWeapon";
113:
114: if (nsn.equals("NSN/1520010350266")) // Helicopter: UH-60A
115: return "CargoRotaryWingAircraft";
116:
117: if (nsn.equals("NSN/2350010871095") || // Tank: M1A1
118: nsn.equals("NSN/2350001226826") || // Recovery Vehicle: M88A1
119: nsn.equals("NSN/2350013050028") || // Howitzer: M109A6
120: nsn.equals("NSN/2350014059886") || // Fighting Veh: M2A2 W/ODS
121: nsn.equals("NSN/2350012487620") || // Fighting Veh: M3A2
122: nsn.equals("NSN/2350010684089") || // CommandPostCarrier: M57782
123: nsn.equals("NSN/2350012197577") || // PersonnelCarrier: M113A3
124: nsn.equals("NSN/2350010853792")) // TrackedPersonnelCarrier: M981
125: return "SelfPropelledGroundWeapon";
126:
127: if (nsn.equals("NSN/2320011077155") || // HMMWV M998
128: nsn.equals("NSN/2320011007673") || // HMMWV M985
129: nsn.equals("NSN/2320011007672") || // HEMMT M978 WOWN (Tank)
130: nsn.equals("NSN/2320013042278") || // PLS Truck: M1075
131: nsn.equals("NSN/2320013189902")) // HET Tractor: M1070
132: return "Truck";
133:
134: if (nsn.equals("NSN/2330013035197") || // PLS Trailer: M1076
135: nsn.equals("NSN/2330013038832")) // HET Trailer: M1000
136: return "Trailer";
137:
138: if (nsn.equals("NSN/8115001519953")) // 20 Ft Container
139: return "Container";
140:
141: if (nsn.equals("NSN/3990013077676")) // PLS Flatrack: M1077
142: return "Container";
143:
144: if (nsn.equals("C005A") || nsn.equals("C005B")
145: || nsn.equals("C017A") || nsn.equals("C141B")
146: || nsn.equals("DC10"))
147: return "CargoFixedWingAircraft";
148:
149: return "ClassVIIMajorEndItem";
150: }
151:
152: public String getQuery() {
153: return null;
154: }
155:
156: public void processRow(Object[] row) {
157: return;
158: }
159:
160: }
|