1 package osm.jp.gpx.matchtime.gui;
3 import java.lang.reflect.InvocationTargetException;
4 import java.text.SimpleDateFormat;
6 public class Command extends Thread {
7 String[] args; // コマンドパラメータ
8 private String commandName = ""; // コマンド名
9 @SuppressWarnings({ "rawtypes" })
10 private final Class cmd; // 実行対象インスタンス
13 * コンストラクタ:実行対象のインスタンスを得る
16 public Command(Class<?> cmd) {
19 this.commandName = cmd.getName();
20 this.args = new String[0];
27 public void setArgs(String[] args) {
31 public void setCommandName(String name) {
32 this.commandName = name;
34 public String getCommandName() {
35 return this.commandName;
38 @SuppressWarnings("unchecked")
41 System.out.println("[START:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
42 for (int i=0; i < args.length; i++) {
43 System.out.println(" args["+ i +"]: "+ this.args[i]);
49 java.lang.reflect.Method method = this.cmd.getMethod("main", new Class[] {String[].class});
50 method.setAccessible(true);
51 method.invoke(null, new Object[]{this.args});
54 System.out.println("[END:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
56 catch (InvocationTargetException e) {
57 System.out.println("[ERR!:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
60 catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) {
61 System.out.println("[ERR!:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
65 catch(InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) {
66 e.printStackTrace(System.out);