1 package siouxsie.desktop.prefs.impl;
2
3 import java.util.prefs.BackingStoreException;
4 import java.util.prefs.Preferences;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.apache.hivemind.events.RegistryShutdownListener;
9
10 import siouxsie.desktop.prefs.IPreferencesService;
11
12 /**
13 *
14 * @author Arnaud Cogoluegnes
15 * @version $Id$
16 * @todo add configuration points for preferences event handlers?
17 */
18 public class PreferencesService implements IPreferencesService, RegistryShutdownListener {
19
20 /** the specific node name for the application */
21 private String rootNodeName;
22
23 private Preferences userRootNode;
24
25 private Preferences systemRootNode;
26
27 private static final Log LOG = LogFactory.getLog(PreferencesService.class);
28
29
30
31
32
33 public Preferences getSiouxsieSystemPreferences() {
34 return systemRootNode;
35 }
36
37
38
39
40
41 public Preferences getSiouxsieUserPreferences() {
42 return userRootNode;
43 }
44
45 public String getRootNodeName() {
46 return rootNodeName;
47 }
48
49 public void setRootNodeName(String rootNodeName) {
50 this.rootNodeName = rootNodeName;
51 }
52
53 public void init() {
54 userRootNode = Preferences.userRoot().node(rootNodeName);
55 systemRootNode = Preferences.systemRoot().node(rootNodeName);
56 }
57
58
59
60
61
62 public void registryDidShutdown() {
63 try {
64 userRootNode.flush();
65 } catch (BackingStoreException e) {
66 LOG.error("could not flush user preferences",e);
67 }
68
69 try {
70 systemRootNode.flush();
71 } catch (BackingStoreException e) {
72 LOG.error("could not flush system preferences",e);
73 }
74 }
75 }