1.1 --- a/openide.util/src/org/openide/util/NbPreferences.java Wed Jan 27 17:46:23 2010 -0500
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,140 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
1.8 - *
1.9 - * The contents of this file are subject to the terms of either the GNU
1.10 - * General Public License Version 2 only ("GPL") or the Common
1.11 - * Development and Distribution License("CDDL") (collectively, the
1.12 - * "License"). You may not use this file except in compliance with the
1.13 - * License. You can obtain a copy of the License at
1.14 - * http://www.netbeans.org/cddl-gplv2.html
1.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.16 - * specific language governing permissions and limitations under the
1.17 - * License. When distributing the software, include this License Header
1.18 - * Notice in each file and include the License file at
1.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
1.20 - * particular file as subject to the "Classpath" exception as provided
1.21 - * by Sun in the GPL Version 2 section of the License file that
1.22 - * accompanied this code. If applicable, add the following below the
1.23 - * License Header, with the fields enclosed by brackets [] replaced by
1.24 - * your own identifying information:
1.25 - * "Portions Copyrighted [year] [name of copyright owner]"
1.26 - *
1.27 - * Contributor(s):
1.28 - *
1.29 - * The Original Software is NetBeans. The Initial Developer of the Original
1.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
1.31 - * Microsystems, Inc. All Rights Reserved.
1.32 - *
1.33 - * If you wish your version of this file to be governed by only the CDDL
1.34 - * or only the GPL Version 2, indicate your decision by adding
1.35 - * "[Contributor] elects to include this software in this distribution
1.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.37 - * single choice of license, a recipient has the option to distribute
1.38 - * your version of this file under either the CDDL, the GPL Version 2 or
1.39 - * to extend the choice of license to its licensees as provided above.
1.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
1.41 - * Version 2 license, then the option applies only if the new code is
1.42 - * made subject to such option by the copyright holder.
1.43 - */
1.44 -
1.45 -package org.openide.util;
1.46 -
1.47 -import java.io.ByteArrayOutputStream;
1.48 -import java.io.PrintStream;
1.49 -import java.util.logging.Level;
1.50 -import java.util.logging.Logger;
1.51 -import java.util.prefs.Preferences;
1.52 -
1.53 -/**
1.54 - * Provides an implementation of the Preferences API which may be backed by
1.55 - * a NetBeans-specific implementation.
1.56 - * @see <a href="doc-files/preferences.html">Preferences API in NetBeans</a>
1.57 - * @since org.openide.util 7.4
1.58 - * @author Radek Matous
1.59 - */
1.60 -public final class NbPreferences {
1.61 - private static Provider PREFS_IMPL;
1.62 -
1.63 - private NbPreferences() {}
1.64 -
1.65 - /**
1.66 - * Returns user preference node . {@link Preferences#absolutePath} of such
1.67 - * a node depends whether class provided as a parameter was loaded as a part of any module
1.68 - * or not. If so, then absolute path corresponds to slashified code name base of module.
1.69 - * If not, then absolute path corresponds to class's package.
1.70 - *
1.71 - * @param cls the class for which a user preference node is desired.
1.72 - * @return the user preference node
1.73 - */
1.74 - public static Preferences forModule(Class cls) {
1.75 - if (PREFS_IMPL == null) {
1.76 - PREFS_IMPL = getPreferencesProvider();
1.77 - }
1.78 - return PREFS_IMPL.preferencesForModule(cls);
1.79 - }
1.80 -
1.81 - /**
1.82 - * Returns the root preference node.
1.83 - *
1.84 - * @return the root preference node.
1.85 - */
1.86 - public static Preferences root() {
1.87 - if (PREFS_IMPL == null) {
1.88 - PREFS_IMPL = getPreferencesProvider();
1.89 - }
1.90 - return PREFS_IMPL.preferencesRoot();
1.91 - }
1.92 -
1.93 - private static Provider getPreferencesProvider() {
1.94 - Provider retval = Lookup.getDefault().lookup(Provider.class);
1.95 - if (retval == null) {
1.96 - retval = new Provider() {
1.97 - public Preferences preferencesForModule(Class cls) {
1.98 - return Preferences.userNodeForPackage(cls);
1.99 - }
1.100 -
1.101 - public Preferences preferencesRoot() {
1.102 - return Preferences.userRoot();
1.103 - }
1.104 - };
1.105 - // Avoided warning in case it is set
1.106 - //(e.g. from NbTestCase - org.netbeans.junit.internal.MemoryPreferencesFactory).
1.107 - String prefsFactory = System.getProperty("java.util.prefs.PreferencesFactory");//NOI18N
1.108 - if (!"org.netbeans.junit.internal.MemoryPreferencesFactory".equals(prefsFactory)) {//NOI18N
1.109 - Logger logger = Logger.getLogger(NbPreferences.class.getName());
1.110 - ByteArrayOutputStream bos = new ByteArrayOutputStream();
1.111 - new Exception().printStackTrace(new PrintStream(bos));
1.112 - logger.log(prefsFactory == null ? Level.WARNING : Level.FINE,
1.113 - "NetBeans implementation of Preferences not found: " + bos.toString() );//NOI18N
1.114 - }
1.115 - }
1.116 - return retval;
1.117 - }
1.118 -
1.119 - /**
1.120 - * Implementation of {@link NbPreferences} methods.
1.121 - * Not intended for use outside the NetBeans Platform.
1.122 - * @since org.openide.util 8.1
1.123 - */
1.124 - public interface Provider {
1.125 - /**
1.126 - * Returns user preference node. {@link Preferences#absolutePath} of such
1.127 - * a node depends whether class provided as a parameter was loaded as a part of any module
1.128 - * or not. If so, then absolute path corresponds to slashified code name base of module.
1.129 - * If not, then absolute path corresponds to class's package.
1.130 - *
1.131 - * @param cls the class for which a user preference node is desired.
1.132 - * @return the user preference node
1.133 - */
1.134 - Preferences preferencesForModule(Class cls);
1.135 - /**
1.136 - * Returns the root preference node.
1.137 - *
1.138 - * @return the root preference node.
1.139 - */
1.140 - Preferences preferencesRoot();
1.141 - }
1.142 -
1.143 -}