📄 gdbrastercatalogfactory.java
字号:
package com.esri.solutions.jitk.services.elevation;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IEnumDataset;
import com.esri.arcgis.geodatabase.IRasterCatalog;
import com.esri.arcgis.geodatabase.IRasterCatalogProxy;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.geodatabase.IWorkspaceFactory;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.util.security.Cryptographer;
import com.esri.solutions.jitk.services.common.ServicesException;
/**
* Implementation of {@link IRasterCatalogFactory} that creates an
* {@link IRasterCatalog} instance from a geodatabase. The connection
* information for the geodatabase can be set within a {@link Properties}
* object via a call to {@link #setConnectionInfo(Properties)}. The Properties
* that are needed are:
*
* <ul>
* <li>SERVER: Optional. Host name of the Geodatabase
* <li>INSTANCE: Required. Instance information for the Geodatabase.
* <li>DATABASE: Optional. Required if the backend Geodatabase requires it.
* <li>USER: Optional. Username to connect to the geodatabase. Required if
* AUTHENTICATION_MODE is DBMS.
* <li>PASSWORD: Optional. Password to connect to the geodatabase. Required if
* AUTHENTICATION_MODE is DBMS. Can be
* encrypted or in plain text. If encrypted, PASSWORD_ENCRYPTED
* must be true.
* <li>PASSWORD_ENCRYPTED: Optional. Boolean value indicating if the PASSWORD value
* is encrypted. Required if AUTHENTICATION_MODE is DBMS.
* <li>AUTHENTICATION_MODE: Required. Indicates how authentication will be done with
* the geodatabase. If value is OS, the credentials of the user
* running the process are used. If the value is RDBMS, the values
* specified by USER and PASSWORD are used.
*
* <li>VERSION: Required. Indicates the version of data that is to be used within
* the geodatabase. Typically, sde.DEFAULT.
* <li>RASTER_CATALOG: Required. Name of the Raster Catalog to create an instance for.
* </ul>
*/
public class GdbRasterCatalogFactory implements IRasterCatalogFactory {
/**
* Contains the connection information for the geodatabase.
*/
private final Properties m_props;
/**
* Logger to use to log messages from this class.
*/
private static final Logger LOG = LogManager.getLogger(GdbRasterCatalogFactory.class);
/**
* Constructs a new instance of <code>GdbRasterCatalogFactory</code>.
*/
public GdbRasterCatalogFactory () {
m_props = new Properties();
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.services.elevation.IRasterCatalogFactory#createRasterCatalog(com.esri.arcgis.server.IServerContext)
*/
public IRasterCatalog createRasterCatalog(IServerContext ctx) throws ServicesException {
if (ctx == null) {
throw new NullPointerException ();
}
try {
IWorkspaceFactory factory = null;
factory = (IWorkspaceFactory) ctx.createObject(SdeWorkspaceFactory.getClsid());
IPropertySet ps = createPropertySet(m_props, ctx);
IWorkspace workspace = factory.open(ps, (int)0);
String name = m_props.getProperty("RASTER_CATALOG");
if (name == null) {
throw new ServicesException ("BAD_CONFIGURATION");
}
IRasterCatalog rc = findRasterCatalog(workspace, name);
if (rc == null) {
LOG.error("Cannot find Raster Catalog [" + name + "] in workspace.");
throw new ServicesException ("MISSING_RASTER_CATALOG");
}
return rc;
} catch (AutomationException e) {
throw new ServicesException ("AGS_AUTOMATION_EXCEPTION", e);
} catch (IOException e) {
throw new ServicesException ("AGS_IO_EXCEPTION", e);
}
}
/**
* Sets the Geodatabase Connection Information and the Raster Catalog
* name. This information must be set prior to calling {@link #createRasterCatalog(IServerContext)}
*
* @param props Contains geodatabase connection information.
*/
public void setConnectionInfo (Properties props) {
if (props != null) {
LOG.info("Connection Info: " + props.toString());
m_props.putAll(props);
}
}
private IPropertySet createPropertySet (Properties props, IServerContext ctx) throws AutomationException, IOException {
Cryptographer crypto = new Cryptographer();
boolean passwordEncrypted = false;
if (Boolean.valueOf(props.getProperty("PASSWORD_ENCRYPTED") == null)) {
passwordEncrypted = false;
} else {
passwordEncrypted = Boolean.valueOf(props.getProperty("PASSWORD_ENCRYPTED"));
}
IPropertySet ps = null;
ps = (IPropertySet) ctx.createObject(PropertySet.getClsid());
Set<Object> keys = null;
keys = props.keySet();
for (Object key : keys) {
String value = props.getProperty((String) key);
if (key.equals("PASSWORD")) {
if (passwordEncrypted) {
value = crypto.decrypt(value);
}
}
ps.setProperty((String)key, value);
}
return ps;
}
private IRasterCatalog findRasterCatalog (IWorkspace ws, String name) throws AutomationException, IOException {
IEnumDataset datasets = null;
IDataset tempDataset = null;
datasets = ws.getDatasets(esriDatasetType.esriDTRasterCatalog);
tempDataset = datasets.next();
while (tempDataset != null) {
if (tempDataset.getName().equalsIgnoreCase(name)) {
return new IRasterCatalogProxy(tempDataset);
}
tempDataset = datasets.next();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -