protected Header readHeaderFromBuffer(ByteBuffer buffer) throws WWRuntimeException {
    // Read file code - first byte
    int fileCode = buffer.get();
    if (fileCode > 5) {
      String message = Logging.getMessage("SHP.NotADBaseFile", file.getPath());
      Logging.logger().log(java.util.logging.Level.SEVERE, message);
      throw new WWRuntimeException(message);
    }

    // Last update date
    int yy = 0xFF & buffer.get(); // unsigned
    int mm = buffer.get();
    int dd = buffer.get();

    // Number of records
    int numRecords = buffer.getInt();

    // Header struct length
    int headerLength = buffer.getShort();

    // Record length
    int recordLength = buffer.getShort();

    // Assemble header
    Header header = new Header();
    header.fileCode = fileCode;
    Calendar cal = Calendar.getInstance();
    cal.set(1900 + yy, mm - 1, dd);
    header.lastModificationDate = cal.getTime();
    header.numberOfRecords = numRecords;
    header.headerLength = headerLength;
    header.recordLength = recordLength;

    return header;
  }
  public int countImagesInSector(Sector sector, int levelNumber) {
    if (sector == null) {
      String msg = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    Level targetLevel = this.levels.getLastLevel();
    if (levelNumber >= 0) {
      for (int i = levelNumber; i < this.getLevels().getLastLevel().getLevelNumber(); i++) {
        if (this.levels.isLevelEmpty(i)) continue;

        targetLevel = this.levels.getLevel(i);
        break;
      }
    }

    // Collect all the tiles intersecting the input sector.
    LatLon delta = targetLevel.getTileDelta();
    Angle latOrigin = this.levels.getTileOrigin().getLatitude();
    Angle lonOrigin = this.levels.getTileOrigin().getLongitude();
    final int nwRow = Tile.computeRow(delta.getLatitude(), sector.getMaxLatitude(), latOrigin);
    final int nwCol = Tile.computeColumn(delta.getLongitude(), sector.getMinLongitude(), lonOrigin);
    final int seRow = Tile.computeRow(delta.getLatitude(), sector.getMinLatitude(), latOrigin);
    final int seCol = Tile.computeColumn(delta.getLongitude(), sector.getMaxLongitude(), lonOrigin);

    int numRows = nwRow - seRow + 1;
    int numCols = seCol - nwCol + 1;

    return numRows * numCols;
  }
Example #3
0
  /**
   * Main Method
   *
   * @param args command line arguments
   */
  public static void main(String[] args) {
    // init logging
    try {
      Logging.init("lucane.log", "ALL");
    } catch (IOException ioe) {
      System.err.println("Unable to init logging, exiting.");
      System.exit(1);
    }

    Server server = null;
    ServerConfig config = null;

    try {
      config = new ServerConfig(CONFIG_FILE);
    } catch (Exception e) {
      Logging.getLogger().severe("Unable to read or parse the config file.");
      e.printStackTrace();
      System.exit(1);
    }

    // Server creation
    server = new Server(config);
    server.generateKeys();
    Logging.getLogger().info("Server is ready.");
    server.run();
  }
Example #4
0
  /**
   * Creates a new Server object.
   *
   * @param sqlDriver JDBC driver
   * @param dbURL JDBC connection url
   * @param dbLogin database login
   * @param dbPasswd database password
   */
  private Server(ServerConfig config) {
    Server.instance = this;
    this.connections = new ArrayList();
    this.services = new ArrayList();
    this.port = config.getPort();
    this.socket = null;
    this.dbLayer = null;

    try {
      dbLayer = DatabaseAbstractionLayer.createLayer(config);
      Logging.getLogger().finer("dbLayer   : " + dbLayer);

      this.store = new Store(config);
    } catch (Exception ex) {
      Logging.getLogger().severe("#Err > Unable to connect to the database : " + ex.getMessage());
      ex.printStackTrace();
      System.exit(1);
    }

    try {
      this.serverIp = InetAddress.getLocalHost().getHostAddress();
      this.socket = new ServerSocket(this.port);
    } catch (IOException e) {
      Logging.getLogger().severe("#Err > Unable to listen on the port " + port + ".");
      e.printStackTrace();
      System.exit(1);
    }

    loadInternalServices();
  }
  /**
   * Unzips the sole entry in the specified zip file, and saves it in a temporary directory, and
   * returns a File to the temporary location.
   *
   * @param path the path to the source file.
   * @param suffix the suffix to give the temp file.
   * @return a {@link File} for the temp file.
   * @throws IllegalArgumentException if the <code>path</code> is <code>null</code> or empty.
   */
  public static File unzipAndSaveToTempFile(String path, String suffix) {
    if (WWUtil.isEmpty(path)) {
      String message = Logging.getMessage("nullValue.PathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    InputStream stream = null;

    try {
      stream = WWIO.openStream(path);

      ByteBuffer buffer = WWIO.readStreamToBuffer(stream);
      File file = WWIO.saveBufferToTempFile(buffer, WWIO.getFilename(path));

      buffer = WWIO.readZipEntryToBuffer(file, null);
      return WWIO.saveBufferToTempFile(buffer, suffix);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      WWIO.closeStream(stream, path);
    }

    return null;
  }
  public static String getFeatureTypeName(String tableName) {
    if (tableName == null) {
      String message = Logging.getMessage("nullValue.StringIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    String suffix = WWIO.getSuffix(tableName);
    if (suffix == null) return null;

    suffix = "." + suffix;

    if (suffix.equalsIgnoreCase(VPFConstants.POINT_FEATURE_TABLE))
      return VPFConstants.POINT_FEATURE_TYPE;
    else if (suffix.equalsIgnoreCase(VPFConstants.LINE_FEATURE_TABLE))
      return VPFConstants.LINE_FEATURE_TYPE;
    else if (suffix.equalsIgnoreCase(VPFConstants.AREA_FEATURE_TABLE))
      return VPFConstants.AREA_FEATURE_TYPE;
    else if (suffix.equalsIgnoreCase(VPFConstants.TEXT_FEATURE_TABLE))
      return VPFConstants.TEXT_FEATURE_TYPE;
    else if (suffix.equalsIgnoreCase(VPFConstants.COMPLEX_FEATURE_TABLE))
      return VPFConstants.COMPLEX_FEATURE_TYPE;

    return null;
  }
  /**
   * Causes the View attached to the specified WorldWindow to animate to the specified sector. The
   * View starts animating at its current location and stops when the sector fills the window.
   *
   * @param wwd the WorldWindow who's View animates.
   * @param sector the sector to go to.
   * @throws IllegalArgumentException if either the <code>wwd</code> or the <code>sector</code> are
   *     <code>null</code>.
   */
  public static void goTo(WorldWindow wwd, Sector sector) {
    if (wwd == null) {
      String message = Logging.getMessage("nullValue.WorldWindow");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (sector == null) {
      String message = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Create a bounding box for the specified sector in order to estimate its size in model
    // coordinates.
    Box extent =
        Sector.computeBoundingBox(
            wwd.getModel().getGlobe(), wwd.getSceneController().getVerticalExaggeration(), sector);

    // Estimate the distance between the center position and the eye position that is necessary to
    // cause the sector to
    // fill a viewport with the specified field of view. Note that we change the distance between
    // the center and eye
    // position here, and leave the field of view constant.
    Angle fov = wwd.getView().getFieldOfView();
    double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle();

    // Configure OrbitView to look at the center of the sector from our estimated distance. This
    // causes OrbitView to
    // animate to the specified position over several seconds. To affect this change immediately use
    // the following:
    // ((OrbitView) wwd.getView()).setCenterPosition(new Position(sector.getCentroid(), 0d));
    // ((OrbitView) wwd.getView()).setZoom(zoom);
    wwd.getView().goTo(new Position(sector.getCentroid(), 0d), zoom);
  }
  /**
   * @param placeNameServiceSet the set of PlaceNameService objects that PlaceNameLayer will render.
   * @throws IllegalArgumentException if {@link
   *     gov.nasa.worldwind.layers.placename.PlaceNameServiceSet} is null
   */
  public PlaceNameLayer(PlaceNameServiceSet placeNameServiceSet) {
    if (placeNameServiceSet == null) {
      String message = Logging.getMessage("nullValue.PlaceNameServiceSetIsNull");
      Logging.logger().fine(message);
      throw new IllegalArgumentException(message);
    }

    //
    this.placeNameServiceSet = placeNameServiceSet.deepCopy();
    for (int i = 0; i < this.placeNameServiceSet.getServiceCount(); i++) {
      // todo do this for long as well and pick min
      int calc1 =
          (int)
              (PlaceNameService.TILING_SECTOR.getDeltaLatDegrees()
                  / this.placeNameServiceSet
                      .getService(i)
                      .getTileDelta()
                      .getLatitude()
                      .getDegrees());
      int numLevels = (int) Math.log(calc1);
      navTiles.add(
          new NavigationTile(
              this.placeNameServiceSet.getService(i),
              PlaceNameService.TILING_SECTOR,
              numLevels,
              "top"));
    }

    if (!WorldWind.getMemoryCacheSet().containsCache(Tile.class.getName())) {
      long size = Configuration.getLongValue(AVKey.PLACENAME_LAYER_CACHE_SIZE, 2000000L);
      MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size);
      cache.setName("Placename Tiles");
      WorldWind.getMemoryCacheSet().addCache(Tile.class.getName(), cache);
    }
  }
  protected boolean loadTile(Tile tile, java.net.URL url) {
    if (WWIO.isFileOutOfDate(url, this.placeNameServiceSet.getExpiryTime())) {
      // The file has expired. Delete it then request download of newer.
      this.getDataFileStore().removeFile(url);
      String message = Logging.getMessage("generic.DataFileExpired", url);
      Logging.logger().fine(message);
      return false;
    }

    PlaceNameChunk tileData;
    synchronized (this.fileLock) {
      tileData = readTileData(tile, url);
    }

    if (tileData == null) {
      // Assume that something's wrong with the file and delete it.
      this.getDataFileStore().removeFile(url);
      tile.getPlaceNameService()
          .markResourceAbsent(tile.getPlaceNameService().getTileNumber(tile.row, tile.column));
      String message = Logging.getMessage("generic.DeletedCorruptDataFile", url);
      Logging.logger().fine(message);
      return false;
    }

    tile.setDataChunk(tileData);
    WorldWind.getMemoryCache(Tile.class.getName()).add(tile.getFileCachePath(), tile);
    return true;
  }
Example #10
0
  protected void initializeTexture(DrawContext dc) {
    Texture iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
    if (iconTexture != null) return;

    try {
      InputStream iconStream = this.getClass().getResourceAsStream("/" + this.getIconFilePath());
      if (iconStream == null) {
        File iconFile = new File(this.iconFilePath);
        if (iconFile.exists()) {
          iconStream = new FileInputStream(iconFile);
        }
      }

      iconTexture = TextureIO.newTexture(iconStream, false, null);
      iconTexture.bind();
      this.iconWidth = iconTexture.getWidth();
      this.iconHeight = iconTexture.getHeight();
      dc.getTextureCache().put(this.getIconFilePath(), iconTexture);
    } catch (IOException e) {
      String msg = Logging.getMessage("layers.IOExceptionDuringInitialization");
      Logging.logger().severe(msg);
      throw new WWRuntimeException(msg, e);
    }

    GL gl = dc.getGL();
    gl.glTexParameteri(
        GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); // _MIPMAP_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    // Enable texture anisotropy, improves "tilted" world map quality.
    int[] maxAnisotropy = new int[1];
    gl.glGetIntegerv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy, 0);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy[0]);
  }
  /**
   * Resolves a reference to a local element identified by address and identifier, where {@code
   * linkBase} identifies a document, including the current document, and {@code linkRef} is the id
   * of the desired element.
   *
   * <p>If {@code linkBase} refers to a local COLLADA file and {@code linkRef} is non-null, the
   * return value is the element identified by {@code linkRef}. If {@code linkRef} is null, the
   * return value is a parsed {@link ColladaRoot} for the COLLADA file identified by {@code
   * linkBase}. Otherwise, {@code linkBase} is returned.
   *
   * @param linkBase the address of the document containing the requested element.
   * @param linkRef the element's identifier.
   * @return the requested element, or null if the element is not found.
   * @throws IllegalArgumentException if the address is null.
   */
  protected Object resolveLocalReference(String linkBase, String linkRef) {
    if (linkBase == null) {
      String message = Logging.getMessage("nullValue.DocumentSourceIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    try {
      File file = new File(linkBase);

      if (!file.exists()) return null;

      // Determine whether the file is a COLLADA document. If not, just return the file path.
      if (!WWIO.isContentType(file, ColladaConstants.COLLADA_MIME_TYPE))
        return file.toURI().toString();

      // Attempt to open and parse the COLLADA file.
      ColladaRoot refRoot = ColladaRoot.createAndParse(file);
      // An exception is thrown if parsing fails, so no need to check for null.

      // Add the parsed file to the session cache so it doesn't have to be parsed again.
      WorldWind.getSessionCache().put(linkBase, refRoot);

      // Now check the newly opened COLLADA file for the referenced item, if a reference was
      // specified.
      if (linkRef != null) return refRoot.getItemByID(linkRef);
      else return refRoot;
    } catch (Exception e) {
      String message =
          Logging.getMessage("generic.UnableToResolveReference", linkBase + "/" + linkRef);
      Logging.logger().warning(message);
      return null;
    }
  }
 static int computeColumn(Angle delta, Angle longitude) {
   if (delta == null || longitude == null) {
     String msg = Logging.getMessage("nullValue.AngleIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   return (int) ((longitude.getDegrees() + 180d) / delta.getDegrees());
 }
 static Angle computeColumnLongitude(int column, Angle delta) {
   if (delta == null) {
     String msg = Logging.getMessage("nullValue.AngleIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   return Angle.fromDegrees(-180 + delta.getDegrees() * column);
 }
Example #14
0
 public void setBackgroundColor(Color color) {
   if (color == null) {
     String msg = Logging.getMessage("nullValue.ColorIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   this.backColor = color;
 }
Example #15
0
 /**
  * Sets the relative viewport location to display the world map icon. Can be one of
  * AVKey.NORTHEAST, AVKey.NORTHWEST (the default), AVKey.SOUTHEAST, or SOUTHWEST. These indicate
  * the corner of the viewport to place the icon.
  *
  * @param position the desired world map position
  */
 public void setPosition(String position) {
   if (position == null) {
     String message = Logging.getMessage("nullValue.PositionIsNull");
     Logging.logger().severe(message);
     throw new IllegalArgumentException(message);
   }
   this.position = position;
 }
Example #16
0
 /**
  * Sets the world map icon's image location. The layer first searches for this location in the
  * current Java classpath. If not found then the specified path is assumed to refer to the local
  * file system. found there then the
  *
  * @param iconFilePath the path to the icon's image file
  */
 public void setIconFilePath(String iconFilePath) {
   if (iconFilePath == null || iconFilePath.length() == 0) {
     String message = Logging.getMessage("nullValue.FilePathIsNull");
     Logging.logger().severe(message);
     throw new IllegalArgumentException(message);
   }
   this.iconFilePath = iconFilePath;
 }
 static Angle computeRowLatitude(int row, Angle delta) {
   if (delta == null) {
     String msg = Logging.getMessage("nullValue.AngleIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   return Angle.fromDegrees(-90d + delta.getDegrees() * row);
 }
  public GeotiffWriter(File file) throws IOException {
    if (null == file) {
      String msg = Logging.getMessage("nullValue.FileIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    commonInitializer(file);
  }
 /** Closes the event stream associated with this context's XML event reader. */
 protected void closeEventStream() {
   try {
     this.eventStream.close();
     this.eventStream = null;
   } catch (IOException e) {
     String message = Logging.getMessage("generic.ExceptionClosingXmlEventReader");
     Logging.logger().warning(message);
   }
 }
  public void setOutlineWidth(double width) {
    if (width < 0) {
      String message = Logging.getMessage("generic.ArgumentOutOfRange", "width < 0");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.outlineWidth = width;
    this.updateModifiedTime();
  }
  public void setOutlineMaterial(Material material) {
    if (material == null) {
      String message = Logging.getMessage("nullValue.MaterialIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.outlineMaterial = material;
    this.updateModifiedTime();
  }
  public void setOutlineStippleFactor(int factor) {
    if (factor < 0) {
      String message = Logging.getMessage("generic.ArgumentOutOfRange", "factor < 0");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.outlineStippleFactor = factor;
    this.updateModifiedTime();
  }
  public GeotiffWriter(String filename) throws IOException {
    if (null == filename || 0 == filename.trim().length()) {
      String msg = Logging.getMessage("generic.FileNameIsMissing");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    // the initializer does the validity checking...
    commonInitializer(new File(filename));
  }
  public void setInteriorImageScale(double scale) {
    if (scale <= 0) {
      String message = Logging.getMessage("generic.ArgumentOutOfRange", "scale <= 0");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.interiorImageScale = scale;
    this.updateModifiedTime();
  }
 /**
  * @param that the task to compare
  * @return -1 if <code>this</code> less than <code>that</code>, 1 if greater than, 0 if equal
  * @throws IllegalArgumentException if <code>that</code> is null
  */
 public int compareTo(RequestTask that) {
   if (that == null) {
     String msg = Logging.getMessage("nullValue.RequestTaskIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   return this.tile.getPriority() == that.tile.getPriority()
       ? 0
       : this.tile.getPriority() < that.tile.getPriority() ? -1 : 1;
 }
  public void setOutlineOpacity(double opacity) {
    if (opacity < 0 || opacity > 1) {
      String message =
          Logging.getMessage("generic.ArgumentOutOfRange", "opacity < 0 or opacity > 1");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.outlineOpacity = opacity;
    this.updateModifiedTime();
  }
 public static final void openAll() {
   try {
     synchronized (ClientCatalog.class) {
       for (ClientCatalogItem catalogItem : getClientCatalog(null)) {
         Logging.info("OSS loads index " + catalogItem.getIndexName());
         getClient(catalogItem.getIndexName());
       }
     }
   } catch (SearchLibException e) {
     Logging.error(e);
   }
 }
  private void commonInitializer(File file) throws IOException {
    File parent = file.getParentFile();
    if (parent == null) parent = new File(System.getProperty("user.dir"));
    if (!parent.canWrite()) {
      String msg = Logging.getMessage("generic.FolderNoWritePermission", parent.getAbsolutePath());
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.targetFile = new RandomAccessFile(file, "rw");
    this.theChannel = this.targetFile.getChannel();
  }
  /**
   * Create a new <code>ColladaRoot</code> for a {@link ColladaDoc} instance. A ColladaDoc
   * represents COLLADA files from either files or input streams.
   *
   * @param docSource the ColladaDoc instance representing the COLLADA document.
   * @throws IllegalArgumentException if the document source is null.
   * @throws IOException if an error occurs while reading the COLLADA document.
   */
  public ColladaRoot(ColladaDoc docSource) throws IOException {
    super(ColladaConstants.COLLADA_NAMESPACE);

    if (docSource == null) {
      String message = Logging.getMessage("nullValue.DocumentSourceIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.colladaDoc = docSource;
    this.initialize();
  }
  /**
   * Returns the extent ("xmin", "ymin", "xmax", "ymax") for the specified row as a {@link
   * VPFBoundingBox}.
   *
   * @param record the record to extract the bound attributes from.
   * @return extent of the specified row.
   */
  public static VPFBoundingBox getExtent(VPFRecord record) {
    if (record == null) {
      String message = Logging.getMessage("nullValue.RecordIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    return new VPFBoundingBox(
        ((Number) record.getValue("xmin")).doubleValue(),
        ((Number) record.getValue("ymin")).doubleValue(),
        ((Number) record.getValue("xmax")).doubleValue(),
        ((Number) record.getValue("ymax")).doubleValue());
  }