KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > admin > setting > SettingsBean


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: SettingsBean.java,v $
31  * Revision 1.3 2005/04/10 20:10:04 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:57 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:51:36 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.3 2004/11/12 18:16:07 colinmacleod
45  * Ordered imports.
46  *
47  * Revision 1.2 2004/11/12 15:57:19 colinmacleod
48  * Removed dependencies on SSLEXT.
49  * Moved Persistence classes to ivata masks.
50  *
51  * Revision 1.1 2004/09/30 15:15:59 colinmacleod
52  * Split off addressbook elements into security subproject.
53  *
54  * Revision 1.4 2004/07/13 19:54:31 colinmacleod
55  * Moved project to POJOs from EJBs.
56  * Applied PicoContainer to services layer (replacing session EJBs).
57  * Applied Hibernate to persistence layer (replacing entity EJBs).
58  *
59  * Revision 1.3 2004/03/21 21:16:05 colinmacleod
60  * Shortened name to ivata op.
61  *
62  * Revision 1.2 2004/02/01 22:00:32 colinmacleod
63  * Added full names to author tags
64  *
65  * Revision 1.1.1.1 2004/01/27 20:57:46 colinmacleod
66  * Moved ivata openportal to SourceForge..
67  *
68  * Revision 1.5 2003/11/03 11:28:24 jano
69  * commiting addressbook,
70  * tryinjg to fix deploying problem
71  *
72  * Revision 1.4 2003/10/17 12:36:12 jano
73  * fixing problems with building
74  * converting intranet -> portal
75  * Eclipse building
76  *
77  * Revision 1.3 2003/10/15 13:15:08 jano
78  * converting to XDoclet
79  *
80  * Revision 1.2 2003/10/15 13:04:20 colin
81  * fixing for XDoclet
82  *
83  * Revision 1.6 2003/03/27 16:06:25 peter
84  * getSetting methods are user-override aware
85  *
86  * Revision 1.5 2003/03/05 17:34:13 peter
87  * fixed wrong message name in validation
88  *
89  * Revision 1.4 2003/03/05 11:53:53 peter
90  * fixed fieldName messages in validation
91  *
92  * Revision 1.3 2003/02/25 16:58:31 peter
93  * fixed the logic in setSetting method
94  *
95  * Revision 1.2 2003/02/25 14:38:13 colin
96  * implemented setModified methods on entity beans thro IvataEntityBean superclass
97  *
98  * Revision 1.1 2003/02/24 18:56:14 colin
99  * added to admin
100  *
101  * Revision 1.18 2003/02/24 09:50:39 peter
102  * the enable field is boolean now
103  *
104  * Revision 1.17 2003/02/19 18:21:35 peter
105  * validation now covers all settings show to user worth validation
106  *
107  * Revision 1.16 2003/02/11 10:28:44 peter
108  * added isSettingEnabled method
109  *
110  * Revision 1.15 2003/02/07 14:40:45 peter
111  * added new constants and parameter to validate
112  *
113  * Revision 1.14 2003/02/05 18:14:12 peter
114  * added validate method to SettingsBean
115  *
116  * Revision 1.13 2003/02/05 11:58:06 peter
117  * added getSettingType to SettingsBean
118  *
119  * Revision 1.12 2003/02/04 17:43:50 colin
120  * copyright notice
121  *
122  * Revision 1.11 2003/02/04 13:43:37 peter
123  * newly created settings had no names assigned, fixed
124  *
125  * Revision 1.10 2003/02/04 10:25:44 peter
126  * only user settings can be removed via setSetting
127  *
128  * Revision 1.9 2003/02/04 08:01:02 peter
129  * modified to handle null userDO booth in getSetting and setSetting
130  *
131  * Revision 1.8 2002/11/12 09:37:08 colin
132  * added SettingNullException when a setting doesn't exist
133  *
134  * Revision 1.7 2002/09/25 07:08:12 peter
135  * fixed a bug in setSetting (type of the setting)
136  *
137  * Revision 1.6 2002/08/15 14:29:52 peter
138  * removed initial context instances
139  *
140  * Revision 1.5 2002/08/11 11:49:04 colin
141  * Improved error handling and output messages for non-existant settings
142  *
143  * Revision 1.4 2002/06/17 07:29:02 colin
144  * improved and extended javadoc documentation
145  *
146  * moved setting constants into separate class
147  *
148  * Revision 1.1 2002/04/27 17:36:28 colin
149  * first compliling version in EJB/JBuilder project
150  *
151  * Revision 1.1.1.1 2002/04/22 13:51:47 colin
152  * EJB version of the intranet project
153  *
154  * Revision 1.5 2002/02/03 19:54:25 colin
155  * linked settings to the database, rather than hard-coding in
156  * com.ivata.groupware.admin.settings
157  *
158  * Revision 1.4 2002/02/03 16:49:45 colin
159  * updated javadoc
160  *
161  * Revision 1.3 2002/02/02 21:23:01 colin
162  * major restructuring to make the Settings class more generic
163  * all default settings are now taken from the database rather than being
164  * hard coded in the settings class
165  * settings are stored in a HashMap in settings
166  *
167  * Revision 1.2 2002/01/20 19:28:25 colin
168  * added tab and tree tags
169  * implemented address book functionality
170  *
171  * Revision 1.1.1.1 2001/10/06 15:40:20 colin
172  * initial import into cvs
173  * -----------------------------------------------------------------------------
174  */

