KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > framework > amoda > environment > commandline > CommandLineApplication


1 /*
2  * Project: AMODA - Abstract Modeled Application
3  * Class: de.gulden.framework.amoda.environment.commandline.CommandLineApplication
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the AMODA 0.2 development branch,
9  * it is not released as a seperate version.
10  * For AMODA, see http://amoda.berlios.de/.
11  *
12  * This is licensed under the GNU Lesser General Public License (LGPL)
13  * and comes with NO WARRANTY.
14  *
15  * Author: Jens Gulden
16  * Email: amoda@jensgulden.de
17  */

18
19 package de.gulden.framework.amoda.environment.commandline;
20
21 import de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironmentFactory;
22 import de.gulden.framework.amoda.generic.core.*;
23 import de.gulden.framework.amoda.generic.core.GenericApplication;
24 import de.gulden.framework.amoda.model.core.*;
25 import de.gulden.framework.amoda.model.interaction.*;
26 import java.lang.*;
27 import java.net.*;
28 import java.util.*;
29
30 /**
31  * Class CommandLineApplication.
32  *
33  * @author Jens Gulden
34  * @version snapshot-beautyj-1.1
35  */

36 public abstract class CommandLineApplication extends GenericApplication {
37
38     // ------------------------------------------------------------------------
39
// --- fields ---
40
// ------------------------------------------------------------------------
41

42     public static String JavaDoc DEFAULT_CONFIGURATION_RESOURCE = de.gulden.framework.amoda.generic.core.GenericApplication.DEFAULT_CONFIGURATION_RESOURCE;
43
44     protected String JavaDoc[] args;
45
46     protected URL configurationResourceURL;
47
48
49     // ------------------------------------------------------------------------
50
// --- methods ---
51
// ------------------------------------------------------------------------
52

53     public void run(String JavaDoc[] args) {
54         run(args,DEFAULT_CONFIGURATION_RESOURCE);
55     }
56
57     public void run(String JavaDoc[] args, String JavaDoc configurationResource) {
58         java.net.URL JavaDoc url=this.getClass().getResource(configurationResource);
59         setConfigurationResourceURL(url);
60         setArgs(args);
61         super.run();
62     }
63
64     public void executeCommand(String JavaDoc code) {
65         // might be overwritten by subclasses to provide a different way of executing commands
66
getCommand(code).perform();
67     }
68
69     public ArgsParser createArgsParser() {
70         return new CommandLineArgsParser(((de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment)getEnvironment()).getFactory().getArgs());
71     }
72
73     public void start() {
74         // about() **** war mal hier, aber ok?
75
super.start();
76         // to be extended by subclasses
77
}
78
79     public void init(ApplicationEnvironment environment) {
80         super.init(environment);
81
82     }
83
84     public void welcome() {
85         about();
86     }
87
88     public String JavaDoc[] getArgs() {
89         return args;
90     }
91
92     public void setArgs(String JavaDoc[] _args) {
93         args = _args;
94     }
95
96     public URL getConfigurationResourceURL() {
97         return configurationResourceURL;
98     }
99
100     public void setConfigurationResourceURL(URL _configurationResourceURL) {
101         configurationResourceURL = _configurationResourceURL;
102     }
103
104     public void exit(int code) {
105         System.exit(code);
106     }
107
108     public Message createAboutMessage() {
109         de.gulden.framework.amoda.generic.interaction.GenericMessage m = (de.gulden.framework.amoda.generic.interaction.GenericMessage)super.createAboutMessage();
110         m.setSystem(true); // GUIApplicationEnvironent interpretes this as command-line fallback and outputs message on console (useful if CommandLineApplication is run via GUIApplicationEnvironemnt)
111
return m;
112     }
113
114     protected ApplicationEnvironment createApplicationEnvironment() {
115         de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory=new CommandLineApplicationEnvironmentFactory(getArgs()); //,getConfigurationResourceURL()
116
return factory.createApplicationEnvironment();
117     }
118
119 } // end CommandLineApplication
120
Popular Tags