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 geoloc info from a database table. Assumes it's being invoked on
35: * behalf of SQLOplanPlugin. Updates SQLOplanPlugin's geoloc table.
36: */
37:
38: public class GeoLocQueryHandler extends SQLOplanQueryHandler {
39: private static final String QUERY_NAME = "GeoLocQuery";
40:
41: /** Construct and return an SQL query to be used by the Database engine.
42: * Subclasses are required to implement this method.
43: **/
44: public String getQuery() {
45: return (String) getParameter(QUERY_NAME);
46: }
47:
48: /** Process a single row in a result set,
49: * doing whatever is required.
50: **/
51: public void processRow(Object[] rowData) {
52: if (rowData.length != 8) {
53: System.err
54: .println("GeoLocQueryHandler.processRow() - expected 8 columns of data, "
55: + " got " + rowData.length);
56: }
57:
58: NewGeolocLocation geoloc = GLMFactory.newGeolocLocation();
59: geoloc.setName((String) rowData[1]);
60: geoloc.setGeolocCode((String) rowData[0]);
61: geoloc.setIcaoCode((String) rowData[3]);
62: geoloc.setInstallationTypeCode((String) rowData[2]);
63: geoloc.setLatitude(Latitude.newLatitude(((Number) rowData[4])
64: .doubleValue()));
65: geoloc.setLongitude(Longitude
66: .newLongitude(((Number) rowData[5]).doubleValue()));
67: geoloc.setCountryStateCode((String) rowData[6]);
68: geoloc.setCountryStateName((String) rowData[7]);
69:
70: myPlugin.updateLocation(geoloc);
71: }
72: }
|