1 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 36 public abstract class CommandLineApplication extends GenericApplication { 37 38 42 public static String DEFAULT_CONFIGURATION_RESOURCE = de.gulden.framework.amoda.generic.core.GenericApplication.DEFAULT_CONFIGURATION_RESOURCE; 43 44 protected String [] args; 45 46 protected URL configurationResourceURL; 47 48 49 53 public void run(String [] args) { 54 run(args,DEFAULT_CONFIGURATION_RESOURCE); 55 } 56 57 public void run(String [] args, String configurationResource) { 58 java.net.URL url=this.getClass().getResource(configurationResource); 59 setConfigurationResourceURL(url); 60 setArgs(args); 61 super.run(); 62 } 63 64 public void executeCommand(String code) { 65 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 super.start(); 76 } 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 [] getArgs() { 89 return args; 90 } 91 92 public void setArgs(String [] _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); return m; 112 } 113 114 protected ApplicationEnvironment createApplicationEnvironment() { 115 de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory=new CommandLineApplicationEnvironmentFactory(getArgs()); return factory.createApplicationEnvironment(); 117 } 118 119 } | Popular Tags |