1 package cz.cuni.amis.pogamut.usar2004.agent.module.master;
2
3 import cz.cuni.amis.pogamut.usar2004.agent.module.configuration.SuperConfiguration;
4 import cz.cuni.amis.pogamut.usar2004.agent.module.datatypes.*;
5 import cz.cuni.amis.pogamut.usar2004.agent.module.geometry.SuperGeometry;
6 import cz.cuni.amis.pogamut.usar2004.agent.module.response.SuperResponse;
7 import cz.cuni.amis.pogamut.usar2004.agent.module.sensor.*;
8 import cz.cuni.amis.pogamut.usar2004.agent.module.state.SuperState;
9 import java.lang.reflect.Constructor;
10
11
12
13
14
15
16
17 public abstract class ModuleInstanceProvider
18 {
19
20
21
22
23
24
25
26 public static SuperSensor getSensorInstanceByClass(Class clazz)
27 {
28 try
29 {
30 Constructor ctor = clazz.getConstructor();
31 SuperSensor instance = (SuperSensor) ctor.newInstance();
32 return instance;
33 }
34 catch(Exception e)
35 {
36 System.out.println(e.getMessage() + " " + e.toString());
37 return null;
38 }
39 }
40
41
42
43
44
45
46
47
48
49
50 public static SuperSensor getSensorInstanceByType(String type)
51 {
52 SensorType senType = SensorType.getType(type);
53
54 try
55 {
56 Class clazz = senType.getModuleClass();
57 Constructor ctor = clazz.getConstructor();
58 SuperSensor instance = (SuperSensor) ctor.newInstance();
59 return instance;
60 }
61 catch(Exception e)
62 {
63 System.out.println(e.getMessage() + " " + e.toString());
64 return null;
65 }
66 }
67
68
69
70
71
72
73
74
75
76
77
78 public static SuperGeometry getGeometryInstanceByType(String type)
79 {
80 GeometryType geoType = GeometryType.getType(type);
81
82 try
83 {
84 Class clazz = geoType.getModuleClass();
85 Constructor ctor = clazz.getConstructor();
86 SuperGeometry instance = (SuperGeometry) ctor.newInstance();
87 return instance;
88 }
89 catch(Exception e)
90 {
91 System.out.println(e.getMessage() + " " + e.toString());
92 return null;
93 }
94 }
95
96
97
98
99
100
101
102
103
104
105 public static SuperConfiguration getConfigInstanceByType(String type)
106 {
107 ConfigType confType = ConfigType.getType(type);
108
109 try
110 {
111 Class clazz = confType.getModuleClass();
112 Constructor ctor = clazz.getConstructor();
113 SuperConfiguration instance = (SuperConfiguration) ctor.newInstance();
114 return instance;
115 }
116 catch(Exception e)
117 {
118 System.out.println(e.getMessage() + " " + e.toString());
119 return null;
120 }
121 }
122
123
124
125
126
127
128
129
130
131
132
133 public static SuperResponse getResponseInstanceByType(String type)
134 {
135 ResponseType resType = ResponseType.getType(type);
136
137 try
138 {
139 Class clazz = resType.getModuleClass();
140 Constructor ctor = clazz.getConstructor();
141 SuperResponse instance = (SuperResponse) ctor.newInstance();
142 return instance;
143 }
144 catch(Exception e)
145 {
146 System.out.println(e.getMessage() + " " + e.toString());
147 return null;
148 }
149 }
150
151
152
153
154
155
156
157
158
159
160 public static SuperState getStateInstanceByType(String type)
161 {
162 VehicleType resType = VehicleType.getType(type);
163
164 try
165 {
166 Class clazz = resType.getModuleClass();
167 Constructor ctor = clazz.getConstructor();
168 SuperState instance = (SuperState) ctor.newInstance();
169 return instance;
170 }
171 catch(Exception e)
172 {
173 System.out.println(e.getMessage() + " " + e.toString());
174 return null;
175 }
176 }
177 }