175 package com.ivata.groupware.admin.setting;
176
177 import java.util.Locale JavaDoc;
178 import java.util.Map JavaDoc;
179
180 import javax.ejb.SessionBean JavaDoc;
181 import javax.ejb.SessionContext JavaDoc;
182
183 import org.picocontainer.PicoContainer;
184
185 import com.ivata.groupware.admin.security.server.SecuritySession;
186 import com.ivata.groupware.admin.security.user.UserDO;
187 import com.ivata.groupware.container.PicoContainerFactory;
188 import com.ivata.mask.util.SystemException;
189 import com.ivata.mask.validation.ValidationErrors;
190
191
192 /**
193  * <p>This class controls/sets the global preferences. It's might make sense to
194  * make it a stateful bean so it can contais a reference to the current
195  * personUser</p>
196  *
197  * <p>This Session Bean has been extended from a class,
198  * <code>com.ivata.groupware.admin.settings</code>, in the original JSP intranet
199  * prototype.</p>
200  *
201  * @since 2001-09-06
202  * @author Colin MacLeod
203  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
204  * @version $Revision: 1.3 $
205  *
206  * @ejb.bean
207  * name="Settings"
208  * display-name="Settings"
209  * type="Stateless"
210  * view-type="both"
211  * local-jndi-name="SettingsLocal"
212  * jndi-name="SettingsRemote"
213  *
214  * @ejb.transaction
215  * type = "Required"
216  *
217  * @ejb.home
218  * generate="false"
219  * remote-class="com.ivata.groupware.admin.setting.SettingsRemoteHome"
220  *
221  * @ejb.interface
222  * remote-class="com.ivata.groupware.admin.setting.SettingsRemote"
223  */

