001: //
002: /*
003: * <copyright>
004: *
005: * Copyright 1997-2004 BBNT Solutions, LLC
006: * under sponsorship of the Defense Advanced Research Projects
007: * Agency (DARPA).
008: *
009: * You can redistribute this software and/or modify it under the
010: * terms of the Cougaar Open Source License as published on the
011: * Cougaar Open Source Website (www.cougaar.org).
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: *
025: * </copyright>
026: */
027:
028: package org.cougaar.glm.xml.parser;
029:
030: import org.cougaar.glm.ldm.GLMFactory;
031: import org.cougaar.glm.ldm.plan.GeolocLocation;
032: import org.cougaar.glm.ldm.plan.NewGeolocLocation;
033: import org.cougaar.planning.ldm.LDMServesPlugin;
034: import org.cougaar.planning.ldm.measure.Latitude;
035: import org.cougaar.planning.ldm.measure.Longitude;
036: import org.w3c.dom.Node;
037: import org.w3c.dom.NodeList;
038:
039: /**
040: * Copyright (c) 1999 BBN Technologies
041: */
042: public class LocationParser {
043:
044: public GeolocLocation getLocation(LDMServesPlugin ldm, Node node) {
045: GLMFactory af = (GLMFactory) ldm.getFactory("glm");
046:
047: NodeList nlist = node.getChildNodes();
048: int nlength = nlist.getLength();
049: double latitude = Double.NaN;
050: double longitude = Double.NaN;
051: String geoloc = null;
052: String name = null;
053: String type = null;
054: String statecode = null;
055: String statename = null;
056:
057: for (int i = 0; i < nlength; i++) {
058: Node child = nlist.item(i);
059: String childname = child.getNodeName();
060:
061: if (child.getNodeType() == Node.ELEMENT_NODE) {
062:
063: if (childname.equals("geoloc")) {
064: Node data = child.getFirstChild();
065: geoloc = data.getNodeValue();
066: // System.out.println("LocationParser: geoloc = " + geoloc);
067: } else if (childname.equals("latitude")) {
068: Node data = child.getFirstChild();
069: Double d = new Double(data.getNodeValue());
070: latitude = d.doubleValue();
071: // System.out.println("LocationParser: latitude = " + latitude);
072: } else if (childname.equals("longitude")) {
073: Node data = child.getFirstChild();
074: Double d = new Double(data.getNodeValue());
075: longitude = d.doubleValue();
076: // System.out.println("LocationParser: longitude = " + longitude);
077: } else if (childname.equals("name")) {
078: Node data = child.getFirstChild();
079: name = data.getNodeValue();
080: // System.out.println("LocationParser: name = " + name);
081: } else if (childname.equals("type")) {
082: Node data = child.getFirstChild();
083: type = data.getNodeValue();
084: // System.out.println("LocationParser: type = " + type);
085: } else if (childname.equals("statecode")) {
086: Node data = child.getFirstChild();
087: statecode = data.getNodeValue();
088: // System.out.println("LocationParser: name = " + statecode);
089: } else if (childname.equals("statename")) {
090: Node data = child.getFirstChild();
091: statename = data.getNodeValue();
092: // System.out.println("LocationParser: name = " + statename);
093: }
094: }
095: }
096:
097: NewGeolocLocation loc = af.newGeolocLocation();
098: loc.setGeolocCode(geoloc);
099: loc.setLatitude(Latitude.newLatitude(latitude));
100: loc.setLongitude(Longitude.newLongitude(longitude));
101: loc.setName(name);
102: loc.setInstallationTypeCode(type);
103: loc.setCountryStateCode(statecode);
104: loc.setCountryStateName(statename);
105: return loc;
106: }
107: }
|