/*
 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.gauss;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

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

/**
 * Contains all constants that define the GAUSS environment. For every key the
 * respective information is stored in an instance of ConfigHolder.
 * The GaussConfigPanel contains a user input mask to adjust some
 * of the defined settings.
 * 
 * @author Markus Kraetzig 
 * 
 * @see com.jstatcom.engine.ConfigHolder
 * @see com.jstatcom.engine.gauss.GaussConfigPanel
 */
public abstract class GaussConfigKeys extends ConfigKeys {
    private static String[] validKeys = { "3.2", "3.5", "3.6", "4.0", "5.0",
            "6.0", "7.0", "8.0" };

    /**
     * The directory of the executable, e.g. c:\mteng8.0\engauss.exe.
     */
    public static final GaussConfigKeys EXE_LOCATION = new GaussConfigKeys(
            "EXE_LOCATION") {

        public String isValid(String value) {
            if (value == null)
                return toString() + " cannot be null.";
            if (new File(value).exists())
                return null;
            return "\"" + value
                    + "\" does not seem to be a valid GAUSS directory.";
        }

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

    /**
     * The GAUSS version.
     */
    public static final GaussConfigKeys GAUSS_VERSION = new GaussConfigKeys(
            "GAUSS_VERSION") {

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

            for (int i = 0; i < validKeys.length; i++) {
                if (value.equals(validKeys[i]))
                    return null;
            }
            return "\"" + value
                    + "\" is not in the list of valid GAUSS versions "
                    + Arrays.asList(validKeys).toString() + ".";
        }

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

    /**
     * The size of the shared memory used for the communication.
     */
    public static final GaussConfigKeys SHARED_MEM_SIZE = new GaussConfigKeys(
            "SHARED_MEM_SIZE") {

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

            int number = 0;
            int lowerBound = 1000;
            int upperBound = 1000000000;

            try {
                number = Integer.parseInt(value);
            } catch (NumberFormatException nEx) {
                return "\"" + value + "\" is not a valid integer number.";
            }
            if (number < lowerBound || number > upperBound)
                return "\"" + value + "\" is not in the valid range of ["
                        + lowerBound + ";" + upperBound
                        + "].\nA reasonable default value is 800000.";
            return null;
        }

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

    /**
     * The temporary directory with read/write access.
     */
    public static final GaussConfigKeys TEMP_DIR = new GaussConfigKeys(
            "TEMP_DIR") {

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

            // if TEMP_DIR is not set, use java.io.tmpdir
            if (value.length() == 0) {
                value = JSCConstants.getSystemTemp();
                return null;
            }
            if (!new File(value).isDirectory())
                return "Temporary directory \"" + value
                        + "\" is not a directory.";
            // Test the write access to the temporary 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 "";
        }
    };

    /**
     * The XML file containing the list of libraries.
     */
    public static final GaussConfigKeys LIB_CFG = new GaussConfigKeys("LIB_CFG") {

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

        public String defaultVal() {
            return "lib.xml";
        }
    };

    /**
     * The XML file containing the list of files to be compiled.
     */
    public static final GaussConfigKeys COMPILE_CFG = new GaussConfigKeys(
            "COMPILE_CFG") {

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

        public String defaultVal() {
            return "compile.xml";
        }
    };

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

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

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

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

    /*
     * Gets an iterator over all valid GAUSS versions.
     * 
     * @return iterator over all version strings
     */
    public static Iterator versionIterator() {
        ArrayList list = new ArrayList();
        for (int i = 0; i < validKeys.length; i++)
            list.add(validKeys[i]);
        return list.iterator();
    }
}
 

Ads help maintain this website.