KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > common > PrefsHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.common;
5
6 import java.util.prefs.Preferences JavaDoc;
7
8 public class PrefsHelper {
9   private static PrefsHelper m_helper = new PrefsHelper();
10
11   public static PrefsHelper getHelper() {
12     return m_helper;
13   }
14
15   public Preferences JavaDoc userNodeFor(Object JavaDoc object) {
16     return userNodeForClass(object.getClass());
17   }
18
19   public Preferences JavaDoc userNodeForClass(Class JavaDoc clas) {
20     String JavaDoc path = "/" + clas.getName().replace('.', '/');
21     return Preferences.userRoot().node(path);
22   }
23
24   public String JavaDoc[] keys(Preferences JavaDoc prefs) {
25     try {
26       return prefs.keys();
27     }
28     catch(Exception JavaDoc e) {
29       e.printStackTrace();
30       return new String JavaDoc[] {};
31     }
32   }
33
34   public String JavaDoc[] childrenNames(Preferences JavaDoc prefs) {
35     try {
36       return prefs.childrenNames();
37     }
38     catch(Exception JavaDoc e) {
39       e.printStackTrace();
40       return new String JavaDoc[] {};
41     }
42   }
43
44   public void flush(Preferences JavaDoc prefs) {
45     try {
46       prefs.flush();
47     } catch(Exception JavaDoc e) {/**/}
48   }
49
50   public void clearKeys(Preferences JavaDoc prefs) {
51     try {
52       prefs.clear();
53     } catch(Exception JavaDoc e) {/**/}
54   }
55
56   public void clearChildren(Preferences JavaDoc prefs) {
57     try {
58       String JavaDoc[] names = prefs.childrenNames();
59
60       for(int i = 0; i < names.length; i++) {
61         prefs.node(names[i]).removeNode();
62       }
63     } catch(Exception JavaDoc e) {/**/}
64   }
65 }
66
Popular Tags