1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.prefs.impl;
18
19 import java.util.prefs.Preferences;
20 import java.util.prefs.PreferencesFactory;
21
22 import org.apache.jetspeed.prefs.PreferencesException;
23 import org.apache.jetspeed.prefs.PreferencesProvider;
24
25 /***
26 * <p>{@link java.util.prefs.PreferencesFactory} implementation to
27 * return {@link PreferencesImpl}.</p>
28 *
29 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
30 */
31 public class PreferencesFactoryImpl implements PreferencesFactory
32 {
33
34 protected static PreferencesProvider prefsProvider;
35
36 public PreferencesFactoryImpl()
37 {
38 super();
39 System.setProperty("java.util.prefs.PreferencesFactory", getClass().getName());
40 }
41
42 /***
43 * @see java.util.prefs.PreferencesFactory#systemRoot()
44 */
45 public Preferences systemRoot()
46 {
47 return PreferencesImpl.systemRoot;
48 }
49
50 /***
51 * @see java.util.prefs.PreferencesFactory#userRoot()
52 */
53 public Preferences userRoot()
54 {
55 return PreferencesImpl.userRoot;
56 }
57
58 /***
59 * <p>
60 * Initializes the factory.
61 * </p>
62 *
63 * @throws Exception
64 */
65 public void init() throws Exception
66 {
67 try
68 {
69 PreferencesImpl.setPreferencesProvider(prefsProvider);
70 PreferencesImpl.systemRoot = new PreferencesImpl(null, "", PreferencesImpl.SYSTEM_NODE_TYPE);
71 PreferencesImpl.userRoot = new PreferencesImpl(null, "", PreferencesImpl.USER_NODE_TYPE);
72 }
73 catch(Throwable e)
74 {
75 e.printStackTrace();
76 throw new PreferencesException("Failed to initialize prefs api. "+e.toString());
77 }
78 }
79
80 /***
81 * @return The {@link PreferencesProvider}
82 */
83 public PreferencesProvider getPrefsProvider()
84 {
85 return prefsProvider;
86 }
87
88 /***
89 * <p>
90 * Set the preferences provider.
91 * </p>
92 *
93 * @param prefsProvider The {@link PreferencesProvider}
94 */
95 public void setPrefsProvider(PreferencesProvider prefsProvider)
96 {
97 PreferencesFactoryImpl.prefsProvider = prefsProvider;
98 }
99 }