KickJava   Java API By Example, From Geeks To Geeks.

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


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

15 public class UserFactory
16     implements ObjectFactory
17 {
18
19     // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/UserFactory.java,v 1.1 2001/08/20 08:25:07 mischa Exp $
20

21     // Constants
22

23     /**
24      * Singleton instance.
25      */

26     private static UserFactory SINGLETON = null;
27
28
29     // Attributes
30

31     /**
32      * The delegate factory.
33      */

34     private LoginFactory factory = null;
35
36
37     // Constructors
38

39     /**
40      * Inhibits instantiation from outside.
41      *
42      * @param factory the parent factory.
43      */

44     private UserFactory (LoginFactory factory)
45     {
46         this.factory = factory;
47     }
48
49
50     // Instance
51

52     /**
53      * Returns the singleton instance of the factory.
54      *
55      * @return the singleton instance of the factory.
56      * @exception com.teamkonzept.lib.TKException if an error occured during initialization.
57      */

58     public static synchronized final UserFactory getInstance ()
59         throws TKException
60     {
61         if (SINGLETON == null)
62         {
63             SINGLETON = new UserFactory(LoginFactory.getInstance());
64         }
65
66         return SINGLETON;
67     }
68
69
70     // Method implementations
71

72     /**
73      * Informs the factory about changes in its configuration.
74      *
75      * @exception com.teamkonzept.lib.TKException if an error occured during configuration.
76      */

77     public final void configurationChanged ()
78         throws TKException
79     {
80         this.factory.configurationChanged();
81     }
82
83     /**
84      * Retrieves the specified object.
85      *
86      * @param id the specifiying ID of the object.
87      * @return the specified object.
88      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
89      */

90     public final WMObject getObject (Integer JavaDoc id)
91         throws TKException
92     {
93         return this.factory.getObject(id);
94     }
95
96     /**
97      * Retrieves all known objects.
98      *
99      * @return all known objects.
100      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
101      */

102     public final TKVector getObjects ()
103         throws TKException
104     {
105         return this.factory.getObjects(getObjectIDs());
106     }
107
108     /**
109      * Retrieves the specified objects.
110      *
111      * @param ids the specifiying IDs of the objects.
112      * @return the specified objects.
113      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
114      */

115     public TKVector getObjects (TKVector ids)
116         throws TKException
117     {
118         return this.factory.getObjects(ids);
119     }
120
121     /**
122      * Retrieves all known object IDs.
123      *
124      * @return all known object IDs.
125      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
126      */

127     public final TKVector getObjectIDs ()
128         throws TKException
129     {
130         TKVector proxies = null;
131
132         try
133         {
134             // Create appropriate data.
135
LoginDBData data = new LoginDBData(null, null, null, LoginDBInterface.TYPE_USER);
136             data.setQuery(LoginDBInterface.WM_USER_SELECT_BY_TYPE);
137             data.setPrototype(new ObjectCollectionDBData(null,
138                                                            null,
139                                                            LoginDBInterface.PRIMARY_KEY_NAME,
140                                                            null));
141
142             // Database lookup.
143
proxies = getObjectIDs(data);
144         }
145         catch (Exception JavaDoc x)
146         {
147             throw WebmanExceptionHandler.getException(x);
148         }
149
150         return proxies;
151     }
152
153     /**
154      * Retrieves the specified object IDs.
155      *
156      * @param data the specifiying data of the objects.
157      * @return the specified object IDs.
158      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
159      */

160     public final TKVector getObjectIDs (ObjectDBData data)
161         throws TKException
162     {
163         return this.factory.getObjectIDs(data);
164     }
165
166     /**
167      * Retrieves the associated object IDs.
168      *
169      * @param object the object.
170      * @return the associated object IDs.
171      * @exception com.teamkonzept.lib.TKException if an error occured during object retrieval.
172      */

173     public final TKVector getObjectAssociations (WMObject object)
174         throws TKException
175     {
176         return this.factory.getObjectAssociations(object);
177     }
178
179     /**
180      * Creates the specified object.
181      *
182      * @param data the specifying object data.
183      * @return the specified object.
184      * @exception com.teamkonzept.lib.TKException if an error occured during object creation.
185      */

186     public final WMObject createObject (ObjectDBData data)
187         throws TKException
188     {
189         return this.factory.createObject(data);
190     }
191
192     /**
193      * Modifies the given object.
194      *
195      * @param object the object.
196      * @exception com.teamkonzept.lib.TKException if an error occured during object modification.
197      */

198     public final void modifyObject (WMObject object)
199         throws TKException
200     {
201         this.factory.modifyObject(object);
202     }
203
204     /**
205      * Deletes the given object.
206      *
207      * @param object the object.
208      * @exception com.teamkonzept.lib.TKException if an error occured during object deletion.
209      */

210     public final void deleteObject (WMObject object)
211         throws TKException
212     {
213         this.factory.deleteObject(object);
214     }
215
216
217     // Convenience methods
218

219     /**
220      * Retrieves the specified user.
221      *
222      * @param id the ID of the user.
223      * @return the specified user.
224      * @exception com.teamkonzept.lib.TKException if an error occured during user retrieval.
225      */

226     public final User getUser (Integer JavaDoc id)
227         throws TKException
228     {
229         return (User) getObject(id);
230     }
231
232     /**
233      * Retrieves all known users.
234      *
235      * @return all known users.
236      * @exception com.teamkonzept.lib.TKException if an error occured during user retrieval.
237      */

238     public final TKVector getUsers ()
239         throws TKException
240     {
241         return getObjects();
242     }
243
244     /**
245      * Creates the specified user.
246      *
247      * @param login the login of the user.
248      * @param name the name of the user.
249      * @return the specified user.
250      * @exception com.teamkonzept.lib.TKException if an error occured during user creation.
251      */

252     public final User createUser (String JavaDoc login,
253                                     String JavaDoc name)
254         throws TKException
255     {
256         // Check login token.
257
this.factory.checkLogin(login);
258
259         // Proceed if no errors occur.
260
return (User) createObject(new LoginDBData(null,
261                                                        login,
262                                                        name,
263                                                        LoginDBInterface.TYPE_USER));
264     }
265
266     /**
267      * Modifies the given user.
268      *
269      * @param user the user to be modified.
270      * @exception com.teamkonzept.lib.TKException if an error occured during user modification.
271      */

272     public final void modifyUser (User user)
273         throws TKException
274     {
275         modifyObject(user);
276     }
277
278     /**
279      * Deletes the given user.
280      *
281      * @param user the user to be deleted.
282      * @exception com.teamkonzept.lib.TKException if an error occured during user deletion.
283      */

284     public final void deleteUser (User user)
285         throws TKException
286     {
287         deleteObject(user);
288     }
289
290 }
291
Popular Tags