/** * Extracts all <Property/> key and values from the given DOM element * * @param config Parsed configuration document. */ protected void extractProperties(RasterServerConfiguration config) { foreach (Map.Entry <String, String> prop in config.getProperties().entrySet()) { this.setValue(prop.getKey(), prop.getValue()); } }
protected void init(Object o) { if (null == o) { String message = Logging.getMessage("nullValue.ObjectIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } // if (null == rootElement) // { // String message = Logging.getMessage("generic.UnexpectedObjectType", o.GetType().Name); // Logging.logger().severe(message); // throw new ArgumentException(message); // } // // String rootElementName = rootElement.getNodeName(); // if (!"RasterServer".Equals(rootElementName)) // { // String message = Logging.getMessage("generic.InvalidDataSource", rootElementName); // Logging.logger().severe(message); // throw new ArgumentException(message); // } RasterServerConfiguration config = new RasterServerConfiguration(o); try { config.parse(); } catch (XMLStreamException e) { String message = Logging.getMessage("generic.InvalidDataSource", ""); message += "\n" + e.getMessage(); Logging.logger().severe(message); throw new ArgumentException(message); } this.extractProperties(config); if (this.readRasterSources(config)) { // success, all raster sources are available String message = Logging.getMessage("generic.DataSetAvailable", this.getDataSetName()); Logging.logger().finest(message); } else { // some (or all) required source rasters are not available (either missing or unreadable) // and therefore the dataset may not generate high resolution on-the-fly String message = Logging.getMessage("generic.DataSetLimitedAvailability", this.getDataSetName()); Logging.logger().severe(message); } }
/** * Reads XML document and extracts raster sources * * @param config Parsed configuration document. * * @return TRUE, if all raster sources are available, FALSE otherwise * */ protected bool readRasterSources(RasterServerConfiguration config) { long startTime = System.currentTimeMillis(); bool hasUnavailableRasterSources = false; int numSources = 0; Sector extent = null; try { List <RasterServerConfiguration.Source> sources = config.getSources(); if (sources == null || sources.size() == 0) { return(false); } numSources = sources.size(); foreach (RasterServerConfiguration.Source source in sources) { Thread.yield(); try { String rasterSourcePath = source.getPath(); if (WWUtil.isEmpty(rasterSourcePath)) { continue; } AVList rasterMetadata = new AVListImpl(); File rasterSourceFile = new File(rasterSourcePath); // normalize rasterSourcePath = rasterSourceFile.getAbsolutePath(); if (!rasterSourceFile.exists()) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.FileDoesNotExists", rasterSourcePath); Logging.logger().warning(reason); continue; } if (!rasterSourceFile.canRead()) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.FileNoReadPermission", rasterSourcePath); Logging.logger().warning(reason); continue; } DataRasterReader rasterReader = this.findDataRasterReader(rasterSourceFile, rasterMetadata); if (null == rasterReader) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnknownFileFormatOrMatchingReaderNotFound", rasterSourcePath); Logging.logger().warning(reason); continue; } Sector sector = source.getSector(); if (null == sector) { rasterReader.readMetadata(rasterSourceFile, rasterMetadata); Object o = rasterMetadata.getValue(AVKey.SECTOR); sector = (o is Sector) ? (Sector)o : null; } else { rasterMetadata.setValue(AVKey.SECTOR, sector); } Object rasterPixelFormat = rasterMetadata.getValue(AVKey.PIXEL_FORMAT); String datasetPixelFormat = this.getDataSetPixelFormat(); if (!WWUtil.isEmpty(datasetPixelFormat)) { // verify all data rasters are the same type - we do not allow to mix elevations and imagery if (!datasetPixelFormat.Equals(rasterPixelFormat)) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnexpectedRasterType", rasterSourcePath); Logging.logger().warning(reason); continue; } } else { if (AVKey.IMAGE.Equals(rasterPixelFormat) || AVKey.ELEVATION.Equals(rasterPixelFormat)) { this.setDataSetPixelFormat((String)rasterPixelFormat); } else { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnknownFileFormat", rasterSourcePath); Logging.logger().warning(reason); continue; } } if (null != sector) { extent = Sector.union(extent, sector); this.dataRasterList.add( new CachedDataRaster(rasterSourceFile, rasterMetadata, rasterReader, this.getCache()) ); } else { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.NoSectorSpecified", rasterSourcePath); Logging.logger().warning(reason); } } catch (Throwable t) { String message = t.getMessage(); message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message; Logging.logger().log(java.util.logging.Level.WARNING, message, t); } } if (null != extent && extent.getDeltaLatDegrees() > 0d && extent.getDeltaLonDegrees() > 0d) { this.setValue(AVKey.SECTOR, extent); } } catch (Throwable t) { String message = t.getMessage(); message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message; Logging.logger().log(java.util.logging.Level.SEVERE, message, t); } finally { Logging.logger().finest(this.getStringValue(AVKey.DISPLAY_NAME) + ": " + numSources + " files in " + (System.currentTimeMillis() - startTime) + " milli-seconds"); } return(!hasUnavailableRasterSources); }