001: /*
002: * Project: AMODA - Abstract Modeled Application
003: * Class: de.gulden.framework.amoda.environment.commandline.CommandLineApplication
004: * Version: snapshot-beautyj-1.1
005: *
006: * Date: 2004-09-29
007: *
008: * This is a snapshot version of the AMODA 0.2 development branch,
009: * it is not released as a seperate version.
010: * For AMODA, see http://amoda.berlios.de/.
011: *
012: * This is licensed under the GNU Lesser General Public License (LGPL)
013: * and comes with NO WARRANTY.
014: *
015: * Author: Jens Gulden
016: * Email: amoda@jensgulden.de
017: */
018:
019: package de.gulden.framework.amoda.environment.commandline;
020:
021: import de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironmentFactory;
022: import de.gulden.framework.amoda.generic.core.*;
023: import de.gulden.framework.amoda.generic.core.GenericApplication;
024: import de.gulden.framework.amoda.model.core.*;
025: import de.gulden.framework.amoda.model.interaction.*;
026: import java.lang.*;
027: import java.net.*;
028: import java.util.*;
029:
030: /**
031: * Class CommandLineApplication.
032: *
033: * @author Jens Gulden
034: * @version snapshot-beautyj-1.1
035: */
036: public abstract class CommandLineApplication extends GenericApplication {
037:
038: // ------------------------------------------------------------------------
039: // --- fields ---
040: // ------------------------------------------------------------------------
041:
042: public static String DEFAULT_CONFIGURATION_RESOURCE = de.gulden.framework.amoda.generic.core.GenericApplication.DEFAULT_CONFIGURATION_RESOURCE;
043:
044: protected String[] args;
045:
046: protected URL configurationResourceURL;
047:
048: // ------------------------------------------------------------------------
049: // --- methods ---
050: // ------------------------------------------------------------------------
051:
052: public void run(String[] args) {
053: run(args, DEFAULT_CONFIGURATION_RESOURCE);
054: }
055:
056: public void run(String[] args, String configurationResource) {
057: java.net.URL url = this .getClass().getResource(
058: configurationResource);
059: setConfigurationResourceURL(url);
060: setArgs(args);
061: super .run();
062: }
063:
064: public void executeCommand(String code) {
065: // might be overwritten by subclasses to provide a different way of executing commands
066: getCommand(code).perform();
067: }
068:
069: public ArgsParser createArgsParser() {
070: return new CommandLineArgsParser(
071: ((de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment) getEnvironment())
072: .getFactory().getArgs());
073: }
074:
075: public void start() {
076: // about() **** war mal hier, aber ok?
077: super .start();
078: // to be extended by subclasses
079: }
080:
081: public void init(ApplicationEnvironment environment) {
082: super .init(environment);
083:
084: }
085:
086: public void welcome() {
087: about();
088: }
089:
090: public String[] getArgs() {
091: return args;
092: }
093:
094: public void setArgs(String[] _args) {
095: args = _args;
096: }
097:
098: public URL getConfigurationResourceURL() {
099: return configurationResourceURL;
100: }
101:
102: public void setConfigurationResourceURL(
103: URL _configurationResourceURL) {
104: configurationResourceURL = _configurationResourceURL;
105: }
106:
107: public void exit(int code) {
108: System.exit(code);
109: }
110:
111: public Message createAboutMessage() {
112: de.gulden.framework.amoda.generic.interaction.GenericMessage m = (de.gulden.framework.amoda.generic.interaction.GenericMessage) super
113: .createAboutMessage();
114: m.setSystem(true); // GUIApplicationEnvironent interpretes this as command-line fallback and outputs message on console (useful if CommandLineApplication is run via GUIApplicationEnvironemnt)
115: return m;
116: }
117:
118: protected ApplicationEnvironment createApplicationEnvironment() {
119: de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory = new CommandLineApplicationEnvironmentFactory(
120: getArgs()); //,getConfigurationResourceURL()
121: return factory.createApplicationEnvironment();
122: }
123:
124: } // end CommandLineApplication
|