/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.engine.grte;

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

import com.jstatcom.engine.ConfigKeys;
import com.jstatcom.engine.EngineTypes;
import com.jstatcom.model.JSCConstants;

/**
 * Contains all constants that can be changed for the the GRTE environment. For
 * every key the respective information is stored in an instance of
 * ConfigHolder.
 * 
 * @author Markus Kraetzig
 */
public abstract class GRTEConfigKeys extends ConfigKeys {

    /**
     * Whether graphics initialization should be used or not. This is to
     * control, whether initJGRTE should be called on
     * initialization and whether the graphics subdirectory should be created.
     */
    public static final GRTEConfigKeys DO_JGRTE_INIT = new GRTEConfigKeys(
            "DO_JGRTE_INIT") {

        public String isValid(String value) {
            return null;
        }

        public String defaultVal() {
            return "true";
        }
    };

    /**
     * Sets the name of the system library to load. The default is
     * gaussjavaapirt, which means that the GRT version 5 is
     * used. It is easily possible to switch to higher versions without changing
     * the JAVA code.
     */
    public static final GRTEConfigKeys GAUSSAPI_SYSLIBNAME = new GRTEConfigKeys(
            "GAUSSAPI_SYSLIBNAME") {

        public String isValid(String value) {
            if (value == null || value.length() == 0)
                return "System library name cannot be empty.";
            return null;
        }

        public String defaultVal() {
            return "gaussjavaapirt";
        }
    };

    /**
     * The path to the graphics directory with read/write access.
     */
    public static final GRTEConfigKeys GRAPHICS_DIR = new GRTEConfigKeys(
            "GRAPHICS_DIR") {

        public String isValid(String value) {
            if (value == null)
                return toString() + " cannot be null.";

            value = value.trim();

            // if GRAPHICS_DIR is not set, use user.dir
            if (value.length() == 0)
                value = JSCConstants.getUserDir();
            if (value.indexOf('~') >= 0 || value.indexOf(' ') >= 0) {
                return "Graphics directory \n\""
                        + value
                        + "\"\ncontains the invalid characters \"~\" or \" \".\n"
                        + "Please change the GRAPHICS_DIR value.";
            }

            if (!new File(value).isDirectory())
                return "Graphics directory \"" + value
                        + "\" is not a directory.";
            // Test the write access to the graphics directory.
            File file = new File(value + "/tmp.tmp");
            if (file.canWrite())
                return null;

            try {
                if (file.createNewFile()) {
                    file.delete();
                    return null;
                }
                return "No write permission to \"" + value + "\".";

            } catch (IOException ioEx) {
                return "No write permission to \"" + value + "\".";

            }

        }

        public String defaultVal() {
            return JSCConstants.getUserDir();
        }
    };

    /**
     * The gcg filename with the compiled code for GRTE.
     */
    public static final GRTEConfigKeys GCG_FILENAME = new GRTEConfigKeys(
            "GCG_FILENAME") {

        public String isValid(String value) {
            if (value == null)
                return toString() + " cannot be empty.";
            String fName = EngineTypes.GRTE.DIR_NAME + File.separator + value;
            if (!new File(fName).isFile())
                return "GCG file \"" + fName + "\" does not exist.";

            return null;
        }

        public String defaultVal() {
            return "jgrte.gcg";
        }
    };

    /**
     * GaussConfigKeys constructor.
     * 
     * @param name
     *            the name of the new constant
     */
    GRTEConfigKeys(String name) {
        super(name);
    }
}
 

Ads help maintain this website.