📄 wwdotnetlayersetinstaller.java
字号:
/* Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.data;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.formats.dds.*;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.util.WWIO;
// TODO: support for LayerSet.xsd format nested descriptors
/**
* @author dcollins
* @version $Id: WWDotNetLayerSetInstaller.java 8941 2009-02-21 00:33:27Z dcollins $
*/
public class WWDotNetLayerSetInstaller extends AbstractDataStoreProducer
{
static class ProductionState
{
// Production parameters.
AVList productionParams;
// Progress counters.
int numSources;
int curSource;
int[] numSourceFiles;
int[] numInstalledFiles;
}
public WWDotNetLayerSetInstaller()
{
}
public String getDataSourceDescription()
{
StringBuilder sb = new StringBuilder();
sb.append(Logging.getMessage("DataStoreProducer.WWDotNetLayerSet.Description"));
DataDescriptorReader reader = new WWDotNetLayerSetReader();
String suffix = WWIO.makeSuffixForMimeType(reader.getMimeType());
sb.append(" (").append("*").append(suffix).append(")");
return sb.toString();
}
protected void doStartProduction(AVList parameters) throws Exception
{
this.getProductionResultsList().clear();
Iterable<DataSource> dataSources = this.getDataSourceList();
ProductionState productionState = new ProductionState();
// Initialize any missing production parameters with suitable defaults.
this.initProductionParameters(parameters, productionState);
// Set the progress parameters for the current data sources.
this.setProgressParameters(dataSources, productionState);
for (DataSource source : dataSources)
{
productionState.curSource++;
this.install(source, productionState);
}
}
protected void initProductionParameters(AVList parameters, ProductionState productionState)
{
Object o = parameters.getValue(AVKey.MIME_TYPE);
if (o == null || !(o instanceof String))
parameters.setValue(AVKey.MIME_TYPE, "image/dds");
productionState.productionParams = parameters;
}
protected String validateProductionParameters(AVList parameters)
{
StringBuilder sb = new StringBuilder();
Object o = parameters.getValue(AVKey.FILE_STORE_LOCATION);
if (o == null || !(o instanceof String) || ((String) o).length() < 1)
sb.append((sb.length() > 0 ? ", " : "")).append(Logging.getMessage("term.fileStoreLocation"));
o = parameters.getValue(AVKey.DATA_CACHE_NAME);
// It's okay if the cache path is empty, but if specified it must be a String.
if (o != null && !(o instanceof String))
sb.append((sb.length() > 0 ? ", " : "")).append(Logging.getMessage("term.fileStoreFolder"));
if (sb.length() == 0)
return null;
return Logging.getMessage("DataStoreProducer.InvalidDataStoreParamters", sb.toString());
}
protected String validateDataSource(DataSource dataSource)
{
StringBuilder sb = new StringBuilder();
if (dataSource.getSource() instanceof DataDescriptor)
{
DataDescriptor dataDescriptor = (DataDescriptor) dataSource.getSource();
if (!dataDescriptor.hasKey(AVKey.WORLD_WIND_DOT_NET_LAYER_SET))
sb.append((sb.length() > 0 ? ", " : "")).append("DataDescriptor not a World Wind .NET LayerSet: ")
.append(dataSource);
}
else
{
try
{
WWDotNetLayerSetReader reader = new WWDotNetLayerSetReader();
reader.setSource(dataSource.getSource());
if (!reader.canRead())
sb.append((sb.length() > 0 ? ", " : "")).append("source not a World Wind .NET LayerSet: ")
.append(dataSource);
}
catch (java.io.IOException e)
{
sb.append((sb.length() > 0 ? ", " : "")).append("source not readable: ").append(dataSource);
}
}
if (sb.length() == 0)
return null;
return Logging.getMessage("DataStoreProducer.InvalidDataSource", sb.toString());
}
//**************************************************************//
//******************** LayerSet Installation *****************//
//**************************************************************//
// TODO
// DONE (1) back out all changes if anything fails
// DONE (2) convert .NET filenames
// DONE (3) convert to app-specified image format
// DONE (4) Write descriptor xml
// (5) Descriptive logging
protected void install(DataSource dataSource, ProductionState productionState) throws java.io.IOException
{
DataDescriptor dataDescriptor;
java.io.File sourceLocation;
java.io.File installLocation;
java.io.File installDescriptor;
String installMimeType = null;
AVList installParams = productionState.productionParams;
Object result = this.readSource(dataSource);
if (result instanceof DataDescriptor)
{
dataDescriptor = (DataDescriptor) result;
}
else
{
String message = result.toString();
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
result = this.sourceLocationFor(dataSource, dataDescriptor);
if (result instanceof java.io.File)
{
sourceLocation = (java.io.File) result;
}
else
{
String message = result.toString();
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
result = this.installLocationFor(installParams, dataSource, dataDescriptor);
if (result instanceof java.io.File)
{
installLocation = (java.io.File) result;
installDescriptor = new java.io.File(installLocation, this.filenameFor(dataDescriptor));
if (WWIO.isAncestorOf(sourceLocation, installLocation))
{
String message = Logging.getMessage("DataStoreProducer.CannotInstallInto",
sourceLocation, installLocation);
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
else if (WWIO.isAncestorOf(installLocation, sourceLocation))
{
String message = Logging.getMessage("DataStoreProducer.CannotInstallInto",
installLocation, sourceLocation);
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
}
else
{
String message = result.toString();
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
try
{
result = installParams.getValue(AVKey.MIME_TYPE);
if (result != null)
{
installMimeType = result.toString();
dataDescriptor.setValue(AVKey.FORMAT_SUFFIX, WWIO.makeSuffixForMimeType(installMimeType));
}
productionState.numSourceFiles[productionState.curSource] = this.countWWDotNetFiles(sourceLocation);
this.installWWDotNetDiretory(sourceLocation, installLocation, installMimeType, productionState);
if (productionState.numSourceFiles[productionState.curSource] != productionState.numInstalledFiles[productionState.curSource])
{
String message = Logging.getMessage("DataStoreProducer.IncompleteInstallation", installLocation);
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
}
catch (java.io.IOException e)
{
// Back out all file system changes made so far.
WWIO.deleteDirectory(installLocation);
String message = Logging.getMessage("generic.ExceptionWhileWriting", installLocation);
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
throw e;
}
try
{
WWDotNetLayerSetWriter writer = new WWDotNetLayerSetWriter();
writer.setDestination(installDescriptor);
writer.write(dataDescriptor);
}
catch (java.io.IOException e)
{
// Back out all file system changes made so far.
WWIO.deleteDirectory(installLocation);
//noinspection ResultOfMethodCallIgnored
installDescriptor.delete();
String message = Logging.getMessage("generic.ExceptionWhileWriting", installDescriptor);
Logging.logger().severe(message);
throw e;
}
this.getProductionResultsList().add(dataDescriptor);
}
protected Object readSource(DataSource dataSource)
{
Object result;
try
{
WWDotNetLayerSetReader reader = new WWDotNetLayerSetReader();
reader.setSource(dataSource.getSource());
result = reader.read();
}
catch (java.io.IOException e)
{
result = Logging.getMessage("generic.ExceptionWhileReading", dataSource);
}
return result;
}
protected Object sourceLocationFor(DataSource dataSource, DataDescriptor descriptor)
{
Object result;
if (dataSource.getSource() instanceof java.io.File)
{
java.io.File file = (java.io.File) dataSource.getSource();
result = file.getParentFile();
if (result == null)
{
result = Logging.getMessage("DataStoreProducer.FileWithoutParent", dataSource);
}
}
else
{
String s = descriptor.getStringValue(AVKey.WORLD_WIND_DOT_NET_PERMANENT_DIRECTORY);
if (s != null)
{
java.io.File file = new java.io.File(s);
if (file.exists())
{
result = file;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -