KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

24     // Constants
25

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

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

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

37     private RoleFactory ()
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 RoleFactory getInstance ()
52         throws TKException
53     {
54         if (SINGLETON == null)
55         {
56             SINGLETON = new RoleFactory();
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      * Returns the role database interface.
71      *
72      * @return the role database interface.
73      */

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

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

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

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

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

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

134     public final TKVector getRoles ()
135         throws TKException
136     {
137         return getObjects();
138     }
139
140     /**
141      * Retrieves all roles referenced by the given task.
142      *
143      * @param task the task.
144      * @return all roles referenced by the given task.
145      * @exception com.teamkonzept.lib.TKException if an error occured during role retrieval.
146      */

147     public final TKVector getRoles (Task task)
148         throws TKException
149     {
150         TKVector objects = null;
151
152         try
153         {
154             // Create appropriate data.
155
RoleDBData data = new RoleDBData((Integer JavaDoc) null, null);
156             data.setQuery(RoleDBInterface.WM_ROLE_TASK_SELECT_BY_TASK);
157             data.setPrototype(new ObjectCollectionDBData(TaskDBInterface.PRIMARY_KEY_NAME,
158                                                            task.getID(),
159                                                            RoleDBInterface.PRIMARY_KEY_NAME,
160                                                            null));
161
162             // Database lookup.
163
objects = getObjects(getObjectIDs(data));
164         }
165         catch (Exception JavaDoc x)
166         {
167             throw WebmanExceptionHandler.getException(x);
168         }
169
170         return objects;
171     }
172
173     /**
174      * Creates the specified role.
175      *
176      * @param name the name of the role.
177      * @return the specified role.
178      * @exception com.teamkonzept.lib.TKException if an error occured during role creation.
179      */

180     public final Role createRole (String JavaDoc name)
181         throws TKException
182     {
183         return (Role) createObject(new RoleDBData(null,
184                                                       name));
185     }
186
187     /**
188      * Modifies the given role.
189      *
190      * @param role the role to be modified.
191      * @exception com.teamkonzept.lib.TKException if an error occured during role modification.
192      */

193     public final void modifyRole (Role role)
194         throws TKException
195     {
196         if (role.isModifiedAssociations())
197         {
198             ResolverFactory.getInstance().removeResolvers();
199         }
200
201         modifyObject(role);
202     }
203
204     /**
205      * Deletes the given role.
206      *
207      * @param role the role to be deleted.
208      * @exception com.teamkonzept.lib.TKException if an error occured during role deletion.
209      */

210     public final void deleteRole (Role role)
211         throws TKException
212     {
213         ResolverFactory.getInstance().removeResolvers();
214
215         deleteObject(role);
216     }
217
218 }
219
Popular Tags