KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > TaskFactory


1 package de.webman.acl;
2
3 import com.teamkonzept.lib.ConfigurationManager;
4 import com.teamkonzept.lib.TKException;
5 import com.teamkonzept.lib.TKVector;
6 import de.webman.acl.db.*;
7 import de.webman.acl.resolver.ResolverFactory;
8 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
9
10 /**
11  * Factory for task objects.
12  *
13  * @version 1.0
14  * @since 1.0
15  * @author © 2001 Webman AG
16  */

17 public class TaskFactory
18     extends ObjectFactoryBase
19     implements ObjectFactory
20 {
21
22     // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/TaskFactory.java,v 1.1 2001/08/20 08:25:07 mischa Exp $
23

24     // Constants
25

26     /**
27      * Singleton instance.
28      */

29     private static TaskFactory SINGLETON = null;
30
31
32     // Constructors
33

34     /**
35      * Inhibits instantiation from outside.
36      */

37     private TaskFactory ()
38     {
39         super();
40     }
41
42
43     // Instance
44

45     /**
46      * Returns the singleton instance of the factory.
47      *
48      * @return the singleton instance of the factory.
49      * @exception com.teamkonzept.lib.TKException if an error occured during initialization.
50      */

51     public static synchronized final TaskFactory getInstance ()
52         throws TKException
53     {
54         if (SINGLETON == null)
55         {
56             SINGLETON = new TaskFactory();
57             SINGLETON.configurationChanged();
58             ConfigurationManager.getInstance()
59                                 .registerConfigurationListener(SINGLETON,
60                                                                PROPERTY_GROUP_NAME);
61         }
62
63         return SINGLETON;
64     }
65
66
67     // Method implementations
68

69     /**
70      * Retrieves the task database interface.
71      *
72      * @return the task database interface.
73      */

74     public final ObjectDBInterface getDBInterface ()
75     {
76         return TaskDBInterface.getInstance();
77     }
78
79     /**
80      * Retrieves a task data wrapper.
81      *
82      * @param id the ID of the task.
83      * @return a task data wrapper.
84      */

85     public final ObjectDBData getDBData (Integer JavaDoc id)
86     {
87         return new TaskDBData(id, null, null);
88     }
89
90     /**
91      * Retrieves a task data wrapper.
92      *
93      * @param object the task.
94      * @return a task data wrapper.
95      */

96     public final ObjectDBData getDBData (WMObject object)
97     {
98         return new TaskDBData((Task) object);
99     }
100
101     /**
102      * Builds a concrete task object.
103      *
104      * @param data the initial task data.
105      * @return a concrete task object.
106      */

107     public final WMObject buildObject (ObjectDBData data)
108     {
109         return new Task((TaskDBData) data);
110     }
111
112
113     // Convenience methods
114

115     /**
116      * Retrieves the specified task.
117      *
118      * @param id the ID of the task.
119      * @return the specified task.
120      * @exception com.teamkonzept.lib.TKException if an error occured during task retrieval.
121      */

122     public final Task getTask (Integer JavaDoc id)
123         throws TKException
124     {
125         return (Task) getObject(id);
126     }
127
128     /**
129      * Retrieves all known tasks.
130      *
131      * @return all known tasks.
132      * @exception com.teamkonzept.lib.TKException if an error occured during task retrieval.
133      */

134     public final TKVector getTasks ()
135         throws TKException
136     {
137         return getObjects();
138     }
139
140     /**
141      * Retrieves the specified tasks.
142      *
143      * @param ids the IDs of the tasks.
144      * @return the specified tasks.
145      * @exception com.teamkonzept.lib.TKException if an error occured during task retrieval.
146      */

147     public final TKVector getTasks (TKVector ids)
148         throws TKException
149     {
150         return getObjects(ids);
151     }
152
153     /**
154      * Retrieves all tasks referenced by the given context.
155      *
156      * @param context the context.
157      * @return all tasks referenced by the given context.
158      * @exception com.teamkonzept.lib.TKException if an error occured during task retrieval.
159      */

160     public final TKVector getTasks (Context context)
161         throws TKException
162     {
163         TKVector objects = null;
164
165         try
166         {
167             // Create appropriate data.
168
TaskDBData data = new TaskDBData((Integer JavaDoc) null, null, context.getID());
169             data.setQuery(TaskDBInterface.WM_TASK_SELECT_BY_CONTEXT);
170             data.setPrototype(new ObjectCollectionDBData(null,
171                                                            null,
172                                                            TaskDBInterface.PRIMARY_KEY_NAME,
173                                                            null));
174
175             // Database lookup.
176
objects = getObjects(getObjectIDs(data));
177         }
178         catch (Exception JavaDoc x)
179         {
180             throw WebmanExceptionHandler.getException(x);
181         }
182
183         return objects;
184     }
185
186     /**
187      * Retrieves all tasks referenced by the given action.
188      *
189      * @param action the action.
190      * @return all tasks referenced by the given action.
191      * @exception com.teamkonzept.lib.TKException if an error occured during task retrieval.
192      */

193     public final TKVector getTasks (Action action)
194         throws TKException
195     {
196         TKVector objects = null;
197
198         try
199         {
200             // Create appropriate data.
201
TaskDBData data = new TaskDBData((Integer JavaDoc) null, null, null);
202             data.setQuery(TaskDBInterface.WM_TASK_ACTION_SELECT_BY_ACTION);
203             data.setPrototype(new ObjectCollectionDBData(ActionDBInterface.PRIMARY_KEY_NAME,
204                                                            action.getID(),
205                                                            TaskDBInterface.PRIMARY_KEY_NAME,
206                                                            null));
207
208             // Database lookup.
209
objects = getObjects(getObjectIDs(data));
210         }
211         catch (Exception JavaDoc x)
212         {
213             throw WebmanExceptionHandler.getException(x);
214         }
215
216         return objects;
217     }
218
219     /**
220      * Creates the specified task.
221      *
222      * @param name the name of the task.
223      * @param context the context of the task.
224      * @return the specified task.
225      * @exception com.teamkonzept.lib.TKException if an error occured during task creation.
226      */

227     public final Task createTask (String JavaDoc name,
228                                     Context context)
229         throws TKException
230     {
231         return (Task) createObject(new TaskDBData(null,
232                                                       name,
233                                                       context.getID()));
234     }
235
236     /**
237      * Modifies the given task.
238      *
239      * @param task the task to be modified.
240      * @exception com.teamkonzept.lib.TKException if an error occured during task modification.
241      */

242     public final void modifyTask (Task task)
243         throws TKException
244     {
245         if (task.isModifiedAssociations())
246         {
247             ResolverFactory.getInstance().removeResolvers();
248         }
249
250         modifyObject(task);
251     }
252
253     /**
254      * Deletes the given task.
255      *
256      * @param task the task to be deleted.
257      * @exception com.teamkonzept.lib.TKException if an error occured during task deletion.
258      */

259     public final void deleteTask (Task task)
260         throws TKException
261     {
262         ResolverFactory.getInstance().removeResolvers();
263
264         deleteObject(task);
265     }
266
267 }
268
Popular Tags