1 19 20 package org.openide.util; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 import java.util.prefs.Preferences ; 28 import org.netbeans.modules.openide.util.PreferencesProvider; 29 30 37 public final class NbPreferences { 38 private static PreferencesProvider PREFS_IMPL; 39 40 private NbPreferences() {} 41 42 51 public static Preferences forModule(Class cls) { 52 if (PREFS_IMPL == null) { 53 PREFS_IMPL = getPreferencesProvider(); 54 } 55 return PREFS_IMPL.preferencesForModule(cls); 56 } 57 58 63 public static Preferences root() { 64 if (PREFS_IMPL == null) { 65 PREFS_IMPL = getPreferencesProvider(); 66 } 67 return PREFS_IMPL.preferencesRoot(); 68 } 69 70 private static PreferencesProvider getPreferencesProvider() { 71 PreferencesProvider retval = Lookup.getDefault().lookup(PreferencesProvider.class); 72 if (retval == null) { 73 retval = new PreferencesProvider() { 74 public Preferences preferencesForModule(Class cls) { 75 return Preferences.userNodeForPackage(cls); 76 } 77 78 public Preferences preferencesRoot() { 79 return Preferences.userRoot(); 80 } 81 }; 82 String prefsFactory = System.getProperty("java.util.prefs.PreferencesFactory"); if (!"org.netbeans.junit.internal.MemoryPreferencesFactory".equals(prefsFactory)) { Logger logger = Logger.getLogger(NbPreferences.class.getName()); 87 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 88 new Exception ().printStackTrace(new PrintStream (bos)); 89 logger.log(prefsFactory == null ? Level.WARNING : Level.FINE, 90 "NetBeans implementation of Preferences not found: " + bos.toString() ); } 92 } 93 return retval; 94 } 95 } 96 | Popular Tags |