- Timestamp:
- 01/10/14 10:46:42 (11 years ago)
- Location:
- trunk/autoquest-test-utils/src
- Files:
-
- 8 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1294 r1325 17 17 import java.util.ArrayList; 18 18 import java.util.HashMap; 19 import java.util.LinkedList; 20 import java.util.List; 19 21 import java.util.Map; 20 22 import java.util.regex.Matcher; … … 163 165 String id = matcher.group(2); 164 166 167 // determine the children before creating this instance 168 List<ITaskInstance> children = new LinkedList<ITaskInstance>(); 169 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 170 children.add(parseTaskInstance(taskMatcher)); 171 } 172 173 // get the model 174 ITask task = getCreateTask(id, type, children); 175 176 // create the respective instance 177 ITaskInstance instance; 178 179 if (task instanceof ISequence) { 180 instance = taskFactory.createNewTaskInstance((ISequence) task); 181 } 182 else if (task instanceof ISelection) { 183 instance = taskFactory.createNewTaskInstance((ISelection) task); 184 } 185 else if (task instanceof IIteration) { 186 instance = taskFactory.createNewTaskInstance((IIteration) task); 187 } 188 else if (task instanceof IOptional) { 189 instance = taskFactory.createNewTaskInstance((IOptional) task); 190 } 191 else { 192 Event event = !task.getInstances().isEmpty() ? 193 ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent() : 194 createUserInteractionEvent(type, id, matcher.group(4)); 195 196 instance = taskFactory.createNewTaskInstance((IEventTask) task, event); 197 } 198 199 // add the children to the instance 200 for (ITaskInstance childInstance : children) { 201 if (instance instanceof ISequenceInstance) { 202 taskBuilder.addChild((ISequenceInstance) instance, childInstance); 203 } 204 else if (instance instanceof ISelectionInstance) { 205 if (((ISelectionInstance) instance).getChild() == null) { 206 taskBuilder.setChild((ISelectionInstance) instance, childInstance); 207 } 208 else { 209 throw new IllegalArgumentException("can not add several children to one " + 210 "selection instance"); 211 } 212 } 213 else if (instance instanceof IIterationInstance) { 214 taskBuilder.addChild((IIterationInstance) instance, childInstance); 215 } 216 else if (instance instanceof IOptionalInstance) { 217 if (((IOptionalInstance) instance).getChild() == null) { 218 taskBuilder.setChild((IOptionalInstance) instance, childInstance); 219 } 220 else { 221 throw new IllegalArgumentException("can not add several children to one " + 222 "optional instance"); 223 } 224 } 225 } 226 227 // validate the instance 228 try { 229 new TaskTreeValidator().validate(instance); 230 } 231 catch (java.lang.AssertionError e) { 232 throw new IllegalArgumentException(e.getMessage(), e); 233 } 234 235 return instance; 236 } 237 238 /** 239 * <p> 240 * TODO: comment 241 * </p> 242 * 243 * @param id 244 * @param type 245 * @param children 246 * @return 247 */ 248 private ITask getCreateTask(String id, String type, List<ITaskInstance> children) { 165 249 ITask task = tasks.get(id); 166 250 … … 179 263 } 180 264 else { 181 task = createUserInteractionTaskInstance(matcher).getTask();265 task = taskFactory.createNewEventTask(type + " --> " + id); 182 266 } 183 267 tasks.put(id, task); 184 } 185 186 ITaskInstance instance; 187 188 if (task instanceof ISequence) { 189 instance = taskFactory.createNewTaskInstance((ISequence) task); 190 } 191 else if (task instanceof ISelection) { 192 instance = taskFactory.createNewTaskInstance((ISelection) task); 193 } 194 else if (task instanceof IIteration) { 195 instance = taskFactory.createNewTaskInstance((IIteration) task); 196 } 197 else if (task instanceof IOptional) { 198 instance = taskFactory.createNewTaskInstance((IOptional) task); 199 } 200 else { 201 instance = taskFactory.createNewTaskInstance 202 ((IEventTask) task, 203 ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent()); 204 } 205 206 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 207 ITaskInstance childInstance = parseTaskInstance(taskMatcher); 208 209 if (task instanceof ISequence) { 210 taskBuilder.addChild((ISequence) task, childInstance.getTask()); 211 } 212 else if (task instanceof ISelection) { 213 taskBuilder.addChild((ISelection) task, childInstance.getTask()); 214 } 215 else if (task instanceof IIteration) { 216 if (((IIteration) task).getMarkedTask() == null) { 217 taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask()); 218 } 219 else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) { 220 throw new IllegalArgumentException 221 ("can not add more than one child to an iteration"); 222 } 223 } 224 else if (task instanceof IOptional) { 225 if (((IOptional) task).getMarkedTask() == null) { 226 taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask()); 227 } 228 else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) { 229 throw new IllegalArgumentException 230 ("can not add more than one child to an optional"); 231 } 232 } 233 else { 234 throw new IllegalArgumentException("can not add children to something that is no " + 235 "sequence, selection, iteration, or optional"); 236 } 237 238 if (instance instanceof ISequenceInstance) { 239 taskBuilder.addChild((ISequenceInstance) instance, childInstance); 240 } 241 else if (instance instanceof ISelectionInstance) { 242 taskBuilder.setChild((ISelectionInstance) instance, childInstance); 243 } 244 else if (instance instanceof IIterationInstance) { 245 taskBuilder.addChild((IIterationInstance) instance, childInstance); 246 } 247 else if (instance instanceof IOptionalInstance) { 248 taskBuilder.setChild((IOptionalInstance) instance, childInstance); 249 } 250 } 251 252 return instance; 268 269 for (ITaskInstance childInstance : children) { 270 if (task instanceof ISequence) { 271 taskBuilder.addChild((ISequence) task, childInstance.getTask()); 272 } 273 else if (task instanceof ISelection) { 274 taskBuilder.addChild((ISelection) task, childInstance.getTask()); 275 } 276 else if (task instanceof IIteration) { 277 if (((IIteration) task).getMarkedTask() == null) { 278 taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask()); 279 } 280 else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) { 281 throw new IllegalArgumentException 282 ("can not add more than one child to an iteration"); 283 } 284 } 285 else if (task instanceof IOptional) { 286 if (((IOptional) task).getMarkedTask() == null) { 287 taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask()); 288 } 289 else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) { 290 throw new IllegalArgumentException 291 ("can not add more than one child to an optional"); 292 } 293 } 294 else { 295 throw new IllegalArgumentException("can not add children to something that " + 296 "is no sequence, selection, iteration, or " + 297 "optional"); 298 } 299 } 300 } 301 else if ("Selection".equals(type)) { 302 // update the selection with further alternatives, if specified by the current 303 // child instance 304 if (children.size() == 1) { 305 ITask newChildTask = children.get(0).getTask(); 306 307 boolean found = false; 308 for (ITask childTask : ((ISelection) task).getChildren()) { 309 if (childTask.equals(newChildTask)) { 310 found = true; 311 break; 312 } 313 } 314 315 if (!found) { 316 taskBuilder.addChild((ISelection) task, newChildTask); 317 } 318 } 319 } 320 321 return task; 253 322 } 254 323 … … 260 329 * @return 261 330 */ 262 private ITaskInstance createUserInteractionTaskInstance(Matcher matcher) { 263 String evenType = matcher.group(1); 264 String id = matcher.group(2); 265 IEventTarget eventTarget = targets.get(id); 331 private Event createUserInteractionEvent(String type, String targetId, String furtherInfo) { 332 IEventTarget eventTarget = targets.get(targetId); 266 333 if (eventTarget == null) { 267 eventTarget = determineTarget(evenType, id, matcher.group(4)); 268 targets.put(id, eventTarget); 269 } 270 IEventType eventType = determineType(evenType, matcher.group(4)); 271 IEventTask task = taskFactory.createNewEventTask(eventType + " --> " + eventTarget); 272 273 return taskFactory.createNewTaskInstance(task, new Event(eventType, eventTarget)); 334 eventTarget = determineTarget(type, targetId, furtherInfo); 335 targets.put(targetId, eventTarget); 336 } 337 IEventType eventType = determineType(type, furtherInfo); 338 339 return new Event(eventType, eventTarget); 274 340 } 275 341
Note: See TracChangeset
for help on using the changeset viewer.