1 package cz.cuni.amis.pogamut.sposh.executor;
2
3 import cz.cuni.amis.pogamut.sposh.context.Context;
4 import cz.cuni.amis.pogamut.sposh.engine.VariableContext;
5 import cz.cuni.amis.pogamut.sposh.exceptions.MethodException;
6 import java.lang.reflect.InvocationTargetException;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public abstract class ParamsAction<CONTEXT extends Context> extends StateAction<CONTEXT> {
50
51 private static final String INIT_METHOD_NAME = "init";
52 private static final String RUN_METHOD_NAME = "run";
53 private static final String DONE_METHOD_NAME = "done";
54 private final ParamsMethod<Void> initMethod;
55 private final ParamsMethod<ActionResult> runMethod;
56 private final ParamsMethod<Void> doneMethod;
57
58 public ParamsAction(CONTEXT ctx) {
59 super(ctx);
60
61 initMethod = new ParamsMethod<Void>(getClass(), INIT_METHOD_NAME, Void.TYPE);
62 runMethod = new ParamsMethod<ActionResult>(getClass(), RUN_METHOD_NAME, ActionResult.class);
63 doneMethod = new ParamsMethod<Void>(getClass(), DONE_METHOD_NAME, Void.TYPE);
64 }
65
66 @Override
67 public final void init(VariableContext params) {
68 try {
69 initMethod.invoke(this, params);
70 } catch (InvocationTargetException ex) {
71 throw new MethodException("",ex.getTargetException());
72 }
73 }
74
75 @Override
76 public final ActionResult run(VariableContext params) {
77 try {
78 return runMethod.invoke(this, params);
79 } catch (InvocationTargetException ex) {
80 throw new MethodException("",ex.getTargetException());
81 }
82 }
83
84 @Override
85 public final void done(VariableContext params) {
86 try {
87 doneMethod.invoke(this, params);
88 } catch (InvocationTargetException ex) {
89 throw new MethodException("",ex.getTargetException());
90 }
91 }
92 }