📄 propertiesfilehorizonlookup.java
字号:
package com.esri.solutions.jitk.web.projection.horizon;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.geometry.WebExtent;
/**
* Concrete implementation of the {@link IHorizonLookup} interface. This class will
* go to a properties file containing horizon extent information.
*
* <p>
* If no properties file is specified via the {@link #setPropertiesFile(String)} method,
* the default properties file located on the classpath at "res/horizons.properties" will
* be used.
* </p>
*/
public class PropertiesFileHorizonLookup implements IHorizonLookup {
/**
* {@link Logger} used to log message for this class.
*/
private static final Logger _logger = Logger.getLogger(PropertiesFileHorizonLookup.class);
/**
* Path to the properties file containing horizon extent information on the classpath.
*/
private String _propertiesFile = "res/horizons.properties";
/**
* Spatial Reference horizon extents {@link Properties}.
*/
private Properties _horizonProperties = null;
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.common.projection.IHorizonLookup#lookup(int)
*/
public WebExtent lookup(int spatialReferenceId) {
WebExtent horizon = null;
try {
if (_horizonProperties == null) {
loadHorizons();
}
String horizonInfo = _horizonProperties.getProperty(String.valueOf(spatialReferenceId));
if (horizonInfo == null) {
_logger.warn("Horizon information not found for spatial reference ID: " + spatialReferenceId);
} else {
String[] coords = horizonInfo.split(",");
horizon = new WebExtent(Double.valueOf(coords[0]), Double.valueOf(coords[1]), Double.valueOf(coords[2]), Double.valueOf(coords[3]));
}
} catch (IOException ex) {
_logger.warn("An IOException occurred loading horizon properties file.", ex);
}
return horizon;
}
/**
* Gets the classpath location of the properties file containing
* the horizon extent information.
*
* @return {@link String} location of the properties file on the classpath.
*/
public String getPropertiesFile() {
return _propertiesFile;
}
/**
* Sets the classpath location of the properties file containing
* the horizon extent information.
*
* @param path {@link String} location of the properteis file on the classpath.
*/
public void setPropertiesFile(String path) {
_propertiesFile = path;
// set to null so that it will be initialized with the new
// properties file
_horizonProperties = null;
}
/**
* Loads the properties file stored in {@link #_propertiesFile} into a
* {@link Properties} object.
*
* @throws IOException if an error occurs loading the properties file via
* {@link Properties#load(java.io.InputStream)}.
*/
private void loadHorizons() throws IOException {
_horizonProperties = new Properties();
_logger.debug("Loading horizon properties file: " + _propertiesFile);
_horizonProperties.load(getClass().getClassLoader().getResourceAsStream(_propertiesFile));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -