/*
* Project: AMODA - Abstract Modeled Application
* Class: de.gulden.framework.amoda.environment.commandline.CommandLineApplication
* Version: snapshot-beautyj-1.1
*
* Date: 2004-09-29
*
* This is a snapshot version of the AMODA 0.2 development branch,
* it is not released as a seperate version.
* For AMODA, see http://amoda.berlios.de/.
*
* This is licensed under the GNU Lesser General Public License (LGPL)
* and comes with NO WARRANTY.
*
* Author: Jens Gulden
* Email: amoda@jensgulden.de
*/
package de.gulden.framework.amoda.environment.commandline;
import de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironmentFactory;
import de.gulden.framework.amoda.generic.core.*;
import de.gulden.framework.amoda.generic.core.GenericApplication;
import de.gulden.framework.amoda.model.core.*;
import de.gulden.framework.amoda.model.interaction.*;
import java.lang.*;
import java.net.*;
import java.util.*;
/**
* Class CommandLineApplication.
*
* @author Jens Gulden
* @version snapshot-beautyj-1.1
*/
public abstract class CommandLineApplication extends GenericApplication {
// ------------------------------------------------------------------------
// --- fields ---
// ------------------------------------------------------------------------
public static String DEFAULT_CONFIGURATION_RESOURCE = de.gulden.framework.amoda.generic.core.GenericApplication.DEFAULT_CONFIGURATION_RESOURCE;
protected String[] args;
protected URL configurationResourceURL;
// ------------------------------------------------------------------------
// --- methods ---
// ------------------------------------------------------------------------
public void run(String[] args) {
run(args,DEFAULT_CONFIGURATION_RESOURCE);
}
public void run(String[] args, String configurationResource) {
java.net.URL url=this.getClass().getResource(configurationResource);
setConfigurationResourceURL(url);
setArgs(args);
super.run();
}
public void executeCommand(String code) {
// might be overwritten by subclasses to provide a different way of executing commands
getCommand(code).perform();
}
public ArgsParser createArgsParser() {
return new CommandLineArgsParser(((de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment)getEnvironment()).getFactory().getArgs());
}
public void start() {
// about() **** war mal hier, aber ok?
super.start();
// to be extended by subclasses
}
public void init(ApplicationEnvironment environment) {
super.init(environment);
}
public void welcome() {
about();
}
public String[] getArgs() {
return args;
}
public void setArgs(String[] _args) {
args = _args;
}
public URL getConfigurationResourceURL() {
return configurationResourceURL;
}
public void setConfigurationResourceURL(URL _configurationResourceURL) {
configurationResourceURL = _configurationResourceURL;
}
public void exit(int code) {
System.exit(code);
}
public Message createAboutMessage() {
de.gulden.framework.amoda.generic.interaction.GenericMessage m = (de.gulden.framework.amoda.generic.interaction.GenericMessage)super.createAboutMessage();
m.setSystem(true); // GUIApplicationEnvironent interpretes this as command-line fallback and outputs message on console (useful if CommandLineApplication is run via GUIApplicationEnvironemnt)
return m;
}
protected ApplicationEnvironment createApplicationEnvironment() {
de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory=new CommandLineApplicationEnvironmentFactory(getArgs()); //,getConfigurationResourceURL()
return factory.createApplicationEnvironment();
}
} // end CommandLineApplication
|