KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

24     // Constants
25

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

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

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

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

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

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

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

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

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

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

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

147     public final TKVector getActions (Event event)
148         throws TKException
149     {
150         TKVector objects = null;
151
152         try
153         {
154             // Create appropriate data.
155
ActionDBData data = new ActionDBData((Integer JavaDoc) null, null);
156             data.setQuery(ActionDBInterface.WM_ACTION_EVENT_SELECT_BY_EVENT);
157             data.setPrototype(new ObjectCollectionDBData(EventDBInterface.PRIMARY_KEY_NAME,
158                                                            event.getID(),
159                                                            ActionDBInterface.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 action.
175      *
176      * @param name the name of the action.
177      * @return the specified action.
178      * @exception com.teamkonzept.lib.TKException if an error occured during action creation.
179      */

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

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

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