/*
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.Map;
import com.jstatcom.engine.AbstractConfigPanel;
import com.jstatcom.engine.ConfigHolder;
import com.jstatcom.engine.ConfigKeys;
import com.jstatcom.engine.Engine;
import com.jstatcom.engine.EngineTypes;
/**
* GaussEngineType holds information about the
* GaussEngine and works as a factory to create an instance of
* GAUSS. It is a Singleton.
*
* @author Markus Kraetzig
*/
public final class GaussEngineType extends EngineTypes {
/**
* To enforce the Singleton property of this class.
*/
public static final GaussEngineType INSTANCE = new GaussEngineType("GAUSS");
private GaussEngine gaussEngine = null;
private AbstractConfigPanel configPanel = null;
/**
* Gets a unique temporary file. The file is created by this method in the
* temporary directory specified for the respective engine. The prefix is
* "jsc". It will automatically be deleted when the VM exits
* normally.
*
* @return the name of a temporary file
* @throws RuntimeException
* if the file could not be created
*/
public File getTempFile() {
// Create tmp file.
String tmpDir = ConfigHolder.valueOf(this).getConfig(
GaussConfigKeys.TEMP_DIR)
+ "/" + DIR_NAME;
File tmpFile = null;
try {
tmpFile = File.createTempFile("jsc", null, new File(tmpDir));
tmpFile.deleteOnExit();
} catch (IOException ex) {
throw new RuntimeException(ex.getMessage());
}
return tmpFile;
}
/**
* GaussEngineType constructor is private to ensure Singleton.
*
* @param name
* String
*/
private GaussEngineType(String name) {
super(name);
}
/**
* Checks the validity of the configuration for the GaussEngine.
*
* @see com.jstatcom.engine.EngineTypes
* @throws IllegalArgumentException
* if (configHolder == null)
*/
public String checkSettings(ConfigHolder configHolder) {
if (configHolder == null)
throw new IllegalArgumentException("Argument was null.");
// Test whether Gaussversion fits with specified directory.
// This is only a distinction between 3.2 and newer Versions
// and only tests, whether tgauss.exe is there.
// Test whether the 16 bit restriction for directory names
// of Gaussversion 3.2 holds. TEMP_DIR, EXE_LOCATION and
// GCG_FILENAME have to be checked.
// This is not implemented.
// if TEMP_DIR is empty, then use system variable TEMP.
// IF TEMP is also empty, then use TMP
return null;
}
/**
* @see com.jstatcom.engine.EngineTypes
*/
public Map getConfigKeys() {
return ConfigKeys.getAllKeys(GaussConfigKeys.class);
}
/**
* @see com.jstatcom.engine.EngineTypes
*/
public AbstractConfigPanel getConfigPanel() {
if (configPanel == null)
configPanel = new GaussConfigPanel();
return configPanel;
}
/**
* @see com.jstatcom.engine.EngineTypes
*/
public Engine getEngine() {
if (gaussEngine == null) {
try {
gaussEngine = GaussEngine.getInstance();
gaussEngine.start(true);
} catch (Throwable ex) {
throw new RuntimeException(
"The GAUSS engine could not be initialized\ndue to the following error:\n\n"
+ ex.getMessage() + "\n");
}
}
addLoadedEngine(gaussEngine);
return gaussEngine;
}
}
Ads help maintain this website.