[1123] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.tasktrees; |
---|
| 16 | |
---|
[1202] | 17 | import java.util.ArrayList; |
---|
[1123] | 18 | import java.util.HashMap; |
---|
[1327] | 19 | import java.util.HashSet; |
---|
[1325] | 20 | import java.util.LinkedList; |
---|
| 21 | import java.util.List; |
---|
[1123] | 22 | import java.util.Map; |
---|
[1327] | 23 | import java.util.Set; |
---|
[1123] | 24 | import java.util.regex.Matcher; |
---|
| 25 | import java.util.regex.Pattern; |
---|
| 26 | |
---|
[1202] | 27 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
[1123] | 28 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
[1202] | 29 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
[1123] | 30 | import de.ugoe.cs.autoquest.eventcore.StringEventType; |
---|
[1333] | 31 | import de.ugoe.cs.autoquest.eventcore.gui.Scroll; |
---|
[1202] | 32 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput; |
---|
[1294] | 33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1123] | 35 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
[1294] | 36 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
[1123] | 37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
[1294] | 38 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
[1123] | 39 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
[1294] | 40 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
[1123] | 41 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1294] | 42 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; |
---|
[1146] | 43 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 44 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
| 45 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
| 46 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 47 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
| 48 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
[1123] | 49 | import de.ugoe.cs.autoquest.test.DummyGUIElement; |
---|
[1202] | 50 | import de.ugoe.cs.autoquest.test.DummyTextField; |
---|
[1123] | 51 | |
---|
| 52 | /** |
---|
| 53 | * TODO comment |
---|
| 54 | * |
---|
| 55 | * @version $Revision: $ $Date: 01.04.2012$ |
---|
| 56 | * @author 2012, last modified by $Author: patrick$ |
---|
| 57 | */ |
---|
[1146] | 58 | public class TaskTreeDecoder { |
---|
[1123] | 59 | |
---|
| 60 | /** */ |
---|
[1146] | 61 | private static Pattern taskInstancePattern = Pattern.compile("([^{}]+)\\{|\\}"); |
---|
[1123] | 62 | |
---|
| 63 | /** */ |
---|
[1146] | 64 | private static Pattern taskInstanceDetailsPattern = |
---|
[1202] | 65 | Pattern.compile("\\s*(\\w*)\\s*([\\w\\(\\)\"]*)\\s*(\\(([\\w*\\s*]*)\\))?((\\w*)|(\".*\"))?"); |
---|
| 66 | |
---|
[1123] | 67 | /** */ |
---|
[1146] | 68 | private ITaskFactory taskFactory; |
---|
[1123] | 69 | |
---|
| 70 | /** */ |
---|
[1146] | 71 | private ITaskBuilder taskBuilder; |
---|
[1123] | 72 | |
---|
| 73 | /** */ |
---|
| 74 | Map<String, IEventTarget> targets = new HashMap<String, IEventTarget>(); |
---|
| 75 | |
---|
[1146] | 76 | /** */ |
---|
| 77 | Map<String, ITask> tasks = new HashMap<String, ITask>(); |
---|
| 78 | |
---|
[1123] | 79 | /** |
---|
| 80 | * |
---|
| 81 | */ |
---|
[1146] | 82 | public TaskTreeDecoder(ITaskFactory taskFactory, ITaskBuilder taskBuilder) { |
---|
[1123] | 83 | super(); |
---|
[1146] | 84 | this.taskFactory = taskFactory; |
---|
| 85 | this.taskBuilder = taskBuilder; |
---|
[1123] | 86 | } |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * |
---|
| 90 | */ |
---|
[1146] | 91 | public ITaskInstanceList decode(String taskTreeSpec) { |
---|
| 92 | ITaskInstanceList taskInstanceList = null; |
---|
[1123] | 93 | |
---|
[1146] | 94 | Matcher taskMatcher = taskInstancePattern.matcher(taskTreeSpec); |
---|
[1123] | 95 | |
---|
| 96 | if (taskMatcher.find()) { |
---|
[1146] | 97 | taskInstanceList = parseTaskInstanceList(taskMatcher); |
---|
[1123] | 98 | } |
---|
| 99 | |
---|
| 100 | if (taskMatcher.find()) { |
---|
| 101 | throw new IllegalArgumentException("too many tasks specified"); |
---|
| 102 | } |
---|
| 103 | |
---|
[1327] | 104 | correctTargets(taskInstanceList); |
---|
| 105 | |
---|
[1333] | 106 | // validate the instance list |
---|
| 107 | try { |
---|
| 108 | new TaskTreeValidator().validate(taskInstanceList); |
---|
| 109 | } |
---|
| 110 | catch (java.lang.AssertionError e) { |
---|
| 111 | throw new IllegalArgumentException(e.getMessage(), e); |
---|
| 112 | } |
---|
| 113 | |
---|
[1146] | 114 | return taskInstanceList; |
---|
[1123] | 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * |
---|
| 119 | */ |
---|
[1146] | 120 | private ITaskInstanceList parseTaskInstanceList(Matcher taskMatcher) { |
---|
[1123] | 121 | if ("}".equals(taskMatcher.group(1))) { |
---|
[1146] | 122 | throw new IllegalArgumentException("invalid task instance list specification"); |
---|
[1123] | 123 | } |
---|
| 124 | |
---|
| 125 | String taskDetails = taskMatcher.group(1); |
---|
| 126 | |
---|
[1146] | 127 | Matcher matcher = taskInstanceDetailsPattern.matcher(taskDetails); |
---|
[1123] | 128 | |
---|
| 129 | if (!matcher.find()) { |
---|
| 130 | throw new IllegalArgumentException("could not parse task details"); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | String type = matcher.group(1); |
---|
| 134 | |
---|
[1146] | 135 | ITaskInstanceList list; |
---|
[1123] | 136 | |
---|
[1146] | 137 | if ("UserSession".equals(type)) { |
---|
| 138 | list = taskFactory.createUserSession(); |
---|
[1123] | 139 | } |
---|
[1146] | 140 | else if ("TaskInstances".equals(type)) { |
---|
| 141 | list = taskFactory.createNewTaskInstance(taskFactory.createNewSequence()); |
---|
[1123] | 142 | } |
---|
[1146] | 143 | else { |
---|
| 144 | throw new IllegalArgumentException("unknown type of task instance list: " + type); |
---|
[1123] | 145 | } |
---|
[1146] | 146 | |
---|
| 147 | while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { |
---|
| 148 | ITaskInstance childInstance = parseTaskInstance(taskMatcher); |
---|
| 149 | |
---|
| 150 | if (!(list instanceof IUserSession)) { |
---|
| 151 | taskBuilder.addChild |
---|
| 152 | ((ISequence) ((ITaskInstance) list).getTask(), childInstance.getTask()); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | taskBuilder.addTaskInstance(list, childInstance); |
---|
[1123] | 156 | } |
---|
[1146] | 157 | |
---|
| 158 | return list; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | * |
---|
| 163 | */ |
---|
| 164 | private ITaskInstance parseTaskInstance(Matcher taskMatcher) { |
---|
| 165 | if ("}".equals(taskMatcher.group(1))) { |
---|
| 166 | throw new IllegalArgumentException("invalid task instance specification"); |
---|
[1123] | 167 | } |
---|
[1146] | 168 | |
---|
| 169 | String taskDetails = taskMatcher.group(1); |
---|
| 170 | |
---|
| 171 | Matcher matcher = taskInstanceDetailsPattern.matcher(taskDetails); |
---|
| 172 | |
---|
| 173 | if (!matcher.find()) { |
---|
| 174 | throw new IllegalArgumentException("could not parse task details"); |
---|
[1123] | 175 | } |
---|
[1146] | 176 | |
---|
| 177 | String type = matcher.group(1); |
---|
| 178 | String id = matcher.group(2); |
---|
[1123] | 179 | |
---|
[1325] | 180 | // determine the children before creating this instance |
---|
| 181 | List<ITaskInstance> children = new LinkedList<ITaskInstance>(); |
---|
| 182 | while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { |
---|
| 183 | children.add(parseTaskInstance(taskMatcher)); |
---|
[1146] | 184 | } |
---|
| 185 | |
---|
[1325] | 186 | // get the model |
---|
| 187 | ITask task = getCreateTask(id, type, children); |
---|
| 188 | |
---|
| 189 | // create the respective instance |
---|
[1294] | 190 | ITaskInstance instance; |
---|
| 191 | |
---|
| 192 | if (task instanceof ISequence) { |
---|
| 193 | instance = taskFactory.createNewTaskInstance((ISequence) task); |
---|
[1123] | 194 | } |
---|
[1294] | 195 | else if (task instanceof ISelection) { |
---|
| 196 | instance = taskFactory.createNewTaskInstance((ISelection) task); |
---|
| 197 | } |
---|
| 198 | else if (task instanceof IIteration) { |
---|
| 199 | instance = taskFactory.createNewTaskInstance((IIteration) task); |
---|
| 200 | } |
---|
| 201 | else if (task instanceof IOptional) { |
---|
| 202 | instance = taskFactory.createNewTaskInstance((IOptional) task); |
---|
| 203 | } |
---|
| 204 | else { |
---|
[1327] | 205 | Event event = createUserInteractionEvent(type, id, matcher.group(4)); |
---|
[1325] | 206 | instance = taskFactory.createNewTaskInstance((IEventTask) task, event); |
---|
[1294] | 207 | } |
---|
[1146] | 208 | |
---|
[1325] | 209 | // add the children to the instance |
---|
| 210 | for (ITaskInstance childInstance : children) { |
---|
| 211 | if (instance instanceof ISequenceInstance) { |
---|
| 212 | taskBuilder.addChild((ISequenceInstance) instance, childInstance); |
---|
[1123] | 213 | } |
---|
[1325] | 214 | else if (instance instanceof ISelectionInstance) { |
---|
| 215 | if (((ISelectionInstance) instance).getChild() == null) { |
---|
| 216 | taskBuilder.setChild((ISelectionInstance) instance, childInstance); |
---|
[1123] | 217 | } |
---|
[1325] | 218 | else { |
---|
| 219 | throw new IllegalArgumentException("can not add several children to one " + |
---|
| 220 | "selection instance"); |
---|
[1123] | 221 | } |
---|
| 222 | } |
---|
[1325] | 223 | else if (instance instanceof IIterationInstance) { |
---|
| 224 | taskBuilder.addChild((IIterationInstance) instance, childInstance); |
---|
| 225 | } |
---|
| 226 | else if (instance instanceof IOptionalInstance) { |
---|
| 227 | if (((IOptionalInstance) instance).getChild() == null) { |
---|
| 228 | taskBuilder.setChild((IOptionalInstance) instance, childInstance); |
---|
[1123] | 229 | } |
---|
[1325] | 230 | else { |
---|
| 231 | throw new IllegalArgumentException("can not add several children to one " + |
---|
| 232 | "optional instance"); |
---|
[1123] | 233 | } |
---|
| 234 | } |
---|
[1325] | 235 | } |
---|
| 236 | |
---|
| 237 | return instance; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /** |
---|
| 241 | * |
---|
| 242 | */ |
---|
| 243 | private ITask getCreateTask(String id, String type, List<ITaskInstance> children) { |
---|
[1327] | 244 | String effectiveId = id; |
---|
| 245 | ITask task = tasks.get(effectiveId); |
---|
[1325] | 246 | |
---|
| 247 | if (task == null) { |
---|
| 248 | if ("Sequence".equals(type)) { |
---|
| 249 | task = taskFactory.createNewSequence(); |
---|
[1123] | 250 | } |
---|
[1325] | 251 | else if ("Selection".equals(type)) { |
---|
| 252 | task = taskFactory.createNewSelection(); |
---|
[1294] | 253 | } |
---|
[1325] | 254 | else if ("Iteration".equals(type)) { |
---|
| 255 | task = taskFactory.createNewIteration(); |
---|
[1294] | 256 | } |
---|
[1325] | 257 | else if ("Optional".equals(type)) { |
---|
| 258 | task = taskFactory.createNewOptional(); |
---|
[1294] | 259 | } |
---|
[1325] | 260 | else { |
---|
[1327] | 261 | effectiveId = type + " --> " + id; |
---|
| 262 | task = tasks.get(effectiveId); |
---|
| 263 | |
---|
| 264 | if (task == null) { |
---|
| 265 | task = taskFactory.createNewEventTask(effectiveId); |
---|
| 266 | } |
---|
[1325] | 267 | } |
---|
[1327] | 268 | tasks.put(effectiveId, task); |
---|
[1325] | 269 | |
---|
| 270 | for (ITaskInstance childInstance : children) { |
---|
| 271 | if (task instanceof ISequence) { |
---|
| 272 | taskBuilder.addChild((ISequence) task, childInstance.getTask()); |
---|
| 273 | } |
---|
| 274 | else if (task instanceof ISelection) { |
---|
| 275 | taskBuilder.addChild((ISelection) task, childInstance.getTask()); |
---|
| 276 | } |
---|
| 277 | else if (task instanceof IIteration) { |
---|
| 278 | if (((IIteration) task).getMarkedTask() == null) { |
---|
| 279 | taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask()); |
---|
| 280 | } |
---|
| 281 | else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) { |
---|
| 282 | throw new IllegalArgumentException |
---|
| 283 | ("can not add more than one child to an iteration"); |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | else if (task instanceof IOptional) { |
---|
| 287 | if (((IOptional) task).getMarkedTask() == null) { |
---|
| 288 | taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask()); |
---|
| 289 | } |
---|
| 290 | else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) { |
---|
| 291 | throw new IllegalArgumentException |
---|
| 292 | ("can not add more than one child to an optional"); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | else { |
---|
| 296 | throw new IllegalArgumentException("can not add children to something that " + |
---|
| 297 | "is no sequence, selection, iteration, or " + |
---|
| 298 | "optional"); |
---|
| 299 | } |
---|
[1294] | 300 | } |
---|
[1123] | 301 | } |
---|
[1325] | 302 | else if ("Selection".equals(type)) { |
---|
| 303 | // update the selection with further alternatives, if specified by the current |
---|
| 304 | // child instance |
---|
| 305 | if (children.size() == 1) { |
---|
| 306 | ITask newChildTask = children.get(0).getTask(); |
---|
| 307 | |
---|
| 308 | boolean found = false; |
---|
| 309 | for (ITask childTask : ((ISelection) task).getChildren()) { |
---|
| 310 | if (childTask.equals(newChildTask)) { |
---|
| 311 | found = true; |
---|
| 312 | break; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | if (!found) { |
---|
| 317 | taskBuilder.addChild((ISelection) task, newChildTask); |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | } |
---|
[1333] | 321 | else if ("Optional".equals(type)) { |
---|
| 322 | // update the optional with what is optional if available |
---|
| 323 | if (children.size() == 1) { |
---|
| 324 | ITask newChildTask = children.get(0).getTask(); |
---|
| 325 | |
---|
| 326 | if (((IOptional) task).getMarkedTask() == null) { |
---|
| 327 | taskBuilder.setMarkedTask((IOptional) task, newChildTask); |
---|
| 328 | } |
---|
| 329 | else if (!((IOptional) task).getMarkedTask().equals(newChildTask)) { |
---|
| 330 | throw new IllegalArgumentException("all children of the same optional must " + |
---|
| 331 | "be of an identical task model."); |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | } |
---|
[1123] | 335 | |
---|
[1325] | 336 | return task; |
---|
[1123] | 337 | } |
---|
| 338 | |
---|
[1212] | 339 | /** |
---|
| 340 | * <p> |
---|
| 341 | * </p> |
---|
| 342 | * |
---|
| 343 | * @param matcher |
---|
| 344 | * @return |
---|
| 345 | */ |
---|
[1325] | 346 | private Event createUserInteractionEvent(String type, String targetId, String furtherInfo) { |
---|
| 347 | IEventTarget eventTarget = targets.get(targetId); |
---|
[1294] | 348 | if (eventTarget == null) { |
---|
[1327] | 349 | eventTarget = new DummyGUIElement(targetId); |
---|
[1325] | 350 | targets.put(targetId, eventTarget); |
---|
[1202] | 351 | } |
---|
[1327] | 352 | |
---|
[1325] | 353 | IEventType eventType = determineType(type, furtherInfo); |
---|
[1294] | 354 | |
---|
[1325] | 355 | return new Event(eventType, eventTarget); |
---|
[1212] | 356 | } |
---|
[1202] | 357 | |
---|
[1212] | 358 | /** |
---|
| 359 | * <p> |
---|
| 360 | * </p> |
---|
| 361 | * |
---|
| 362 | * @param type |
---|
| 363 | * @param enteredText |
---|
| 364 | * @return |
---|
| 365 | */ |
---|
[1333] | 366 | private IEventType determineType(String type, String additionalInfo) { |
---|
[1327] | 367 | if ("TextInput".equals(type)) { |
---|
[1333] | 368 | return new TextInput(additionalInfo, new ArrayList<Event>()); |
---|
[1212] | 369 | } |
---|
[1333] | 370 | else if ("Scroll".equals(type)) { |
---|
| 371 | int x = 0; |
---|
| 372 | int y = 0; |
---|
| 373 | if (additionalInfo != null) { |
---|
| 374 | String[] parts = additionalInfo.split(" "); |
---|
| 375 | if (parts.length > 0) { |
---|
| 376 | try { |
---|
| 377 | x = Integer.parseInt(parts[0]); |
---|
| 378 | } |
---|
| 379 | catch (NumberFormatException e) { |
---|
| 380 | throw new IllegalArgumentException("could not parse scroll coordinates", e); |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | if (parts.length > 1) { |
---|
| 384 | try { |
---|
| 385 | y = Integer.parseInt(parts[1]); |
---|
| 386 | } |
---|
| 387 | catch (NumberFormatException e) { |
---|
| 388 | throw new IllegalArgumentException("could not parse scroll coordinates", e); |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | return new Scroll(x, y); |
---|
| 393 | } |
---|
[1212] | 394 | else { |
---|
[1327] | 395 | return new StringEventType(type); |
---|
[1212] | 396 | } |
---|
| 397 | } |
---|
[1202] | 398 | |
---|
[1212] | 399 | /** |
---|
| 400 | * |
---|
| 401 | */ |
---|
[1327] | 402 | private void correctTargets(ITaskInstanceList taskInstanceList) { |
---|
| 403 | Set<IEventTarget> textInputTargets = new HashSet<IEventTarget>(); |
---|
| 404 | |
---|
| 405 | for (ITaskInstance instance : taskInstanceList) { |
---|
| 406 | getTextInputTargets(instance, textInputTargets); |
---|
[1212] | 407 | } |
---|
[1327] | 408 | |
---|
| 409 | Map<IEventTarget, IEventTarget> replacements = new HashMap<IEventTarget, IEventTarget>(); |
---|
| 410 | |
---|
| 411 | for (IEventTarget oldTarget : textInputTargets) { |
---|
| 412 | replacements.put(oldTarget, new DummyTextField(oldTarget.toString())); |
---|
[1212] | 413 | } |
---|
[1327] | 414 | |
---|
| 415 | for (int i = 0; i < taskInstanceList.size(); i++) { |
---|
| 416 | taskBuilder.setTaskInstance |
---|
| 417 | (taskInstanceList, i, replaceTargets(taskInstanceList.get(i), replacements)); |
---|
| 418 | } |
---|
| 419 | |
---|
[1212] | 420 | } |
---|
| 421 | |
---|
[1327] | 422 | /** |
---|
| 423 | * |
---|
| 424 | */ |
---|
| 425 | private void getTextInputTargets(ITaskInstance instance, Set<IEventTarget> textInputTargets) { |
---|
| 426 | if (instance instanceof ISequenceInstance) { |
---|
| 427 | for (ITaskInstance child : (ISequenceInstance) instance) { |
---|
| 428 | getTextInputTargets(child, textInputTargets); |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | else if (instance instanceof ISelectionInstance) { |
---|
| 432 | getTextInputTargets(((ISelectionInstance) instance).getChild(), textInputTargets); |
---|
| 433 | } |
---|
| 434 | else if (instance instanceof IIterationInstance) { |
---|
| 435 | for (ITaskInstance child : (IIterationInstance) instance) { |
---|
| 436 | getTextInputTargets(child, textInputTargets); |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | else if (instance instanceof IOptionalInstance) { |
---|
| 440 | getTextInputTargets(((IOptionalInstance) instance).getChild(), textInputTargets); |
---|
| 441 | } |
---|
| 442 | else if ((instance instanceof IEventTaskInstance) && |
---|
| 443 | (((IEventTaskInstance) instance).getEvent().getType() instanceof TextInput)) |
---|
| 444 | { |
---|
| 445 | textInputTargets.add(((IEventTaskInstance) instance).getEvent().getTarget()); |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | /** |
---|
| 450 | * |
---|
| 451 | */ |
---|
| 452 | private ITaskInstance replaceTargets(ITaskInstance instance, |
---|
| 453 | Map<IEventTarget, IEventTarget> replacements) |
---|
| 454 | { |
---|
| 455 | ITaskInstance replacement = instance; |
---|
| 456 | if (instance instanceof ITaskInstanceList) { |
---|
| 457 | for (int i = 0; i < ((ITaskInstanceList) instance).size(); i++) { |
---|
| 458 | taskBuilder.setTaskInstance |
---|
| 459 | ((ITaskInstanceList) instance, i, |
---|
| 460 | replaceTargets(((ITaskInstanceList) instance).get(i), replacements)); |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | else if (instance instanceof ISelectionInstance) { |
---|
| 464 | ISelectionInstance selInst = (ISelectionInstance) instance; |
---|
| 465 | taskBuilder.setChild(selInst, replaceTargets(selInst.getChild(), replacements)); |
---|
| 466 | } |
---|
| 467 | else if (instance instanceof IOptionalInstance) { |
---|
| 468 | IOptionalInstance optInst = (IOptionalInstance) instance; |
---|
[1333] | 469 | if (optInst.getChild() != null) { |
---|
| 470 | taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); |
---|
| 471 | } |
---|
[1327] | 472 | } |
---|
| 473 | else if ((instance instanceof IEventTaskInstance) && |
---|
| 474 | (replacements.containsKey(((IEventTaskInstance) instance).getEvent().getTarget()))) |
---|
| 475 | { |
---|
| 476 | Event origEvent = ((IEventTaskInstance) instance).getEvent(); |
---|
| 477 | replacement = taskFactory.createNewTaskInstance |
---|
| 478 | (((IEventTaskInstance) instance).getEventTask(), |
---|
| 479 | new Event(origEvent.getType(), replacements.get(origEvent.getTarget()))); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | return replacement; |
---|
| 483 | } |
---|
| 484 | |
---|
[1123] | 485 | } |
---|