@Override
 public void callback(DocumentClosure incomingClosure) {
   if (outputOneAtATime) incomingClosure.serialize(outputStream);
   else if (++currentResult >= documentCollection.size()) {
     System.out.println("\n\n");
     try {
       generateHtml();
     } catch (IllegalArgumentException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (SIMPLTranslationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (URISyntaxException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     semanticsSessionScope.getDownloadMonitors().stop(false);
   }
 }
 public static void main(String[] args) {
   SimplTypesScope.graphSwitch = GRAPH_SWITCH.ON;
   MetadataToHtmlTest test;
   try {
     test = new MetadataToHtmlTest();
     test.collect(args);
   } catch (SIMPLTranslationException e) {
     e.printStackTrace();
   }
 }
  /** @see ecologylab.oodss.messages.RequestMessage#performService(ecologylab.collections.Scope) */
  @Override
  public ResponseMessage performService(Scope objectRegistry) {
    GPSDatum gpsDatum = (GPSDatum) objectRegistry.get(EarthGPSSimulatorServer.GPS_DATUM);

    if (gpsDatum == null) gpsDatum = new GPSDatum();

    long lastTimePoint = (Long) objectRegistry.get(EarthGPSSimulatorServer.LAST_TIME_POINT);

    if (lastTimePoint != 0)
      gpsDatum.setGrndSpd(gpsDatum.distanceTo(lat, lon) / ((timePoint - lastTimePoint) / 1000.0));

    objectRegistry.put(EarthGPSSimulatorServer.LAST_TIME_POINT, timePoint);

    gpsDatum.setLat(lat);
    gpsDatum.setLon(lon);

    CompassDatum compassDatum =
        (CompassDatum) objectRegistry.get(EarthGPSSimulatorServer.COMPASS_DATUM);

    if (compassDatum == null) compassDatum = new CompassDatum();

    compassDatum.setHeading(heading);

    Kml currentLookPointKML = new Kml();
    Placemark currentLookPoint = new Placemark("location", "Current simulated GPS location.", null);
    currentLookPoint.setPoint(new Point(gpsDatum));

    try {
      debug(SimplTypesScope.serialize(currentLookPoint, StringFormat.XML));
    } catch (SIMPLTranslationException e) {
      e.printStackTrace();
    }

    currentLookPointKML.setPlacemark(currentLookPoint);

    KmlResponse resp = new KmlResponse(currentLookPointKML);

    debug("Ground speed: " + gpsDatum.getSpeed());

    return resp;
  }