01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.common;
05:
06: import java.util.prefs.Preferences;
07:
08: public class PrefsHelper {
09: private static PrefsHelper m_helper = new PrefsHelper();
10:
11: public static PrefsHelper getHelper() {
12: return m_helper;
13: }
14:
15: public Preferences userNodeFor(Object object) {
16: return userNodeForClass(object.getClass());
17: }
18:
19: public Preferences userNodeForClass(Class clas) {
20: String path = "/" + clas.getName().replace('.', '/');
21: return Preferences.userRoot().node(path);
22: }
23:
24: public String[] keys(Preferences prefs) {
25: try {
26: return prefs.keys();
27: } catch (Exception e) {
28: e.printStackTrace();
29: return new String[] {};
30: }
31: }
32:
33: public String[] childrenNames(Preferences prefs) {
34: try {
35: return prefs.childrenNames();
36: } catch (Exception e) {
37: e.printStackTrace();
38: return new String[] {};
39: }
40: }
41:
42: public void flush(Preferences prefs) {
43: try {
44: prefs.flush();
45: } catch (Exception e) {/**/
46: }
47: }
48:
49: public void clearKeys(Preferences prefs) {
50: try {
51: prefs.clear();
52: } catch (Exception e) {/**/
53: }
54: }
55:
56: public void clearChildren(Preferences prefs) {
57: try {
58: String[] names = prefs.childrenNames();
59:
60: for (int i = 0; i < names.length; i++) {
61: prefs.node(names[i]).removeNode();
62: }
63: } catch (Exception e) {/**/
64: }
65: }
66: }
|