OSDN Git Service

fixed: GUIを一新した
[importpicture/importpicture.git] / src / main / java / osm / jp / gpx / matchtime / gui / Command.java
1 package osm.jp.gpx.matchtime.gui;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.text.SimpleDateFormat;
5
6 public class Command extends Thread {
7     String[] args;              // コマンドパラメータ
8     private String commandName = "";    // コマンド名
9     @SuppressWarnings({ "rawtypes" })
10     private final Class cmd;            // 実行対象インスタンス
11
12     /**
13      * コンストラクタ:実行対象のインスタンスを得る
14      * @param cmd
15      */
16     public Command(Class<?> cmd) {
17         super();
18         this.cmd = cmd;
19         this.commandName = cmd.getName();
20         this.args = new String[0];
21     }
22
23     /**
24      * コマンドパラメータの設定
25      * @param folder
26      */
27     public void setArgs(String[] args) {
28         this.args = args;
29     }
30
31     public void setCommandName(String name) {
32         this.commandName = name;
33     }
34     public String getCommandName() {
35         return this.commandName;
36     }
37
38     @SuppressWarnings("unchecked")
39     @Override
40     public void run() {
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]);
44         }
45         System.out.println();
46
47         try {
48             try {
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});
52
53                 System.out.println();
54                 System.out.println("[END:"+ (new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss")).format(new java.util.Date()) +"]\t"+ this.commandName);
55             }
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);
58                 throw e;
59             }
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);
62                 throw e;
63             }
64         }
65         catch(InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) {
66             e.printStackTrace(System.out);
67         }
68         System.out.println();
69     }
70 }