Mercurial > hg > Database > Christie
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:5be6647b87d2 | 6:3dcfe63d6394 |
---|---|
1 package christie.codegear; | 1 package christie.codegear; |
2 | 2 |
3 import christie.annotation.Peek; | |
3 import christie.annotation.Take; | 4 import christie.annotation.Take; |
4 import christie.datagear.DataGear; | 5 import christie.datagear.DataGear; |
5 import christie.datagear.DataGearManager; | 6 import christie.datagear.DataGearManager; |
6 | 7 |
7 import java.lang.reflect.Field; | 8 import java.lang.reflect.Field; |
10 | 11 |
11 /** | 12 /** |
12 * Created by e125769 on 12/7/17. | 13 * Created by e125769 on 12/7/17. |
13 * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す | 14 * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す |
14 */ | 15 */ |
15 public abstract class CodeGear implements Runnable { | 16 public abstract class CodeGear implements Runnable{ |
16 public InputDataGear idg = new InputDataGear(this); | 17 public InputDataGear idg = new InputDataGear(this); |
17 public OutputDataGear odg = new OutputDataGear(this); | 18 public OutputDataGear odg = new OutputDataGear(this); |
18 public ArrayList<Command> commandList = new ArrayList<Command>(); | 19 public ArrayList<Command> commandList = new ArrayList<Command>(); |
19 public CodeGearManager cgm; | 20 public CodeGearManager cgm; |
20 public DataGearManager dgm; | 21 public DataGearManager dgm; |
22 //public CodeGearExecutor cge; | |
21 | 23 |
22 public CodeGear(CodeGearManager cgm){//AnnotationからInputDataGearをセット | 24 public CodeGear(CodeGearManager cgm){ |
23 this.cgm = cgm; | 25 this.cgm = cgm; |
24 this.dgm = cgm.getDGM("local"); | 26 //this.cge = new CodeGearExecutor(); |
27 this.dgm = cgm.getDGM(); | |
28 } | |
29 | |
30 public void execute() {//AnnotationからInputDataGearをセット | |
25 odg.initODG(cgm); | 31 odg.initODG(cgm); |
26 | 32 |
27 for (Field field : this.getClass().getDeclaredFields()) { | 33 for (Field field : this.getClass().getDeclaredFields()) { |
28 if (field.isAnnotationPresent(Take.class)){ | 34 DataGear dg = null; |
35 try { | |
36 dg = (DataGear) field.get(this); | |
37 } catch (IllegalAccessException e) { | |
38 e.printStackTrace(); | |
39 } | |
40 | |
41 if (field.isAnnotationPresent(Take.class)) { | |
29 Take ano = field.getAnnotation(Take.class); | 42 Take ano = field.getAnnotation(Take.class); |
30 commandList.add(new Command(this, null, "local", ano.value(), CommandType.TAKE)); | 43 commandList.add(new Command(this, dg, "local", ano.value(), CommandType.TAKE)); |
44 } else if (field.isAnnotationPresent(Peek.class)) { | |
45 Peek ano = field.getAnnotation(Peek.class); | |
46 commandList.add(new Command(this, dg, "local", ano.value(), CommandType.PEEK)); | |
31 } | 47 } |
32 } | 48 } |
33 | 49 |
34 idg.finishInput(this.cgm, commandList); | 50 idg.finishInput(cgm, commandList); |
35 } | 51 } |
36 | 52 |
37 public void setInputValue(){//Annotationから揃ったInputDataGearの値をキャスト | |
38 for (Field field : this.getClass().getDeclaredFields()) { | |
39 field.setAccessible(true); | |
40 if (field.isAnnotationPresent(Take.class)){ | |
41 Take ano = field.getAnnotation(Take.class); | |
42 try { | |
43 field.set(this, idg.inputValue.get(ano.value()));//ダウンキャストできるか? | |
44 } catch (IllegalAccessException e) { | |
45 e.printStackTrace(); | |
46 } | |
47 } | |
48 } | |
49 } | |
50 | |
51 public void run(){} | |
52 | |
53 } | 53 } |