source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskFactory.java @ 1588

Last change on this file since 1588 was 1294, checked in by pharms, 11 years ago
  • rework of task model to move event instance stuff to task instances
  • introduction of sequence, selection, iteration and optional instances
  • Property svn:executable set to *
File size: 5.7 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
16
17import java.util.List;
18
19import de.ugoe.cs.autoquest.eventcore.Event;
20import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
21import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
32import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
33
34/**
35 * <p>
36 * this is the default implementation of the interface {@link ITaskFactory}. It
37 * does not do anything fancy except implementing the interface. It instantiates the other
38 * implementations of the tree ifc in this package.
39 * </p>
40 *
41 * @author Patrick Harms
42 */
43public class TaskFactory implements ITaskFactory {
44
45    /* (non-Javadoc)
46     * @see ITaskFactory#createNewEventTask(String)
47     */
48    @Override
49    public IEventTask createNewEventTask(String description) {
50        return new EventTask(description);
51    }
52
53    /* (non-Javadoc)
54     * @see ITaskFactory#createNewSequence()
55     */
56    @Override
57    public ISequence createNewSequence() {
58        return new Sequence();
59    }
60
61    /* (non-Javadoc)
62     * @see ITaskFactory#createNewIteration()
63     */
64    @Override
65    public IIteration createNewIteration() {
66        return new Iteration();
67    }
68
69    /* (non-Javadoc)
70     * @see ITaskFactory#createNewOptional()
71     */
72    @Override
73    public IOptional createNewOptional() {
74        return new Optional();
75    }
76
77    /* (non-Javadoc)
78     * @see ITaskFactory#createNewSelection()
79     */
80    @Override
81    public ISelection createNewSelection() {
82        return new Selection();
83    }
84
85    /* (non-Javadoc)
86     * @see ITaskFactory#createNewTaskInstance(IEventTask, Event)
87     */
88    @Override
89    public IEventTaskInstance createNewTaskInstance(IEventTask task, Event event) {
90        if (!(task instanceof EventTask)) {
91            throw new IllegalArgumentException
92                ("illegal type of event task provided: " + task.getClass());
93        }
94       
95        EventTaskInstance instance = new EventTaskInstance(task, event);
96        ((EventTask) task).addInstance(instance);
97       
98        return instance;
99    }
100
101    /* (non-Javadoc)
102     * @see ITaskFactory#createNewTaskInstance(ISequence)
103     */
104    @Override
105    public ISequenceInstance createNewTaskInstance(ISequence sequence) {
106        if (!(sequence instanceof Sequence)) {
107            throw new IllegalArgumentException
108                ("illegal type of sequence provided: " + sequence.getClass());
109        }
110       
111        SequenceInstance instance = new SequenceInstance(sequence);
112        ((Sequence) sequence).addInstance(instance);
113       
114        return instance;
115    }
116
117    /* (non-Javadoc)
118     * @see ITaskFactory#createNewTaskInstance(IIteration)
119     */
120    @Override
121    public IIterationInstance createNewTaskInstance(IIteration iteration) {
122        if (!(iteration instanceof Iteration)) {
123            throw new IllegalArgumentException
124                ("illegal type of iteration provided: " + iteration.getClass());
125        }
126       
127        IterationInstance instance = new IterationInstance(iteration);
128        ((Iteration) iteration).addInstance(instance);
129       
130        return instance;
131    }
132
133    /* (non-Javadoc)
134     * @see ITaskFactory#createNewTaskInstance(IOptional)
135     */
136    @Override
137    public IOptionalInstance createNewTaskInstance(IOptional optional) {
138        if (!(optional instanceof Optional)) {
139            throw new IllegalArgumentException
140                ("illegal type of optional provided: " + optional.getClass());
141        }
142       
143        OptionalInstance instance = new OptionalInstance(optional);
144        ((Optional) optional).addInstance(instance);
145       
146        return instance;
147    }
148
149    /* (non-Javadoc)
150     * @see ITaskFactory#createNewTaskInstance(ISelection)
151     */
152    @Override
153    public ISelectionInstance createNewTaskInstance(ISelection selection) {
154        if (!(selection instanceof Selection)) {
155            throw new IllegalArgumentException
156                ("illegal type of optional provided: " + selection.getClass());
157        }
158       
159        SelectionInstance instance = new SelectionInstance(selection);
160        ((Selection) selection).addInstance(instance);
161       
162        return instance;
163    }
164
165    /* (non-Javadoc)
166     * @see ITaskFactory#createUserSession()
167     */
168    @Override
169    public IUserSession createUserSession() {
170        return new UserSession();
171    }
172
173    /* (non-Javadoc)
174     * @see ITaskFactory#createTaskModel(List<IUserSession>)
175     */
176    @Override
177    public ITaskModel createTaskModel(List<IUserSession> userSessions) {
178        return new TaskModel(userSessions);
179    }
180
181}
Note: See TracBrowser for help on using the repository browser.