1 4 package com.tc.admin.common; 5 6 import java.util.prefs.Preferences ; 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 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 } 28 catch(Exception e) { 29 e.printStackTrace(); 30 return new String [] {}; 31 } 32 } 33 34 public String [] childrenNames(Preferences prefs) { 35 try { 36 return prefs.childrenNames(); 37 } 38 catch(Exception e) { 39 e.printStackTrace(); 40 return new String [] {}; 41 } 42 } 43 44 public void flush(Preferences prefs) { 45 try { 46 prefs.flush(); 47 } catch(Exception e) {} 48 } 49 50 public void clearKeys(Preferences prefs) { 51 try { 52 prefs.clear(); 53 } catch(Exception e) {} 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 | Popular Tags |