224 public class SettingsBean implements SessionBean JavaDoc, Settings {
225
226
227     /**
228      * <p>Provides the session bean with container-specific information.</p>
229      */

230     SessionContext JavaDoc sessionContext;
231
232     /**
233      * <p>
234      * Change the value of an existing setting.
235      * </p>
236      *
237      * @param name the name of the setting to set
238      * @param value new value to be set.
239      * @param user if not <code>null</code>, then the setting for this user
240      * is set, otherwise the general setting is changed.
241      */

242     public void amendSetting(final SecuritySession securitySession,
243             final String JavaDoc name,
244             final Object JavaDoc value,
245             final UserDO user) throws SystemException {
246         getSettings().amendSetting(securitySession, name, value, user);
247     }
248
249     /**
250      * <p>Called by the container to notify a stateful session object it has been
251      * activated.</p>
252      */

253     public void ejbActivate() {}
254
255     /**
256      * <p>Mandatory, parameter-less <code>ejbCreate</code> is required by the
257      * stateless bean interface.</p>
258      *
259      * <p>This method will be called after a client calls the <code>create</code>
260      * of the remote/local home interface.</p>
261      *
262      * @ejb.create-method
263      */

264     public void ejbCreate() {}
265
266     /**
267      * <p>Called by the container to notify a stateful session object it will be
268      * deactivated. Called just before deactivation.</p>
269      */

270     public void ejbPassivate() {}
271
272     /**
273      * <p>This method is called by the container when the session bean is about
274      * to be removed.</p>
275      *
276      * <p>This method will be called after a client calls the <code>remove</code>
277      * method of the remote/local home interface.</p>
278      */

279     public void ejbRemove() {}
280
281     /**
282      * <p>Get a setting of class <code>Boolean</code>.</p>
283      *
284      * @return the setting if set, or null if not
285      * @param name the name of the setting to return the value for
286      * @param userDO the user to search for. If null is specified, the
287      * default setting is searched for and returned if found.
288      * @exception SettingsDataTypeException if the setting has any class other
289      * than Boolean
290      * @return a setting of class <code>Boolean</code> for the setting
291      * name provided.
292      * @see #getSetting
293      * @see #getIntegerSetting
294      * @see #getStringSetting
295      * @throws SettingNullException if this setting does not exist.
296      *
297      * @ejb.interface-method
298      * view-type="both"
299      */

300     public final Boolean JavaDoc getBooleanSetting(final SecuritySession securitySession,
301             final String JavaDoc name,
302             final UserDO userDO) throws SystemException {
303         return getSettings().getBooleanSetting(securitySession, name, userDO);
304     }
305
306     /**
307      * <p>Get a setting of class <code>Integer</code>.</p>
308      *
309      * @exception SettingsDataTypeException if the setting has any class other
310      * than Integer.
311      * @return the setting if set, or null if not
312      * @param name the name of the setting to return the value for.
313      * @param userDO the user to search for. If null is specified, the
314      * default setting is searched for and returned if found.
315      * @return a setting of class <code>Integer</code> for the setting
316      * name provided.
317      * @see #getSetting
318      * @see #getStringSetting
319      * @see #getBooleanSetting
320      * @throws SettingNullException if this setting does not exist.
321      *
322      * @ejb.interface-method
323      * view-type="both"
324      */

325     public final Integer JavaDoc getIntegerSetting(final SecuritySession securitySession,
326             final String JavaDoc name,
327             final UserDO userDO) throws SystemException {
328         return getSettings().getIntegerSetting(securitySession, name, userDO);
329     }
330
331     /**
332      * <p>Get a setting for a given user. The class of the returned object will
333      * depend on the <code>type</code> field of the EJB with this name and can
334      * be one of:</br/>
335      * <ul>
336      * <li><code>Integer</code></li>
337      * <li><code>String</code></li>
338      * <li><code>Boolean</code></li></p>
339      *
340      * @return the setting if set, or null if not
341      * @param name the name of the setting to return the value for
342      * @param userDO the user to search for. If null is specified, the
343      * default setting is searched for and returned if found.
344      * @return a setting with the setting name provided. The type of the
345      * returned object depends on the <code>type</code> field of the
346      * setting.
347      * @see #getIntegerSetting
348      * @see #getStringSetting
349      * @see #getBooleanSetting
350      * @throws SettingNullException if this setting does not exist.
351      *
352      * @ejb.interface-method
353      * view-type="both"
354      */

355     public final Object JavaDoc getSetting(final SecuritySession securitySession,
356             final String JavaDoc name,
357             final UserDO userDO) throws SystemException {
358         return getSettings().getSetting(securitySession, name, userDO);
359     }
360     /**
361      * Get the implementation which does all the hard work.
362      */

363     private Settings getSettings() throws SystemException {
364         PicoContainer container = PicoContainerFactory.getInstance()
365             .getGlobalContainer();
366         return (Settings) container.getComponentInstance(Settings.class);
367     }
368
369     /**
370      * <p>Get the type of a setting</p>
371      * @param name the name of the setting
372      * @return one of the static fields of <code>SettingConstants</code>
373      * @throws SettingNullException if this setting does not exist.
374      *
375      * @ejb.interface-method
376      * view-type="both"
377      */

378     public final int getSettingType(final SecuritySession securitySession,
379             final String JavaDoc name) throws SystemException {
380         return getSettings().getSettingType(securitySession, name);
381     }
382
383     /**
384      * <p>Get a setting of class String.</p>
385      *
386      * @return the setting if set, or null if not
387      * @param name the name of the setting to return the value for
388      * @param userDO the user to search for. If null is specified, the
389      * default setting is searched for and returned if found.
390      * @exception SettingsDataTypeException if the setting has any class other
391      * than String
392      * @return a setting of class <code>String</code> for the setting
393      * name provided.
394      * @see #getSetting
395      * @see #getIntegerSetting
396      * @see #getBooleanSetting
397      * @throws SettingNullException if this setting does not exist.
398      *
399      * @ejb.interface-method
400      * view-type="both"
401      */

402     public final String JavaDoc getStringSetting(final SecuritySession securitySession,
403             final String JavaDoc name,
404             final UserDO userDO) throws SystemException {
405         return getSettings().getStringSetting(securitySession, name, userDO);
406     }
407     /**
408      * <p>
409      * Find out whether or not a setting is enabled.
410      * </p>
411      *
412      * @param securitySession valid security session.
413      * @param name name of the setting to check.
414      * @return <code>true</code> if the setting exists and is enabled.
415      * @throws SystemException if it don't work out in some way :-)
416      *
417      * @ejb.interface-method
418      * view-type="both"
419      */

420     public boolean isSettingEnabled(final SecuritySession securitySession,
421             final String JavaDoc
422             name)
423             throws SystemException {
424         return getSettings().isSettingEnabled(securitySession, name);
425     }
426
427     /**
428      * <p>
429      * Revert a user setting back to the general value.
430      * </p>
431      *
432      * @param name the name of the setting to revert
433      * @param user the setting for this user is reverted
434      */

435     public void revertSetting(final SecuritySession securitySession,
436             final String JavaDoc name,
437             final UserDO user) throws SystemException {
438         getSettings().revertSetting(securitySession, name, user);
439     }
440
441     /**
442      * <p>Provides access to the runtime properties of the context in which this
443      * session bean is running.</p>
444      *
445      * <p>Is usually stored by the bean internally.</p>
446      *
447      * @param sessionContext new value for the session context. Is usually
448      * stored internally
449      */

450     public final void setSessionContext(final SessionContext JavaDoc sessionContext) {
451         this.sessionContext = sessionContext;
452     }
453
454     /**
455      * <p>Confirm all of the settings passed are correct.</p>
456      *
457      * @param settings a <code>Map</code> with setting names as keys and setting
458      * values as values
459      * @param the <code>Locale</code> to get localised error messages
460      * @param settingType one of the constants in <code>SettingConstants</code>:
461      * <code>SETTING_USER</code> or <code>SETTING_SYSTEM</code>
462      * @return a collection of validation errors if any of the settings contains
463      * invalid value.
464      *
465      * @ejb.interface-method
466      * view-type="both"
467      */

468     public ValidationErrors validate(final SecuritySession securitySession,
469             final Map JavaDoc settings,
470             final Locale JavaDoc locale,
471             final int settingType) throws SystemException {
472         return getSettings().validate(securitySession, settings, locale, settingType);
473     }
474
475 }
476
Popular Tags