diff src/main/java/christie/codegear/CodeGear.java @ 6:3dcfe63d6394

set type to DataGear by Annotation
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Wed, 27 Dec 2017 00:06:50 +0900
parents 5be6647b87d2
children 21372a589bd3
line wrap: on
line diff
--- a/src/main/java/christie/codegear/CodeGear.java	Thu Dec 14 20:46:18 2017 +0900
+++ b/src/main/java/christie/codegear/CodeGear.java	Wed Dec 27 00:06:50 2017 +0900
@@ -1,5 +1,6 @@
 package christie.codegear;
 
+import christie.annotation.Peek;
 import christie.annotation.Take;
 import christie.datagear.DataGear;
 import christie.datagear.DataGearManager;
@@ -12,42 +13,41 @@
  * Created by e125769 on 12/7/17.
  * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す
  */
-public abstract class CodeGear implements Runnable {
+public abstract class CodeGear implements Runnable{
     public InputDataGear idg = new InputDataGear(this);
     public OutputDataGear odg = new OutputDataGear(this);
     public ArrayList<Command> commandList = new ArrayList<Command>();
     public CodeGearManager cgm;
     public DataGearManager dgm;
+    //public CodeGearExecutor cge;
 
-    public CodeGear(CodeGearManager cgm){//AnnotationからInputDataGearをセット
+    public CodeGear(CodeGearManager cgm){
         this.cgm = cgm;
-        this.dgm = cgm.getDGM("local");
+        //this.cge = new CodeGearExecutor();
+        this.dgm = cgm.getDGM();
+    }
+
+    public void execute() {//AnnotationからInputDataGearをセット
         odg.initODG(cgm);
 
         for (Field field : this.getClass().getDeclaredFields()) {
-            if (field.isAnnotationPresent(Take.class)){
+            DataGear dg = null;
+            try {
+                dg = (DataGear) field.get(this);
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            }
+
+            if (field.isAnnotationPresent(Take.class)) {
                 Take ano = field.getAnnotation(Take.class);
-                commandList.add(new Command(this, null, "local", ano.value(), CommandType.TAKE));
+                commandList.add(new Command(this, dg, "local", ano.value(), CommandType.TAKE));
+            } else if (field.isAnnotationPresent(Peek.class)) {
+                Peek ano = field.getAnnotation(Peek.class);
+                commandList.add(new Command(this, dg, "local", ano.value(), CommandType.PEEK));
             }
         }
 
-        idg.finishInput(this.cgm, commandList);
+        idg.finishInput(cgm, commandList);
     }
 
-    public void setInputValue(){//Annotationから揃ったInputDataGearの値をキャスト
-        for (Field field : this.getClass().getDeclaredFields()) {
-            field.setAccessible(true);
-            if (field.isAnnotationPresent(Take.class)){
-                Take ano = field.getAnnotation(Take.class);
-                try {
-                    field.set(this, idg.inputValue.get(ano.value()));//ダウンキャストできるか?
-                } catch (IllegalAccessException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
-    public void run(){}
-
 }