KickJava   Java API By Example, From Geeks To Geeks.

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


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 profile objects.
10  *
11  * @version 1.0
12  * @since 1.0
13  * @author © 2001 Webman AG
14  */

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

21     // Constants
22

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

26     private static ProfileFactory 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 ProfileFactory (LoginFactory factory)
45         throws TKException
46     {
47         this.factory = factory;
48     }
49
50
51     // Instance
52

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

285     public final void deleteProfile (Profile profile)
286         throws TKException
287     {
288         deleteObject(profile);
289     }
290
291 }
292
Popular Tags