KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.teamkonzept.webman.mainint.WebmanExceptionHandler;
8
9 /**
10  * Factory for property objects.
11  *
12  * @version 1.0
13  * @since 1.0
14  * @author © 2001 Webman AG
15  */

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

23     // Constants
24

25     /**
26      * Singleton instance.
27      */

28     private static PropertyFactory SINGLETON = null;
29
30
31     // Constructors
32

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

36     private PropertyFactory ()
37     {
38         super();
39     }
40
41
42     // Instance
43

44     /**
45      * Returns the singleton instance of the factory.
46      *
47      * @return the singleton instance of the factory.
48      * @exception com.teamkonzept.lib.TKException if an error occured during initialization.
49      */

50     public static synchronized final PropertyFactory getInstance ()
51         throws TKException
52     {
53         if (SINGLETON == null)
54         {
55             SINGLETON = new PropertyFactory();
56             SINGLETON.configurationChanged();
57             ConfigurationManager.getInstance()
58                                 .registerConfigurationListener(SINGLETON,
59                                                                PROPERTY_GROUP_NAME);
60         }
61
62         return SINGLETON;
63     }
64
65
66     // Method implementations
67

68     /**
69      * Returns the property database interface.
70      *
71      * @return the property database interface.
72      */

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

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

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

106     public final WMObject buildObject (ObjectDBData data)
107     {
108         return new Property((PropertyDBData) data);
109     }
110
111
112     // Convenience methods
113

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

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

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

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

181     public final Property createProperty (Login login,
182                                             String JavaDoc name,
183                                             String JavaDoc value)
184         throws TKException
185     {
186         return (Property) createObject(new PropertyDBData(null,
187                                                               login.getID(),
188                                                               name,
189                                                               value));
190     }
191
192     /**
193      * Modifies the given property.
194      *
195      * @param property the property to be modified.
196      * @exception com.teamkonzept.lib.TKException if an error occured during property modification.
197      */

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

210     public final void deleteProperty (Property property)
211         throws TKException
212     {
213         deleteObject(property);
214     }
215
216 }
217
Popular Tags