01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.plugin.ldm;
28:
29: import org.cougaar.glm.ldm.GLMFactory;
30: import org.cougaar.glm.ldm.plan.NewGeolocLocation;
31: import org.cougaar.planning.ldm.measure.Latitude;
32: import org.cougaar.planning.ldm.measure.Longitude;
33:
34: /** Reads alploc info from a database table. Assumes it's being invoked on
35: * behalf of SQLOplanPlugin. Updates SQLOplanPlugin's geoloc table with alplocs.
36: *
37: * BOZO - alplocs are not geolocs but there isn't any other commonly understood way
38: * to access them.
39: */
40:
41: public class AlpLocQueryHandler extends SQLOplanQueryHandler {
42: private static final String QUERY_NAME = "AlpLocQuery";
43:
44: /** Construct and return an SQL query to be used by the Database engine.
45: * Subclasses are required to implement this method.
46: **/
47: public String getQuery() {
48: return (String) getParameter(QUERY_NAME);
49: }
50:
51: /** Process a single row in a result set,
52: * doing whatever is required.
53: **/
54: public void processRow(Object[] rowData) {
55: if (rowData.length != 4) {
56: System.err
57: .println("AlpLocQueryHandler.processRow() - expected 4 columns of data, "
58: + " got " + rowData.length);
59: }
60:
61: NewGeolocLocation geoloc = GLMFactory.newGeolocLocation();
62: try {
63: if (rowData[1] instanceof String)
64: geoloc.setName((String) rowData[1]);
65: else
66: geoloc.setName(new String((byte[]) rowData[1],
67: "US-ASCII"));
68: if (rowData[0] instanceof String) {
69: geoloc.setGeolocCode((String) rowData[0]);
70: geoloc.setIcaoCode((String) rowData[0]);
71: } else {
72: geoloc.setGeolocCode(new String((byte[]) rowData[0],
73: "US-ASCII"));
74: geoloc.setIcaoCode(new String((byte[]) rowData[0],
75: "US-ASCII"));
76: }
77: //geoloc.setName((String) rowData[1]);
78: //geoloc.setGeolocCode((String) rowData[0]);
79: //geoloc.setIcaoCode((String) rowData[0]);
80: geoloc.setLatitude(Latitude
81: .newLatitude(((Number) rowData[2]).doubleValue()));
82: geoloc.setLongitude(Longitude
83: .newLongitude(((Number) rowData[3]).doubleValue()));
84: geoloc.setInstallationTypeCode("AlpLoc");
85:
86: myPlugin.updateLocation(geoloc);
87:
88: } catch (Exception usee) {
89: System.err
90: .println("Caught exception while executing a query: "
91: + usee);
92: usee.printStackTrace();
93: }
94:
95: }
96:
97: }
|