⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultservercontextfactory.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.common.agslocal;

import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IServerConnection;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.ServerInitializer;
import com.esri.arcgis.util.security.Cryptographer;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.Serializable;

import java.util.Properties;


/**
 * Concrete implementation of the {@link IServerContextFactory} that is
 * responsible for creating an {@link IServerContext} object.
 */
public class DefaultServerContextFactory implements IServerContextFactory,
    Serializable {
    /**
     * Serialization version ID.
     */
    private static final long serialVersionUID = 8256383236533082863L;

    /**
     * {@link Logger} used to log messages for this class.
     */
    private static final Logger _logger = LogManager.getLogger(DefaultServerContextFactory.class);

    /**
     * {@link Properties} containing the necessary connection information for creating
     * an {@link IServerContext} object.
     */
    private final Properties m_props;

    /**
     * Default no-args constructor.
     */
    public DefaultServerContextFactory() {
        m_props = new Properties();
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.agslocal.IServerContextFactory#createServerContext()
     */
    public IServerContext createServerContext() throws FactoryException {
        String host = null;
        String domain = null;
        String username = null;
        String password = null;
        String service = null;
        String serviceType = null;
        boolean passwordEncrypted = false;
        Cryptographer crypto = new Cryptographer();

        ServerInitializer serverInitializer = null;
        IServerConnection serverConnection = null;
        IServerObjectManager som = null;
        IServerContext context = null;

        try {
            host = m_props.getProperty("HOST");
            domain = m_props.getProperty("DOMAIN");
            username = m_props.getProperty("USERNAME");
            password = m_props.getProperty("PASSWORD");

            if (Boolean.valueOf(m_props.getProperty("PASSWORD_ENCRYPTED")) == null) {
                passwordEncrypted = false;
            } else {
                passwordEncrypted = Boolean.valueOf(m_props.getProperty(
                            "PASSWORD_ENCRYPTED"));
            }

            service = m_props.getProperty("SERVICE");
            serviceType = m_props.getProperty("SERVICE_TYPE");

            serverInitializer = new ServerInitializer();

            if (domain == null) {
                throw new FactoryException(
                    "DOMAIN not specified, cannot initialize Server.");
            }

            if (username == null) {
                throw new FactoryException(
                    "USERNAME not specified, cannot initialize Server.");
            }

            if (passwordEncrypted) {
                password = crypto.decrypt(password);
            }

            serverInitializer.initializeServer(domain, username, password);

            if (host == null) {
                throw new FactoryException(
                    "HOST not specified, cannot initialize Server");
            }

            serverConnection = new ServerConnection();
            serverConnection.connect(host);

            som = serverConnection.getServerObjectManager();

            if (service == null) {
                service = "";
            }

            if (serviceType == null) {
                serviceType = "";
            }

            service = service.trim();
            serviceType = serviceType.trim();

            context = som.createServerContext(service, serviceType);

            return context;
        } catch (AutomationException e) {
            if (context != null) {
                try {
                    context.releaseContext();
                } catch (AutomationException e1) {
                    _logger.warn("Unable to release ServerContext", e1);
                } catch (IOException e1) {
                    _logger.warn("Unable to release ServerContext", e1);
                }
            }

            throw new FactoryException(e);
        } catch (IOException e) {
            if (context != null) {
                try {
                    context.releaseContext();
                } catch (AutomationException e1) {
                    _logger.warn("Unable to release ServerContext", e1);
                } catch (IOException e1) {
                    _logger.warn("Unable to release ServerContext", e1);
                }
            }

            throw new FactoryException(e);
        }
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.agslocal.IServerContextFactory#getConnectionInfo()
     */
    public Properties getConnectionInfo() {
        return m_props;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.agslocal.IServerContextFactory#setConnectionInfo(java.util.Properties)
     */
    public void setConnectionInfo(Properties props) {
        if (props != null) {
            m_props.putAll(props);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -