view src/java/de/intevation/mxd/ArcGISInitializer.java @ 103:163d474165b0

Added check for ArcGISDesktop environment.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 10 Jun 2011 14:04:03 +0200
parents ef7ca23c4233
children 104af51a4717
line wrap: on
line source
package de.intevation.mxd;

import java.io.IOException;
import java.io.File;

import org.apache.log4j.Logger;

import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;

/**
 * Initializes the ArcGIS Engine and Objects.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class ArcGISInitializer {

    /**
     * The Logger.
     */
    private static final Logger logger = Logger.getLogger(ArcGISInitializer.class);

    /**
     * Private member.
     */
    private AoInitialize    aoInit;
    private String          engineInstallDir = "";


    /**
     * Init ArcGIS Java Objects.
     */
    public boolean initArcGIS ()
    throws IOException {
        logger.debug("initArcGIS()");
        EngineInitializer.initializeEngine();
        aoInit              = new AoInitialize();
        engineInstallDir    = System.getenv("AGSENGINEJAVA");
        File installDir = new File(engineInstallDir);
        if(!installDir.exists()) {
            engineInstallDir = System.getenv("AGSDESKTOPJAVA");
            installDir = new File(engineInstallDir);
            if(!installDir.exists()) {
                logger.error("Could not find ArcGIS Environment. \n" +
                             "AGSENGINEJAVA or AGSDESKTOPJAVA not set.");
                return false;
            }
        }
        else {
            return true;
        }
        return true;
    }

    /**
     * Init ArcGIS License.
     */
    public boolean initArcGISLicenses()
    throws IOException {
        logger.debug("initArcGISLicenses()");
        if(aoInit.isProductCodeAvailable
           (esriLicenseProductCode.esriLicenseProductCodeEngine) ==
           esriLicenseStatus.esriLicenseAvailable) {
           aoInit.initialize
               (esriLicenseProductCode.esriLicenseProductCodeEngine);
        }
        else if (aoInit.isProductCodeAvailable
                 (esriLicenseProductCode.esriLicenseProductCodeArcView) ==
                 esriLicenseStatus.esriLicenseAvailable) {
                 aoInit.initialize
                     (esriLicenseProductCode.esriLicenseProductCodeArcView);
        }
        else {
            logger.error("Engine Runtime or ArcView" +
                         " license not initialized.\n" +
                         "Please install an ArcGIS product and set the" +
                         " PATH-variable correctly.");
            return false;
        }
        return true;
    }

    /**
     * Shutdown the ArcGIS Objects.
     */
    public boolean shutdownArcGIS()
    throws IOException {
        if(aoInit != null) {
            aoInit.shutdown();
            return true;
        }
        else {
            return false;
        }
    }

    /**
     * Get the ArcGIS Engine Directory.
     */
    public String getEngineDirectory()
    throws Exception {
        if(engineInstallDir == "") {
            throw new Exception("Call initArcGIS() first!");
        }
        else {
            return engineInstallDir;
        }
    }
}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)