Exemplo n.º 1
0
  @Override
  protected Layer doCreateFromCapabilities(OGCCapabilities caps, AVList params) {
    String serviceName = caps.getServiceInformation().getServiceName();
    if (serviceName == null
        || !(serviceName.equalsIgnoreCase(OGCConstants.WMS_SERVICE_NAME)
            || serviceName.equalsIgnoreCase("WMS"))) {
      String message =
          Logging.getMessage("WMS.NotWMSService", serviceName != null ? serviceName : "null");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (params == null) params = new AVListImpl();

    if (params.getStringValue(AVKey.LAYER_NAMES) == null) {
      // Use the first named layer since no other guidance given
      List<WMSLayerCapabilities> namedLayers = ((WMSCapabilities) caps).getNamedLayers();

      if (namedLayers == null || namedLayers.size() == 0 || namedLayers.get(0) == null) {
        String message = Logging.getMessage("WMS.NoLayersFound");
        Logging.logger().severe(message);
        throw new IllegalStateException(message);
      }

      params.setValue(AVKey.LAYER_NAMES, namedLayers.get(0).getName());
    }

    return new WMSTiledImageLayer((WMSCapabilities) caps, params);
  }
Exemplo n.º 2
0
  public void export(String mimeType, Object output)
      throws IOException, UnsupportedOperationException {
    if (mimeType == null) {
      String message = Logging.getMessage("nullValue.Format");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    if (KMLConstants.KML_MIME_TYPE.equalsIgnoreCase(mimeType)) {
      try {
        exportAsKML(output);
      } catch (XMLStreamException e) {
        Logging.logger().throwing(getClass().getName(), "export", e);
        throw new IOException(e);
      }
    } else {
      String message = Logging.getMessage("Export.UnsupportedFormat", mimeType);
      Logging.logger().warning(message);
      throw new UnsupportedOperationException(message);
    }
  }
Exemplo n.º 3
0
  public void makeOrderedRenderable(DrawContext dc, AirspaceRenderer renderer) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    for (Layer layer : this.layers) {
      if (!layer.isVisible()) continue;

      if (!layer.isAirspaceVisible(dc)) continue;

      // The layer is responsible for applying its own attributes, so we override its attributes
      // with our own just
      // before rendering.
      layer.setAttributes(this.getAttributes());

      // Create an ordered renderable that draws each layer, but specifies this Cake as the picked
      // object.
      OrderedRenderable or =
          renderer.createOrderedRenderable(dc, layer, layer.computeEyeDistance(dc), this);
      dc.addOrderedRenderable(or);
    }
  }
  /**
   * @param url the "file:" URL of the file to remove from the file store. Only files in the
   *     writable World Wind disk cache or temp file directory are removed by this method.
   * @throws IllegalArgumentException if <code>url</code> is null
   */
  @SuppressWarnings({"ResultOfMethodCallIgnored"})
  public void removeFile(java.net.URL url) {
    if (url == null) {
      String msg = Logging.getMessage("nullValue.URLIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    try {
      java.io.File file = new java.io.File(url.toURI());

      // This block of code must be synchronized for proper operation. A thread may check that the
      // file exists,
      // and become immediately suspended. A second thread may then delete that file. When the first
      // thread
      // wakes up, file.delete() fails.
      synchronized (this.fileLock) {
        if (file.exists()) {
          // Don't remove files outside the cache or temp directory.
          String parent = file.getParent();
          if (!(parent.startsWith(this.getWriteLocation().getPath())
              || parent.startsWith(Configuration.getSystemTempDirectory()))) return;

          file.delete();
        }
      }
    } catch (java.net.URISyntaxException e) {
      Logging.logger()
          .log(
              Level.SEVERE,
              Logging.getMessage("FileStore.ExceptionRemovingFile", url.toString()),
              e);
    }
  }
  /**
   * 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;
    }
  }
  public int computeLevelForResolution(Sector sector, Globe globe, double resolution) {
    if (sector == null) {
      String message = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(message);
      throw new IllegalStateException(message);
    }

    if (globe == null) {
      String message = Logging.getMessage("nullValue.GlobeIsNull");
      Logging.logger().severe(message);
      throw new IllegalStateException(message);
    }

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

      texelSize = this.levels.getLevel(i).getTexelSize();
      if (texelSize > resolution) continue;

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

    Logging.logger()
        .info(
            Logging.getMessage(
                "layers.TiledImageLayer.LevelSelection", targetLevel.getLevelNumber(), texelSize));
    return targetLevel.getLevelNumber();
  }
  protected static AVList wmsGetParamsFromCapsDoc(Capabilities caps, AVList params) {
    if (caps == null) {
      String message = Logging.getMessage("nullValue.WMSCapabilities");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    try {
      DataConfigurationUtils.getWMSLayerParams(caps, formatOrderPreference, params);
    } catch (IllegalArgumentException e) {
      String message = Logging.getMessage("WMS.MissingLayerParameters");
      Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
      throw new IllegalArgumentException(message, e);
    } catch (WWRuntimeException e) {
      String message = Logging.getMessage("WMS.MissingCapabilityValues");
      Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
      throw new IllegalArgumentException(message, e);
    }

    setFallbacks(params);

    // Setup WMS URL builder.
    params.setValue(AVKey.WMS_VERSION, caps.getVersion());
    params.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder(params));
    // Setup default WMS tiled image layer behaviors.
    params.setValue(AVKey.USE_TRANSPARENT_TEXTURES, true);

    return params;
  }
  /**
   * Appends elevation model parameters as elements to a specified context. If a parameter key
   * exists, that parameter is appended to the context. Supported key and element paths are:
   *
   * <table> <th><td>Key</td><td>Name</td><td>Type</td></th>
   * <tr><td>{@link AVKey#DISPLAY_NAME}</td><td>DisplayName</td><td>String</td></tr> <tr><td>{@link
   * AVKey#NETWORK_RETRIEVAL_ENABLED}</td><td>NetworkRetrievalEnabled</td><td>Boolean</td></tr> <tr><td>{@link
   * AVKey#MISSING_DATA_SIGNAL}</td><td>MissingData/@signal</td><td>Double</td></tr> <tr><td>{@link
   * AVKey#MISSING_DATA_REPLACEMENT}</td><td>MissingData/@replacement</td><td>Double</td></tr> <tr><td>{@link
   * AVKey#DETAIL_HINT}</td><td>DataDetailHint</td><td>Double</td></tr> </table>
   *
   * @param params the key-value pairs which define the elevation model parameters.
   * @param context the XML document root on which to append parameter elements.
   * @return a reference to context.
   * @throws IllegalArgumentException if either the parameters or the context are null.
   */
  public static Element createElevationModelElements(AVList params, Element context) {
    if (params == null) {
      String message = Logging.getMessage("nullValue.ParametersIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    WWXML.checkAndAppendTextElement(params, AVKey.DISPLAY_NAME, context, "DisplayName");
    WWXML.checkAndAppendBooleanElement(
        params, AVKey.NETWORK_RETRIEVAL_ENABLED, context, "NetworkRetrievalEnabled");

    if (params.getValue(AVKey.MISSING_DATA_SIGNAL) != null
        || params.getValue(AVKey.MISSING_DATA_REPLACEMENT) != null) {
      Element el = WWXML.getElement(context, "MissingData", null);
      if (el == null) el = WWXML.appendElementPath(context, "MissingData");

      Double d = AVListImpl.getDoubleValue(params, AVKey.MISSING_DATA_SIGNAL);
      if (d != null) el.setAttribute("signal", Double.toString(d));

      d = AVListImpl.getDoubleValue(params, AVKey.MISSING_DATA_REPLACEMENT);
      if (d != null) el.setAttribute("replacement", Double.toString(d));
    }

    WWXML.checkAndAppendDoubleElement(params, AVKey.DETAIL_HINT, context, "DataDetailHint");

    return context;
  }
  /**
   * @param fileName the name to give the newly created file
   * @return a handle to the newly created file if it could be created and added to the file store,
   *     otherwise null
   * @throws IllegalArgumentException if <code>fileName</code> is null
   */
  public java.io.File newFile(String fileName) {
    if (fileName == null) {
      String message = Logging.getMessage("nullValue.FilePathIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (this.writeLocation != null) {
      String fullPath = makeAbsolutePath(this.writeLocation.getFile(), fileName);
      java.io.File file = new java.io.File(fullPath);
      boolean canCreateFile = false;

      // This block of code must be synchronized for proper operation. A thread may check that
      // file.getParentFile() does not exist, and become immediately suspended. A second thread may
      // then create
      // the parent and ancestor directories. When the first thread wakes up,
      // file.getParentFile().mkdirs()
      // fails, resulting in an erroneous log message: The log reports that the file cannot be
      // created.
      synchronized (this.fileLock) {
        if (file.getParentFile().exists()) canCreateFile = true;
        else if (file.getParentFile().mkdirs()) canCreateFile = true;
      }

      if (canCreateFile) return file;
      else {
        String msg = Logging.getMessage("generic.CannotCreateFile", fullPath);
        Logging.logger().severe(msg);
      }
    }

    return null;
  }
Exemplo n.º 10
0
  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;
  }
Exemplo n.º 11
0
  /**
   * Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to
   * set starts with the vector at the specified position, and has size equal to the specified
   * buffer's size. The specified buffer must have the same logical vector size as this buffer
   * (coordsPerVec must be equivalent).
   *
   * @param position the starting vector position to set.
   * @param buffer the input buffer.
   * @throws IllegalArgumentException if the position is out of range, if the buffer is null or
   *     incompatible, or if this buffer has insufficient length to store the sub-buffer at the
   *     specified position.
   */
  public void putSubBuffer(int position, VecBuffer buffer) {
    if (position < 0 || position >= this.getSize()) {
      String message =
          Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    // Buffer is incompatible.
    if (this.coordsPerVec != buffer.coordsPerVec) {
      String message = Logging.getMessage("generic.BufferIncompatible", buffer);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Buffer is too large.
    int sizeNeeded = position + buffer.getSize();
    if (this.getSize() < sizeNeeded) {
      String message = Logging.getMessage("generic.BufferOverflow", this.getSize(), sizeNeeded);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    int index = this.indexFromVectorPosition(position);
    this.buffer.putSubBuffer(index, buffer.getBufferWrapper());
  }
Exemplo n.º 12
0
  /**
   * Sets the vector elements starting at the specified position, and ending at the specified
   * position + count. The position is a logical vector position, position n corresponds to the
   * buffer's nth vector. The array must have sufficient length to represent count separate logical
   * vectors (each with size equal to coordsPerVec) tightly packed into the array, starting at index
   * 0.
   *
   * @param position the starting logical vector position.
   * @param array the source array.
   * @param count the number of logical arrays to set.
   * @throws IllegalArgumentException if the position is out of range, if the array is null, or if
   *     the array has insufficient length.
   */
  public void putAll(int position, double[] array, int count) {
    if (position < 0 || position + count > this.getSize()) {
      String message =
          Logging.getMessage(
              "generic.ArgumentOutOfRange", "position < 0 or position + count >= size");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    int index = this.indexFromVectorPosition(position);
    int length = this.indexFromVectorPosition(count);

    if (array.length < length) {
      String message = Logging.getMessage("generic.ArrayInvalidLength", array.length);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.buffer.putDouble(index, array, 0, length);
  }
Exemplo n.º 13
0
  protected String validateMetadata(Object source, AVList params) {
    StringBuilder sb = new StringBuilder();

    String message = super.validateMetadata(source, params);
    if (message != null) sb.append(message);

    Object o = (params != null) ? params.getValue(AVKey.BYTE_ORDER) : null;
    if (o == null || !(o instanceof String))
      sb.append(sb.length() > 0 ? ", " : "")
          .append(Logging.getMessage("WorldFile.NoByteOrderSpecified", source));

    o = (params != null) ? params.getValue(AVKey.PIXEL_FORMAT) : null;
    if (o == null) {
      sb.append(sb.length() > 0 ? ", " : "")
          .append(Logging.getMessage("WorldFile.NoPixelFormatSpecified", source));
    } else if (!AVKey.ELEVATION.equals(o)) {
      sb.append(sb.length() > 0 ? ", " : "")
          .append(Logging.getMessage("WorldFile.InvalidPixelFormat", source));
    }

    o = (params != null) ? params.getValue(AVKey.PIXEL_TYPE) : null;
    if (o == null) {
      o = (params != null) ? params.getValue(AVKey.DATA_TYPE) : null;
      if (o == null) {
        sb.append(sb.length() > 0 ? ", " : "")
            .append(Logging.getMessage("WorldFile.NoPixelTypeSpecified", source));
      }
    }

    if (sb.length() == 0) return null;

    return sb.toString();
  }
Exemplo n.º 14
0
  public void write(DataRaster raster) throws IOException, IllegalArgumentException {
    if (null == raster) {
      String msg = Logging.getMessage("nullValue.RasterIsNull");
      Logging.logger().finest(msg);
      throw new IllegalArgumentException(msg);
    }

    if (!(raster.getWidth() > 0)) {
      String msg = Logging.getMessage("generic.InvalidWidth", raster.getWidth());
      Logging.logger().finest(msg);
      throw new IllegalArgumentException(msg);
    }

    if (!(raster.getHeight() > 0)) {
      String msg = Logging.getMessage("generic.InvalidHeight", raster.getHeight());
      Logging.logger().finest(msg);
      throw new IllegalArgumentException(msg);
    }

    if (raster instanceof BufferedImageRaster) {
      this.write(((BufferedImageRaster) raster).getBufferedImage(), raster);
    } else if (raster instanceof BufferWrapperRaster) {
      this.writeRaster((BufferWrapperRaster) raster);
    }
  }
Exemplo n.º 15
0
  /**
   * Sets the vector element at the specified position, as a geographic Position. This buffer's
   * logical vector size must be at least 2.
   *
   * @param position the logical vector position.
   * @param p the geographic Position to set.
   * @throws IllegalArgumentException if the position is out of range, if the Position is null, or
   *     if this buffer cannot store a Position.
   */
  public void putPosition(int position, Position p) {
    if (position < 0 || position >= this.getSize()) {
      String message =
          Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

    if (this.coordsPerVec < 2) {
      String message = Logging.getMessage("generic.BufferIncompatible", this);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    double[] compArray = new double[3];
    compArray[1] = p.getLatitude().degrees;
    compArray[0] = p.getLongitude().degrees;
    compArray[2] = p.getElevation();

    this.put(position, compArray);
  }
  /**
   * Create an instance.
   *
   * @param tc the current {@link KMLTraversalContext}.
   * @param placemark the <i>Placemark</i> element containing the <i>Point</i>.
   * @param geom the {@link gov.nasa.worldwind.ogc.kml.KMLPoint} geometry.
   * @throws NullPointerException if the geometry is null.
   * @throws IllegalArgumentException if the parent placemark or the traversal context is null.
   */
  public KMLModelPlacemarkImpl(
      KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) {
    if (tc == null) {
      String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (placemark == null) {
      String msg = Logging.getMessage("nullValue.ParentIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (geom == null) {
      String msg = Logging.getMessage("nullValue.GeometryIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.model = (KMLModel) geom;
    this.parent = placemark;

    this.resourceMap = this.createResourceMap(this.model);
  }
Exemplo n.º 17
0
  public static void checkAndSetValue(
      VPFRecord record, String paramName, String paramKey, AVList params) {
    if (record == null) {
      String message = Logging.getMessage("nullValue.RecordIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

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

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

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

    if (record.hasValue(paramName)) {
      Object o = record.getValue(paramName);
      if (o != null) params.setValue(paramKey, o);
    }
  }
Exemplo n.º 18
0
  /**
   * 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);
  }
  @SuppressWarnings({"ResultOfMethodCallIgnored"})
  protected void buildWritePaths(org.w3c.dom.Node dataFileCacheNode) {
    javax.xml.xpath.XPathFactory pathFactory = javax.xml.xpath.XPathFactory.newInstance();
    javax.xml.xpath.XPath pathFinder = pathFactory.newXPath();

    try {
      org.w3c.dom.NodeList locationNodes =
          (org.w3c.dom.NodeList)
              pathFinder.evaluate(
                  "/dataFileStore/writeLocations/location",
                  dataFileCacheNode.getFirstChild(),
                  javax.xml.xpath.XPathConstants.NODESET);
      for (int i = 0; i < locationNodes.getLength(); i++) {
        org.w3c.dom.Node location = locationNodes.item(i);
        String prop = pathFinder.evaluate("@property", location);
        String wwDir = pathFinder.evaluate("@wwDir", location);
        String append = pathFinder.evaluate("@append", location);
        String create = pathFinder.evaluate("@create", location);

        String path = buildLocationPath(prop, append, wwDir);
        if (path == null) {
          Logging.logger()
              .log(
                  Level.WARNING,
                  "FileStore.LocationInvalid",
                  prop != null ? prop : Logging.getMessage("generic.Unknown"));
          continue;
        }

        Logging.logger().log(Level.FINER, "FileStore.AttemptingWriteDir", path);
        java.io.File pathFile = new java.io.File(path);
        if (!pathFile.exists()
            && create != null
            && (create.contains("t") || create.contains("T"))) {
          Logging.logger().log(Level.FINER, "FileStore.MakingDirsFor", path);
          pathFile.mkdirs();
        }

        if (pathFile.isDirectory() && pathFile.canWrite() && pathFile.canRead()) {
          Logging.logger().log(Level.FINER, "FileStore.WriteLocationSuccessful", path);
          this.writeLocation = new StoreLocation(pathFile);

          // Remove the writable location from search path if it already exists.
          StoreLocation oldLocation = this.storeLocationFor(path);
          if (oldLocation != null) this.readLocations.remove(oldLocation);

          // Writable location is always first in search path.
          this.readLocations.add(0, this.writeLocation);

          break; // only need one
        }
      }
    } catch (javax.xml.xpath.XPathExpressionException e) {
      String message = Logging.getMessage("FileStore.ExceptionReadingConfigurationFile");
      Logging.logger().severe(message);
      throw new IllegalStateException(message, e);
    }
  }
Exemplo n.º 20
0
  /**
   * Computes a <code>Box</code> that bounds a specified buffer of points. Principal axes are
   * computed for the points and used to form a <code>Box</code>. This returns <code>null</code> if
   * the buffer is empty or contains only a partial point.
   *
   * <p>The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by
   * the specified stride. The stride specifies the number of buffer elements between the first
   * coordinate of consecutive tuples. For example, a stride of 3 specifies that each tuple is
   * tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies that there are two elements
   * between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride must be at
   * least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores
   * the remaining elements that follow the last complete tuple.
   *
   * @param buffer the buffer containing the point coordinates for which to compute a bounding
   *     volume.
   * @param stride the number of elements between the first coordinate of consecutive points. If
   *     stride is 3, this interprets the buffer has having tightly packed XYZ coordinate tuples.
   * @return the bounding volume, with axes lengths consistent with the conventions described in the
   *     <code>Box</code> class overview.
   * @throws IllegalArgumentException if the buffer is null or empty, or if the stride is less than
   *     three.
   */
  public static Box computeBoundingBox(FloatBuffer buffer, int stride) {
    if (buffer == null) {
      String msg = Logging.getMessage("nullValue.BufferIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    if (stride < 3) {
      String msg = Logging.getMessage("generic.StrideIsInvalid", stride);
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4[] axes = WWMath.computePrincipalAxes(buffer, stride);
    if (axes == null) {
      String msg = Logging.getMessage("generic.BufferIsEmpty");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4 r = axes[0];
    Vec4 s = axes[1];
    Vec4 t = axes[2];

    // Find the extremes along each axis.
    double minDotR = Double.MAX_VALUE;
    double maxDotR = -minDotR;
    double minDotS = Double.MAX_VALUE;
    double maxDotS = -minDotS;
    double minDotT = Double.MAX_VALUE;
    double maxDotT = -minDotT;

    for (int i = buffer.position(); i <= buffer.limit() - stride; i += stride) {
      double x = buffer.get(i);
      double y = buffer.get(i + 1);
      double z = buffer.get(i + 2);

      double pdr = x * r.x + y * r.y + z * r.z;
      if (pdr < minDotR) minDotR = pdr;
      if (pdr > maxDotR) maxDotR = pdr;

      double pds = x * s.x + y * s.y + z * s.z;
      if (pds < minDotS) minDotS = pds;
      if (pds > maxDotS) maxDotS = pds;

      double pdt = x * t.x + y * t.y + z * t.z;
      if (pdt < minDotT) minDotT = pdt;
      if (pdt > maxDotT) maxDotT = pdt;
    }

    if (maxDotR == minDotR) maxDotR = minDotR + 1;
    if (maxDotS == minDotS) maxDotS = minDotS + 1;
    if (maxDotT == minDotT) maxDotT = minDotT + 1;

    return new Box(axes, minDotR, maxDotR, minDotS, maxDotS, minDotT, maxDotT);
  }
Exemplo n.º 21
0
  /**
   * Create an instance.
   *
   * @param tc the current {@link KMLTraversalContext}.
   * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>.
   * @param geom the {@link gov.nasa.worldwind.ogc.kml.KMLPolygon} geometry.
   * @throws NullPointerException if the geometry is null.
   * @throws IllegalArgumentException if the parent placemark or the traversal context is null.
   */
  public KMLSurfacePolygonImpl(
      KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) {
    if (tc == null) {
      String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (placemark == null) {
      String msg = Logging.getMessage("nullValue.ParentIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.parent = placemark;

    KMLPolygon polygon = (KMLPolygon) geom;

    // KMLPolygon's use linear interpolation between corners by definition. Configure the World Wind
    // SurfacePolygon
    // to use the appropriate path type for linear interpolation in geographic coordinates.
    this.setPathType(AVKey.LINEAR);

    // Note: SurfacePolygon implies altitude mode "clampToGround", therefore KMLSurfacePolygonImpl
    // ignores the
    // KMLPolygon's altitude mode property.

    KMLLinearRing outerBoundary = polygon.getOuterBoundary();
    if (outerBoundary != null) {
      Position.PositionList coords = outerBoundary.getCoordinates();
      if (coords != null && coords.list != null)
        this.setOuterBoundary(outerBoundary.getCoordinates().list);
    }

    Iterable<? extends KMLLinearRing> innerBoundaries = polygon.getInnerBoundaries();
    if (innerBoundaries != null) {
      for (KMLLinearRing ring : innerBoundaries) {
        Position.PositionList coords = ring.getCoordinates();
        if (coords != null && coords.list != null)
          this.addInnerBoundary(ring.getCoordinates().list);
      }
    }

    if (placemark.getName() != null) this.setValue(AVKey.DISPLAY_NAME, placemark.getName());

    if (placemark.getDescription() != null)
      this.setValue(AVKey.DESCRIPTION, placemark.getDescription());

    if (placemark.getSnippetText() != null)
      this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText());

    this.setValue(AVKey.CONTEXT, this.parent);
  }
  /**
   * Create a new WebView.
   *
   * @param frameSize The size of the WebView rectangle.
   * @throws UnsupportedOperationException if this class is instantiated on a non-Windows operating
   *     system.
   * @throws WWRuntimeException if creating the native web browser window fails for any reason. For
   *     example, because the process has run out of User Object handles (see documentation <a
   *     href="#limits">above</a>).
   */
  public WindowsWebView(Dimension frameSize) {
    if (frameSize == null) {
      String message = Logging.getMessage("nullValue.SizeIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (!Configuration.isWindowsOS()) {
      String message =
          Logging.getMessage(
              "NativeLib.UnsupportedOperatingSystem",
              "Windows WebView",
              System.getProperty("os.name"));
      Logging.logger().severe(message);
      throw new UnsupportedOperationException(message);
    }

    this.frameSize = frameSize;

    try {
      // Increment the instance counter
      instances.incrementAndGet();

      // Make sure that the message loop thread is running
      this.ensureMessageLoopRunning();

      // Create the web view
      this.webViewWindowPtr = WindowsWebViewJNI.newWebViewWindow(webViewMessageLoop);
      if (this.webViewWindowPtr == 0) {
        String message = Logging.getMessage("WebView.NativeExceptionInitializingWebView");
        Logging.logger().severe(message);
        throw new WWRuntimeException(message);
      }

      WindowsWebViewJNI.setFrameSize(
          this.webViewWindowPtr, this.frameSize.width, this.frameSize.height);

      this.observerPtr = WindowsWebViewJNI.newNotificationAdapter(this);

      WindowsWebViewJNI.addWindowUpdateObserver(this.webViewWindowPtr, observerPtr);
    } catch (RuntimeException e) {
      // If the WebView was not created successfully do not increment the instance counter.
      instances.decrementAndGet();
      this.handleWebViewCreationError();
      throw e;
    } catch (Error e) {
      // If the WebView was not created successfully do not increment the instance counter.
      instances.decrementAndGet();
      this.handleWebViewCreationError();
      throw e;
    }
  }
Exemplo n.º 23
0
  /**
   * Verifies that the record's shape type matches the expected one, typically that of the
   * shapefile. All non-null records in a Shapefile must be of the same type. Throws an exception if
   * the types do not match and the shape type is not <code>{@link Shapefile#SHAPE_NULL}</code>.
   * Records of type <code>SHAPE_NULL</code> are always valid, and may appear in any Shapefile.
   *
   * <p>For details, see the ESRI Shapefile specification at <a
   * href="http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf"/>, pages 4 and 5.
   *
   * @param shapefile the shapefile.
   * @param shapeType the record's shape type.
   * @throws WWRuntimeException if the shape types do not match.
   * @throws IllegalArgumentException if the specified shape type is null.
   */
  protected void validateShapeType(Shapefile shapefile, String shapeType) {
    if (shapeType == null) {
      String message = Logging.getMessage("nullValue.ShapeType");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (!shapeType.equals(shapefile.getShapeType()) && !shapeType.equals(Shapefile.SHAPE_NULL)) {
      String message = Logging.getMessage("SHP.UnsupportedShapeType", shapeType);
      Logging.logger().severe(message);
      throw new WWRuntimeException(message);
    }
  }
Exemplo n.º 24
0
 public synchronized String getStringValue(String key) {
   if (key == null) {
     String msg = Logging.getMessage("nullValue.AttributeKeyIsNull");
     Logging.logger().severe(msg);
     throw new IllegalStateException(msg);
   }
   try {
     return (String) this.getValue(key);
   } catch (ClassCastException e) {
     String msg = Logging.getMessage("AVAAccessibleImpl.AttributeValueForKeyIsNotAString", key);
     Logging.logger().severe(msg);
     throw new WWRuntimeException(msg, e);
   }
 }
  public static VirtualEarthTile[] createTiles(
      Sector bbox /*int wwLevel, int wwRow, int wwCol*/, VirtualEarthLayer layer)
      throws WWRuntimeException {
    if (null == bbox) {
      String message = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(message);
      throw new WWRuntimeException(message);
    }

    if (null == layer) {
      String message = Logging.getMessage("nullValue.LayerIsNull");
      Logging.logger().severe(message);
      throw new WWRuntimeException(message);
    }

    int level = getZoomLevelByTrueViewRange(bbox.getDeltaLatDegrees());

    Point startPixel =
        LatLongToPixelXY(bbox.getMaxLatitude().degrees, bbox.getMinLongitude().degrees, level);
    Point endPixel =
        LatLongToPixelXY(bbox.getMinLatitude().degrees, bbox.getMaxLongitude().degrees, level);

    Point startTile = PixelXYToTileXY(startPixel.x, startPixel.y);
    Point endTile = PixelXYToTileXY(endPixel.x, endPixel.y);

    ArrayList<VirtualEarthTile> tileList = new ArrayList<VirtualEarthTile>();

    for (int y = startTile.y; y <= endTile.y; y++) {
      for (int x = startTile.x; x <= endTile.x; x++) {
        try {
          int ulPixelX = x * VE_MAX_TILE_SIZE;
          int ulPixelY = y * VE_MAX_TILE_SIZE;
          LatLon ul = PixelXYToLatLong(ulPixelX, ulPixelY, level);

          int lrPixelX = ulPixelX + VE_MAX_TILE_SIZE;
          int lrPixelY = ulPixelY + VE_MAX_TILE_SIZE;
          LatLon lr = PixelXYToLatLong(lrPixelX, lrPixelY, level);

          Sector tileSector = Sector.boundingSector(ul, lr);

          tileList.add(new VirtualEarthTile(x, y, level, layer, tileSector));
        } catch (Exception ex) {
          Logging.logger().log(Level.SEVERE, ex.getMessage(), ex);
        }
      }
    }

    VirtualEarthTile[] tiles = new VirtualEarthTile[tileList.size()];
    return tileList.toArray(tiles);
  }
Exemplo n.º 26
0
  public void drawOnTo(DataRaster canvas) {
    if (canvas == null) {
      String message = Logging.getMessage("nullValue.DestinationIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
    if (!(canvas instanceof BufferedImageRaster)) {
      String message = Logging.getMessage("DataRaster.IncompatibleRaster", canvas);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.doDrawOnTo((BufferedImageRaster) canvas);
  }
Exemplo n.º 27
0
 public synchronized void removePropertyChangeListener(
     String propertyName, java.beans.PropertyChangeListener listener) {
   if (propertyName == null) {
     String msg = Logging.getMessage("nullValue.PropertyNameIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   if (listener == null) {
     String msg = Logging.getMessage("nullValue.ListenerIsNull");
     Logging.logger().severe(msg);
     throw new IllegalArgumentException(msg);
   }
   this.getChangeSupport().removePropertyChangeListener(propertyName, listener);
 }
Exemplo n.º 28
0
  /**
   * Set the format of a specified value type. See {@link #setDefaultFormats()} for a description
   * and examples of formats.
   *
   * @param formatName a key identifying the value type that is to have the specified format.
   *     Available types are those indicated by the "FORMAT_" constants defined by this class or by
   *     its subclasses
   * @param format the label to use for the specified value type.
   * @throws IllegalArgumentException if either the format or format name are null.
   */
  public void setFormat(String formatName, String format) {
    if (formatName == null) {
      String msg = Logging.getMessage("nullValue.FormatKey");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (format == null) {
      String msg = Logging.getMessage("nullValue.Format");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.setValue(formatName, format);
  }
Exemplo n.º 29
0
  /**
   * Set the label of a specified value type. See {@link #setDefaultLabels()} for a description and
   * examples of labels.
   *
   * @param labelName a key identifying the label type. Available names are those indicated by the
   *     "LABEL_" constants defined by this class or by its subclasses
   * @param label the label to use for the specified value type.
   * @throws IllegalArgumentException if either the label or label name is null.
   */
  public void setLabel(String labelName, String label) {
    if (labelName == null) {
      String msg = Logging.getMessage("nullValue.LabelKey");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (label == null) {
      String msg = Logging.getMessage("nullValue.Label");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.setValue(labelName, label);
  }
    public void run() {
      if (Thread.currentThread().isInterrupted())
        return; // the task was cancelled because it's a duplicate or for some other reason

      try {
        this.placemark.retrieveModel(this.address);
      } catch (IOException e) {
        String message = Logging.getMessage("generic.ExceptionWhileReading", e.getMessage());
        Logging.logger().warning(message);
      } catch (XMLStreamException e) {
        String message =
            Logging.getMessage("generic.ExceptionAttemptingToParseXml", e.getMessage());
        Logging.logger().warning(message);
      }
    }