jdk/src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 22951 jdk/src/windows/classes/java/util/prefs/WindowsPreferences.java@5fd21112b2b6
child 30043 b0dd05ec3db1
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     2
 * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.prefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ByteArrayOutputStream;
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    32
import java.security.AccessController;
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    33
import java.security.PrivilegedAction;
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    34
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
    35
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Windows registry based implementation of  <tt>Preferences</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <tt>Preferences</tt>' <tt>systemRoot</tt> and <tt>userRoot</tt> are stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <tt>HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <tt>HKEY_CURRENT_USER\Software\JavaSoft\Prefs</tt> correspondingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author  Konstantin Kladko
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see Preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @see PreferencesFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class WindowsPreferences extends AbstractPreferences{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    51
    static {
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    52
        PrivilegedAction<Void> load = () -> {
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    53
            System.loadLibrary("prefs");
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    54
            return null;
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    55
        };
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    56
        AccessController.doPrivileged(load);
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    57
    }
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 5506
diff changeset
    58
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Logger for error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
    62
    private static PlatformLogger logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Windows registry path to <tt>Preferences</tt>'s root nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final byte[] WINDOWS_ROOT_PATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                               = stringToByteArray("Software\\JavaSoft\\Prefs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Windows handles to <tt>HKEY_CURRENT_USER</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <tt>HKEY_LOCAL_MACHINE</tt> hives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int HKEY_CURRENT_USER = 0x80000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final int HKEY_LOCAL_MACHINE = 0x80000002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Mount point for <tt>Preferences</tt>'  user root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final int USER_ROOT_NATIVE_HANDLE = HKEY_CURRENT_USER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Mount point for <tt>Preferences</tt>'  system root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final int SYSTEM_ROOT_NATIVE_HANDLE = HKEY_LOCAL_MACHINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Maximum byte-encoded path length for Windows native functions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * ending <tt>null</tt> character not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final int MAX_WINDOWS_PATH_LENGTH = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * User root node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    static final Preferences userRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * System root node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static final Preferences systemRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /*  Windows error codes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static final int ERROR_SUCCESS = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final int ERROR_FILE_NOT_FOUND = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final int ERROR_ACCESS_DENIED = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /* Constants used to interpret returns of native functions    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final int NATIVE_HANDLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static final int ERROR_CODE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static final int SUBKEYS_NUMBER = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final int VALUES_NUMBER = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final int MAX_KEY_LENGTH = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final int MAX_VALUE_NAME_LENGTH = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private static final int DISPOSITION = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static final int REG_CREATED_NEW_KEY = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static final int REG_OPENED_EXISTING_KEY = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static final int NULL_NATIVE_HANDLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /* Windows security masks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static final int DELETE = 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static final int KEY_QUERY_VALUE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static final int KEY_SET_VALUE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static final int KEY_CREATE_SUB_KEY = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final int KEY_ENUMERATE_SUB_KEYS = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final int KEY_READ = 0x20019;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final int KEY_WRITE = 0x20006;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private static final int KEY_ALL_ACCESS = 0xf003f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Initial time between registry access attempts, in ms. The time is doubled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * after each failing attempt (except the first).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static int INIT_SLEEP_TIME = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Maximum number of registry access attempts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static int MAX_ATTEMPTS = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * BackingStore availability flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private boolean isBackingStoreAvailable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Java wrapper for Windows registry API RegOpenKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static native int[] WindowsRegOpenKey(int hKey, byte[] subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                                         int securityMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Retries RegOpenKey() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private static int[] WindowsRegOpenKey1(int hKey, byte[] subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                      int securityMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int[] result = WindowsRegOpenKey(hKey, subKey, securityMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } else if (result[ERROR_CODE] == ERROR_FILE_NOT_FOUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            logger().warning("Trying to recreate Windows registry node " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            byteArrayToString(subKey) + " at root 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            Integer.toHexString(hKey) + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // Try recreation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            int handle = WindowsRegCreateKeyEx(hKey, subKey)[NATIVE_HANDLE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            WindowsRegCloseKey(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return WindowsRegOpenKey(hKey, subKey, securityMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            result = WindowsRegOpenKey(hKey, subKey, securityMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Java wrapper for Windows registry API RegCloseKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static native int WindowsRegCloseKey(int hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Java wrapper for Windows registry API RegCreateKeyEx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private static native int[] WindowsRegCreateKeyEx(int hKey, byte[] subKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Retries RegCreateKeyEx() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static int[] WindowsRegCreateKeyEx1(int hKey, byte[] subKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int[] result = WindowsRegCreateKeyEx(hKey, subKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                result = WindowsRegCreateKeyEx(hKey, subKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Java wrapper for Windows registry API RegDeleteKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private static native int WindowsRegDeleteKey(int hKey, byte[] subKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Java wrapper for Windows registry API RegFlushKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private static native int WindowsRegFlushKey(int hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Retries RegFlushKey() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static int WindowsRegFlushKey1(int hKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int result = WindowsRegFlushKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (result == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                result = WindowsRegFlushKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                if (result == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Java wrapper for Windows registry API RegQueryValueEx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private static native byte[] WindowsRegQueryValueEx(int hKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                                              byte[] valueName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Java wrapper for Windows registry API RegSetValueEx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static native int WindowsRegSetValueEx(int hKey, byte[] valueName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                                         byte[] value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Retries RegSetValueEx() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private static int WindowsRegSetValueEx1(int hKey, byte[] valueName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                                         byte[] value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int result = WindowsRegSetValueEx(hKey, valueName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (result == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                result = WindowsRegSetValueEx(hKey, valueName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if (result == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Java wrapper for Windows registry API RegDeleteValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private static native int WindowsRegDeleteValue(int hKey, byte[] valueName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Java wrapper for Windows registry API RegQueryInfoKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private static native int[] WindowsRegQueryInfoKey(int hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Retries RegQueryInfoKey() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private static int[] WindowsRegQueryInfoKey1(int hKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        int[] result = WindowsRegQueryInfoKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                result = WindowsRegQueryInfoKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                if (result[ERROR_CODE] == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Java wrapper for Windows registry API RegEnumKeyEx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private static native byte[] WindowsRegEnumKeyEx(int hKey, int subKeyIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                      int maxKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private static byte[] WindowsRegEnumKeyEx1(int hKey, int subKeyIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                      int maxKeyLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Java wrapper for Windows registry API RegEnumValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private static native byte[] WindowsRegEnumValue(int hKey, int valueIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                      int maxValueNameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private static byte[] WindowsRegEnumValue1(int hKey, int valueIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                      int maxValueNameLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        byte[] result = WindowsRegEnumValue(hKey, valueIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                                            maxValueNameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                long sleepTime = INIT_SLEEP_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    Thread.sleep(sleepTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                } catch(InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                sleepTime *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                result = WindowsRegEnumValue(hKey, valueIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                            maxValueNameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Constructs a <tt>WindowsPreferences</tt> node, creating underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Windows registry node and all its Windows parents, if they are not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Logs a warning message, if Windows Registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    private WindowsPreferences(WindowsPreferences parent, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        super(parent, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        int parentNativeHandle = parent.openKey(KEY_CREATE_SUB_KEY, KEY_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (parentNativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            // if here, openKey failed and logged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        int[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
               WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            logger().warning("Could not create windows registry "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            + "node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            ". Windows RegCreateKeyEx(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            result[ERROR_CODE] + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        newNode = (result[DISPOSITION] == REG_CREATED_NEW_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        closeKey(parentNativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        closeKey(result[NATIVE_HANDLE]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Constructs a root node creating the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Windows registry node and all of its parents, if they have not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Logs a warning message, if Windows Registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param rootNativeHandle Native handle to one of Windows top level keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param rootDirectory Path to root directory, as a byte-encoded string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private  WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        super(null,"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            logger().warning("Could not open/create prefs root node " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            ". Windows RegCreateKeyEx(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            result[ERROR_CODE] + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // Check if a new node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        newNode = (result[DISPOSITION] == REG_CREATED_NEW_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        closeKey(result[NATIVE_HANDLE]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Returns Windows absolute path of the current node as a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Java "/" separator is transformed into Windows "\".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see Preferences#absolutePath()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private byte[] windowsAbsolutePath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        ByteArrayOutputStream bstream = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        bstream.write(WINDOWS_ROOT_PATH, 0, WINDOWS_ROOT_PATH.length-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        StringTokenizer tokenizer = new StringTokenizer(absolutePath(),"/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            bstream.write((byte)'\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            String nextName = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            byte[] windowsNextName = toWindowsName(nextName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            bstream.write(windowsNextName, 0, windowsNextName.length-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        bstream.write(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return bstream.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Opens current node's underlying Windows registry key using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * given security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param securityMask Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return Windows registry key's handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @see #openKey(byte[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @see #openKey(int, byte[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @see #closeKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    private int openKey(int securityMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return openKey(securityMask, securityMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Opens current node's underlying Windows registry key using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * given security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param mask1 Preferred Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param mask2 Alternate Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @return Windows registry key's handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @see #openKey(byte[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @see #openKey(int, byte[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @see #closeKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    private int openKey(int mask1, int mask2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return openKey(windowsAbsolutePath(), mask1,  mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Opens Windows registry key at a given absolute path using a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @param windowsAbsolutePath Windows absolute path of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *        key as a byte-encoded string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @param mask1 Preferred Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @param mask2 Alternate Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @return Windows registry key's handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #openKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see #openKey(int, byte[],int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see #closeKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    private int openKey(byte[] windowsAbsolutePath, int mask1, int mask2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        /*  Check if key's path is short enough be opened at once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            otherwise use a path-splitting procedure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
             int[] result = WindowsRegOpenKey1(rootNativeHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                               windowsAbsolutePath, mask1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
             if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                 result = WindowsRegOpenKey1(rootNativeHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                             windowsAbsolutePath, mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
             if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                logger().warning("Could not open windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                ". Windows RegOpenKey(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                result[ERROR_CODE] + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    throw new SecurityException("Could not open windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                ": Access denied");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
             return result[NATIVE_HANDLE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            return openKey(rootNativeHandle(), windowsAbsolutePath, mask1, mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Opens Windows registry key at a given relative path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * with respect to a given Windows registry key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @param windowsAbsolutePath Windows relative path of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *        key as a byte-encoded string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @param nativeHandle handle to the base Windows key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param mask1 Preferred Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @param mask2 Alternate Windows security mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @return Windows registry key's handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @see #openKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #openKey(byte[],int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @see #closeKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    private int openKey(int nativeHandle, byte[] windowsRelativePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        int mask1, int mask2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /* If the path is short enough open at once. Otherwise split the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
             int[] result = WindowsRegOpenKey1(nativeHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                               windowsRelativePath, mask1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
             if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                 result = WindowsRegOpenKey1(nativeHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                             windowsRelativePath, mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
             if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                logger().warning("Could not open windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                " at root 0x" + Integer.toHexString(nativeHandle) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                ". Windows RegOpenKey(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                result[ERROR_CODE] + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
             return result[NATIVE_HANDLE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            int separatorPosition = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // Be greedy - open the longest possible path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            for (int i = MAX_WINDOWS_PATH_LENGTH; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                if (windowsRelativePath[i] == ((byte)'\\')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    separatorPosition = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            // Split the path and do the recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            byte[] nextRelativeRoot = new byte[separatorPosition+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            System.arraycopy(windowsRelativePath, 0, nextRelativeRoot,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                                      separatorPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            nextRelativeRoot[separatorPosition] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            byte[] nextRelativePath = new byte[windowsRelativePath.length -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                      separatorPosition - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            System.arraycopy(windowsRelativePath, separatorPosition+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                             nextRelativePath, 0, nextRelativePath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            int nextNativeHandle = openKey(nativeHandle, nextRelativeRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                           mask1, mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            if (nextNativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                return NULL_NATIVE_HANDLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            int result = openKey(nextNativeHandle, nextRelativePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                 mask1,mask2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            closeKey(nextNativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Closes Windows registry key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Logs a warning if Windows registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param key's Windows registry handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see #openKey(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see #openKey(byte[],int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @see #openKey(int, byte[],int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    private void closeKey(int nativeHandle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        int result = WindowsRegCloseKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (result != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            logger().warning("Could not close windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            ". Windows RegCloseKey(...) returned error code " + result + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Implements <tt>AbstractPreferences</tt> <tt>putSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Puts name-value pair into the underlying Windows registry node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Logs a warning, if Windows registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @see #getSpi(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    protected void putSpi(String javaName, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    int nativeHandle = openKey(KEY_SET_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    int result =  WindowsRegSetValueEx1(nativeHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                          toWindowsName(javaName), toWindowsValueString(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    if (result != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        logger().warning("Could not assign value to key " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        byteArrayToString(toWindowsName(javaName))+ " at Windows registry node "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
       + byteArrayToString(windowsAbsolutePath()) + " at root 0x"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
       + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
       ". Windows RegSetValueEx(...) returned error code " + result + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Implements <tt>AbstractPreferences</tt> <tt>getSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Gets a string value from the underlying Windows registry node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Logs a warning, if Windows registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @see #putSpi(String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    protected String getSpi(String javaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    int nativeHandle = openKey(KEY_QUERY_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    Object resultObject =  WindowsRegQueryValueEx(nativeHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                                  toWindowsName(javaName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    if (resultObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    return toJavaValueString((byte[]) resultObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * Implements <tt>AbstractPreferences</tt> <tt>removeSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Deletes a string name-value pair from the underlying Windows registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * node, if this value still exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Logs a warning, if Windows registry is unavailable or key has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * been deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    protected void removeSpi(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        int nativeHandle = openKey(KEY_SET_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        int result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            WindowsRegDeleteValue(nativeHandle, toWindowsName(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            logger().warning("Could not delete windows registry "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            + "value " + byteArrayToString(windowsAbsolutePath())+ "\\" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            toWindowsName(key) + " at root 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            ". Windows RegDeleteValue(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            result + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            isBackingStoreAvailable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Implements <tt>AbstractPreferences</tt> <tt>keysSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Gets value names from the underlying Windows registry node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Throws a BackingStoreException and logs a warning, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * Windows registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    protected String[] keysSpi() throws BackingStoreException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        // Find out the number of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int nativeHandle = openKey(KEY_QUERY_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            throw new BackingStoreException("Could not open windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        int[] result =  WindowsRegQueryInfoKey1(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            String info = "Could not query windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            ". Windows RegQueryInfoKeyEx(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            result[ERROR_CODE] + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        int maxValueNameLength = result[MAX_VALUE_NAME_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        int valuesNumber = result[VALUES_NUMBER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (valuesNumber == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
       // Get the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
       String[] valueNames = new String[valuesNumber];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
       for (int i = 0; i < valuesNumber; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            byte[] windowsName = WindowsRegEnumValue1(nativeHandle, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                                                        maxValueNameLength+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (windowsName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                String info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                "Could not enumerate value #" + i + "  of windows node " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                Integer.toHexString(rootNativeHandle()) + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            valueNames[i] = toJavaName(windowsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        return valueNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Implements <tt>AbstractPreferences</tt> <tt>childrenNamesSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Calls Windows registry to retrive children of this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Throws a BackingStoreException and logs a warning message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * if Windows registry is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    protected String[] childrenNamesSpi() throws BackingStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // Open key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS| KEY_QUERY_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            throw new BackingStoreException("Could not open windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        // Get number of children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        int[] result =  WindowsRegQueryInfoKey1(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        if (result[ERROR_CODE] != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            String info = "Could not query windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            ". Windows RegQueryInfoKeyEx(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            result[ERROR_CODE] + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        int maxKeyLength = result[MAX_KEY_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        int subKeysNumber = result[SUBKEYS_NUMBER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        if (subKeysNumber == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        String[] subkeys = new String[subKeysNumber];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        String[] children = new String[subKeysNumber];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        // Get children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        for (int i = 0; i < subKeysNumber; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            byte[] windowsName = WindowsRegEnumKeyEx1(nativeHandle, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                                                                maxKeyLength+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            if (windowsName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                String info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                "Could not enumerate key #" + i + "  of windows node " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                Integer.toHexString(rootNativeHandle()) + ". ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            String javaName = toJavaName(windowsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            children[i] = javaName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Implements <tt>Preferences</tt> <tt>flush()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * Flushes Windows registry changes to disk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Throws a BackingStoreException and logs a warning message if Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * registry is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public void flush() throws BackingStoreException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (isRemoved()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            parent.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (!isBackingStoreAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            throw new BackingStoreException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                       "flush(): Backing store not available.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        int nativeHandle = openKey(KEY_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        if (nativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            throw new BackingStoreException("Could not open windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        int result = WindowsRegFlushKey1(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (result != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            String info = "Could not flush windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            + "registry node " + byteArrayToString(windowsAbsolutePath())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            + " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            ". Windows RegFlushKey(...) returned error code " + result + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        closeKey(nativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Implements <tt>Preferences</tt> <tt>sync()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Flushes Windows registry changes to disk. Equivalent to flush().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @see flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public void sync() throws BackingStoreException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (isRemoved())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            throw new IllegalStateException("Node has been removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Implements <tt>AbstractPreferences</tt> <tt>childSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Constructs a child node with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * given name and creates its underlying Windows registry node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * if it does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * Logs a warning message, if Windows Registry is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    protected AbstractPreferences childSpi(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            return new WindowsPreferences(this, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * Implements <tt>AbstractPreferences</tt> <tt>removeNodeSpi()</tt> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * Deletes underlying Windows registry node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * Throws a BackingStoreException and logs a warning, if Windows registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    public void removeNodeSpi() throws BackingStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        int parentNativeHandle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                         ((WindowsPreferences)parent()).openKey(DELETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (parentNativeHandle == NULL_NATIVE_HANDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            throw new BackingStoreException("Could not open parent windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            + "registry node of " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        int result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (result != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            String info = "Could not delete windows "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            + "registry node " + byteArrayToString(windowsAbsolutePath()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            " at root 0x" + Integer.toHexString(rootNativeHandle()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            ". Windows RegDeleteKeyEx(...) returned error code " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            result + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            logger().warning(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            throw new BackingStoreException(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        closeKey(parentNativeHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Converts value's or node's name from its byte array representation to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * java string. Two encodings, simple and altBase64 are used. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * {@link #toWindowsName(String) toWindowsName()} for a detailed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * description of encoding conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param windowsNameArray Null-terminated byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    private static String toJavaName(byte[] windowsNameArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        String windowsName = byteArrayToString(windowsNameArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        // check if Alt64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if ((windowsName.length()>1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                                   (windowsName.substring(0,2).equals("/!"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            return toJavaAlt64Name(windowsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        StringBuffer javaName = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        // Decode from simple encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        for (int i = 0; i < windowsName.length(); i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if ((ch = windowsName.charAt(i)) == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                char next = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                if ((windowsName.length() > i + 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                   ((next = windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                ch = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                } else  if ((windowsName.length() > i + 1) && (next == '/')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                ch = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            } else if (ch == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                ch = '/';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            javaName.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        return javaName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * Converts value's or node's name from its Windows representation to java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * string, using altBase64 encoding. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * {@link #toWindowsName(String) toWindowsName()} for a detailed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * description of encoding conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    private static String toJavaAlt64Name(String windowsName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        byte[] byteBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                          Base64.altBase64ToByteArray(windowsName.substring(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        StringBuffer result = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        for (int i = 0; i < byteBuffer.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            int firstbyte = (byteBuffer[i++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            int secondbyte =  (byteBuffer[i] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            result.append((char)((firstbyte << 8) + secondbyte));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Converts value's or node's name to its Windows representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * as a byte-encoded string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Two encodings, simple and altBase64 are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * <i>Simple</i> encoding is used, if java string does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * any characters less, than 0x0020, or greater, than 0x007f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * Simple encoding adds "/" character to capital letters, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * "A" is encoded as "/A". Character '\' is encoded as '//',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * '/' is encoded as '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * The constructed string is converted to byte array by truncating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * highest byte and adding the terminating <tt>null</tt> character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * <i>altBase64</i>  encoding is used, if java string does contain at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * one character less, than 0x0020, or greater, than 0x007f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * This encoding is marked by setting first two bytes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * Windows string to '/!'. The java name is then encoded using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * byteArrayToAltBase64() method from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * Base64 class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    private static byte[] toWindowsName(String javaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        StringBuffer windowsName = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        for (int i = 0; i < javaName.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            char ch =javaName.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            if ((ch < 0x0020)||(ch > 0x007f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                // If a non-trivial character encountered, use altBase64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                return toWindowsAlt64Name(javaName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if (ch == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                windowsName.append("//");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            } else if (ch == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                windowsName.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            } else if ((ch >= 'A') && (ch <='Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                windowsName.append("/" + ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                windowsName.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        return stringToByteArray(windowsName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * Converts value's or node's name to its Windows representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * as a byte-encoded string, using altBase64 encoding. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * {@link #toWindowsName(String) toWindowsName()} for a detailed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * description of encoding conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    private static byte[] toWindowsAlt64Name(String javaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        byte[] javaNameArray = new byte[2*javaName.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        // Convert to byte pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        int counter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        for (int i = 0; i < javaName.length();i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                int ch = javaName.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                javaNameArray[counter++] = (byte)(ch >>> 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                javaNameArray[counter++] = (byte)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return stringToByteArray(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                           "/!" + Base64.byteArrayToAltBase64(javaNameArray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * Converts value string from its Windows representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * to java string.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * {@link #toWindowsValueString(String) toWindowsValueString()} for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * description of the encoding algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     private static String toJavaValueString(byte[] windowsNameArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        // Use modified native2ascii algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        String windowsName = byteArrayToString(windowsNameArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        StringBuffer javaName = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        for (int i = 0; i < windowsName.length(); i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if ((ch = windowsName.charAt(i)) == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                char next = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                if (windowsName.length() > i + 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                    (next = windowsName.charAt(i + 1)) == 'u') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    if (windowsName.length() < i + 6){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                        ch = (char)Integer.parseInt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                                      (windowsName.substring(i + 2, i + 6), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        i += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                if ((windowsName.length() > i + 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                          ((windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                ch = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                } else  if ((windowsName.length() > i + 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                               (next == '/')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                ch = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            } else if (ch == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                ch = '/';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            javaName.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        return javaName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * Converts value string to it Windows representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * as a byte-encoded string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * Encoding algorithm adds "/" character to capital letters, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * "A" is encoded as "/A". Character '\' is encoded as '//',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * '/' is encoded as  '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Then encoding scheme similar to jdk's native2ascii converter is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * to convert java string to a byte array of ASCII characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    private static byte[] toWindowsValueString(String javaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        StringBuffer windowsName = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        for (int i = 0; i < javaName.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            char ch =javaName.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            if ((ch < 0x0020)||(ch > 0x007f)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                // write \udddd
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                windowsName.append("/u");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                String hex = Integer.toHexString(javaName.charAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                StringBuffer hex4 = new StringBuffer(hex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                hex4.reverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                int len = 4 - hex4.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                for (int j = 0; j < len; j++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    hex4.append('0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                for (int j = 0; j < 4; j++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    windowsName.append(hex4.charAt(3 - j));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            } else if (ch == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                windowsName.append("//");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            } else if (ch == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                windowsName.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            } else if ((ch >= 'A') && (ch <='Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                windowsName.append("/" + ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                windowsName.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return stringToByteArray(windowsName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * Returns native handle for the top Windows node for this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    private int rootNativeHandle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        return (isUserNode()? USER_ROOT_NATIVE_HANDLE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                              SYSTEM_ROOT_NATIVE_HANDLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * Returns this java string as a null-terminated byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    private static byte[] stringToByteArray(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        byte[] result = new byte[str.length()+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        for (int i = 0; i < str.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            result[i] = (byte) str.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        result[str.length()] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * Converts a null-terminated byte array to java string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    private static String byteArrayToString(byte[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        StringBuffer result = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        for (int i = 0; i < array.length - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            result.append((char)array[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    * Empty, never used implementation  of AbstractPreferences.flushSpi().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    protected void flushSpi() throws BackingStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        // assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    * Empty, never used implementation  of AbstractPreferences.flushSpi().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    protected void syncSpi() throws BackingStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        // assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
  1116
    private static synchronized PlatformLogger logger() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if (logger == null) {
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
  1118
            logger = PlatformLogger.getLogger("java.util.prefs");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        return logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
}