KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

24     // Constants
25

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

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

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

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

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

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

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

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

115     /**
116      * Retrieves all known events.
117      *
118      * @return all known events.
119      * @exception com.teamkonzept.lib.TKException if an error occured during event retrieval.
120      */

121     public final TKVector getEvents ()
122         throws TKException
123     {
124         return getObjects();
125     }
126
127     /**
128      * Retrieves the specified event.
129      *
130      * @param id the ID of the event.
131      * @return the specified event.
132      * @exception com.teamkonzept.lib.TKException if an error occured during event retrieval.
133      */

134     public final Event getEvent (Integer JavaDoc id)
135         throws TKException
136     {
137         return (Event) getObject(id);
138     }
139     
140     /**
141      * Retrieves the specified event.
142      *
143      * @param name the name of the event.
144      * @return the specified event.
145      * @exception com.teamkonzept.lib.TKException if an error occured during event retrieval.
146      */

147     public final Event getEvent (String JavaDoc name)
148         throws TKException
149     {
150         Event event = null;
151
152         try
153         {
154             // Create appropriate data.
155
EventDBData data = new EventDBData(null, name);
156             data.setQuery(EventDBInterface.WM_EVENT_SELECT_BY_NAME);
157             data.setPrototype(new ObjectCollectionDBData(null,
158                                                            null,
159                                                            EventDBInterface.PRIMARY_KEY_NAME,
160                                                            null));
161
162             // Database lookup.
163
TKVector id = getObjectIDs(data);
164
165             if (id != null && id.size() == 1)
166             {
167                 event = (Event) getObject((Integer JavaDoc) id.firstElement());
168             }
169         }
170         catch (Exception JavaDoc x)
171         {
172             throw WebmanExceptionHandler.getException(x);
173         }
174
175         return event;
176     }
177
178     /**
179      * Retrieves all event IDs referenced by the specified policy.
180      *
181      * @param policy the ID of the policy.
182      * @return all event IDs referenced by the specified policy.
183      * @exception com.teamkonzept.lib.TKException if an error occured during event retrieval.
184      */

185     public final TKVector getEventProxies (Integer JavaDoc policy)
186         throws TKException
187     {
188         TKVector proxies = null;
189
190         try
191         {
192             // Create appropriate data.
193
EventDBData data = new EventDBData((Integer JavaDoc) null, null);
194             data.setQuery(EventDBInterface.WM_EVENT_SELECT_BY_POLICY);
195             data.setPrototype(new ObjectCollectionDBData(PolicyDBInterface.PRIMARY_KEY_NAME,
196                                                            policy,
197                                                            EventDBInterface.PRIMARY_KEY_NAME,
198                                                            null));
199
200             // Database lookup.
201
proxies = getObjectIDs(data);
202         }
203         catch (Exception JavaDoc x)
204         {
205             throw WebmanExceptionHandler.getException(x);
206         }
207
208         return proxies;
209     }
210
211     /**
212      * Retrieves all event IDs referenced by the specified policy.
213      *
214      * @param login the ID of the login (<I>required</I>).
215      * @param context the ID of the context (<I>optional</I>).
216      * @param type the object type (<I>optional</I>).
217      * @param reference the object reference (<I>optional</I>).
218      * @param access the access mode of the policy.
219      * @return all event IDs referenced by the specified policy.
220      * @exception com.teamkonzept.lib.TKException if an error occured during event retrieval.
221      */

222     public final TKVector getEventProxies (Integer JavaDoc login,
223                                            Integer JavaDoc context,
224                                            Integer JavaDoc type,
225                                            Integer JavaDoc reference,
226                                            boolean access)
227         throws TKException
228     {
229         TKVector proxies = null;
230
231         try
232         {
233             // Create appropriate data.
234
EventDBData data = new EventDBData((Integer JavaDoc) null, null);
235             data.setQuery(EventDBInterface.WM_EVENT_SELECT_BY_POLICY_ATTRIBUTES);
236             data.setPrototype(new EventCollectionDBData(login,
237                                                           context,
238                                                           type,
239                                                           reference,
240                                                           access
241                                                             ? PolicyDBInterface.MODE_ALLOW
242                                                             : PolicyDBInterface.MODE_DENY));
243
244             // Database lookup.
245
proxies = getObjectIDs(data);
246         }
247         catch (Exception JavaDoc x)
248         {
249             throw WebmanExceptionHandler.getException(x);
250         }
251
252         return proxies;
253     }
254
255     /**
256      * Creates the specified event.
257      *
258      * @param name the name of the event.
259      * @return the specified event.
260      * @exception com.teamkonzept.lib.TKException if an error occured during event creation.
261      */

262     public final Event createEvent (String JavaDoc name)
263         throws TKException
264     {
265         return (Event) createObject(new EventDBData(null, name));
266     }
267
268     /**
269      * Modifies the given event.
270      *
271      * @param event the event to be modified.
272      * @exception com.teamkonzept.lib.TKException if an error occured during event modification.
273      */

274     public final void modifyEvent (Event event)
275         throws TKException
276     {
277         if (event.isModifiedAssociations())
278         {
279             ResolverFactory.getInstance().removeResolvers();
280         }
281
282         modifyObject(event);
283     }
284
285     /**
286      * Deletes the given event.
287      *
288      * @param event the event to be deleted.
289      * @exception com.teamkonzept.lib.TKException if an error occured during event deletion.
290      */

291     public final void deleteEvent (Event event)
292         throws TKException
293     {
294         ResolverFactory.getInstance().removeResolvers();
295
296         deleteObject(event);
297     }
298
299 }
300
Popular Tags