< prev index next >

src/java.prefs/windows/classes/java/util/prefs/WindowsPreferences.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 170,195 **** private boolean isBackingStoreAvailable = true; /** * Java wrapper for Windows registry API RegOpenKey() */ ! private static native int[] WindowsRegOpenKey(int hKey, byte[] subKey, int securityMask); /** * Retries RegOpenKey() MAX_ATTEMPTS times before giving up. */ ! private static int[] WindowsRegOpenKey1(int hKey, byte[] subKey, int securityMask) { ! int[] result = WindowsRegOpenKey(hKey, subKey, securityMask); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else if (result[ERROR_CODE] == ERROR_FILE_NOT_FOUND) { logger().warning("Trying to recreate Windows registry node " + byteArrayToString(subKey) + " at root 0x" + ! Integer.toHexString(hKey) + "."); // Try recreation ! int handle = WindowsRegCreateKeyEx(hKey, subKey)[NATIVE_HANDLE]; WindowsRegCloseKey(handle); return WindowsRegOpenKey(hKey, subKey, securityMask); } else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) { --- 170,195 ---- private boolean isBackingStoreAvailable = true; /** * Java wrapper for Windows registry API RegOpenKey() */ ! private static native long[] WindowsRegOpenKey(long hKey, byte[] subKey, int securityMask); /** * Retries RegOpenKey() MAX_ATTEMPTS times before giving up. */ ! private static long[] WindowsRegOpenKey1(long hKey, byte[] subKey, int securityMask) { ! long[] result = WindowsRegOpenKey(hKey, subKey, securityMask); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else if (result[ERROR_CODE] == ERROR_FILE_NOT_FOUND) { logger().warning("Trying to recreate Windows registry node " + byteArrayToString(subKey) + " at root 0x" + ! Long.toHexString(hKey) + "."); // Try recreation ! long handle = WindowsRegCreateKeyEx(hKey, subKey)[NATIVE_HANDLE]; WindowsRegCloseKey(handle); return WindowsRegOpenKey(hKey, subKey, securityMask); } else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) {
*** 209,230 **** } /** * Java wrapper for Windows registry API RegCloseKey() */ ! private static native int WindowsRegCloseKey(int hKey); /** * Java wrapper for Windows registry API RegCreateKeyEx() */ ! private static native int[] WindowsRegCreateKeyEx(int hKey, byte[] subKey); /** * Retries RegCreateKeyEx() MAX_ATTEMPTS times before giving up. */ ! private static int[] WindowsRegCreateKeyEx1(int hKey, byte[] subKey) { ! int[] result = WindowsRegCreateKeyEx(hKey, subKey); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) { --- 209,230 ---- } /** * Java wrapper for Windows registry API RegCloseKey() */ ! private static native int WindowsRegCloseKey(long hKey); /** * Java wrapper for Windows registry API RegCreateKeyEx() */ ! private static native long[] WindowsRegCreateKeyEx(long hKey, byte[] subKey); /** * Retries RegCreateKeyEx() MAX_ATTEMPTS times before giving up. */ ! private static long[] WindowsRegCreateKeyEx1(long hKey, byte[] subKey) { ! long[] result = WindowsRegCreateKeyEx(hKey, subKey); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) {
*** 243,263 **** return result; } /** * Java wrapper for Windows registry API RegDeleteKey() */ ! private static native int WindowsRegDeleteKey(int hKey, byte[] subKey); /** * Java wrapper for Windows registry API RegFlushKey() */ ! private static native int WindowsRegFlushKey(int hKey); /** * Retries RegFlushKey() MAX_ATTEMPTS times before giving up. */ ! private static int WindowsRegFlushKey1(int hKey) { int result = WindowsRegFlushKey(hKey); if (result == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME; --- 243,263 ---- return result; } /** * Java wrapper for Windows registry API RegDeleteKey() */ ! private static native int WindowsRegDeleteKey(long hKey, byte[] subKey); /** * Java wrapper for Windows registry API RegFlushKey() */ ! private static native int WindowsRegFlushKey(long hKey); /** * Retries RegFlushKey() MAX_ATTEMPTS times before giving up. */ ! private static int WindowsRegFlushKey1(long hKey) { int result = WindowsRegFlushKey(hKey); if (result == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME;
*** 278,298 **** } /** * Java wrapper for Windows registry API RegQueryValueEx() */ ! private static native byte[] WindowsRegQueryValueEx(int hKey, byte[] valueName); /** * Java wrapper for Windows registry API RegSetValueEx() */ ! private static native int WindowsRegSetValueEx(int hKey, byte[] valueName, byte[] value); /** * Retries RegSetValueEx() MAX_ATTEMPTS times before giving up. */ ! private static int WindowsRegSetValueEx1(int hKey, byte[] valueName, byte[] value) { int result = WindowsRegSetValueEx(hKey, valueName, value); if (result == ERROR_SUCCESS) { return result; } else { --- 278,298 ---- } /** * Java wrapper for Windows registry API RegQueryValueEx() */ ! private static native byte[] WindowsRegQueryValueEx(long hKey, byte[] valueName); /** * Java wrapper for Windows registry API RegSetValueEx() */ ! private static native int WindowsRegSetValueEx(long hKey, byte[] valueName, byte[] value); /** * Retries RegSetValueEx() MAX_ATTEMPTS times before giving up. */ ! private static int WindowsRegSetValueEx1(long hKey, byte[] valueName, byte[] value) { int result = WindowsRegSetValueEx(hKey, valueName, value); if (result == ERROR_SUCCESS) { return result; } else {
*** 314,335 **** } /** * Java wrapper for Windows registry API RegDeleteValue() */ ! private static native int WindowsRegDeleteValue(int hKey, byte[] valueName); /** * Java wrapper for Windows registry API RegQueryInfoKey() */ ! private static native int[] WindowsRegQueryInfoKey(int hKey); /** * Retries RegQueryInfoKey() MAX_ATTEMPTS times before giving up. */ ! private static int[] WindowsRegQueryInfoKey1(int hKey) { ! int[] result = WindowsRegQueryInfoKey(hKey); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) { --- 314,335 ---- } /** * Java wrapper for Windows registry API RegDeleteValue() */ ! private static native int WindowsRegDeleteValue(long hKey, byte[] valueName); /** * Java wrapper for Windows registry API RegQueryInfoKey() */ ! private static native long[] WindowsRegQueryInfoKey(long hKey); /** * Retries RegQueryInfoKey() MAX_ATTEMPTS times before giving up. */ ! private static long[] WindowsRegQueryInfoKey1(long hKey) { ! long[] result = WindowsRegQueryInfoKey(hKey); if (result[ERROR_CODE] == ERROR_SUCCESS) { return result; } else { long sleepTime = INIT_SLEEP_TIME; for (int i = 0; i < MAX_ATTEMPTS; i++) {
*** 349,365 **** } /** * Java wrapper for Windows registry API RegEnumKeyEx() */ ! private static native byte[] WindowsRegEnumKeyEx(int hKey, int subKeyIndex, int maxKeyLength); /** * Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up. */ ! private static byte[] WindowsRegEnumKeyEx1(int hKey, int subKeyIndex, int maxKeyLength) { byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength); if (result != null) { return result; } else { --- 349,365 ---- } /** * Java wrapper for Windows registry API RegEnumKeyEx() */ ! private static native byte[] WindowsRegEnumKeyEx(long hKey, int subKeyIndex, int maxKeyLength); /** * Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up. */ ! private static byte[] WindowsRegEnumKeyEx1(long hKey, int subKeyIndex, int maxKeyLength) { byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength); if (result != null) { return result; } else {
*** 381,396 **** } /** * Java wrapper for Windows registry API RegEnumValue() */ ! private static native byte[] WindowsRegEnumValue(int hKey, int valueIndex, int maxValueNameLength); /** * Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up. */ ! private static byte[] WindowsRegEnumValue1(int hKey, int valueIndex, int maxValueNameLength) { byte[] result = WindowsRegEnumValue(hKey, valueIndex, maxValueNameLength); if (result != null) { return result; --- 381,396 ---- } /** * Java wrapper for Windows registry API RegEnumValue() */ ! private static native byte[] WindowsRegEnumValue(long hKey, int valueIndex, int maxValueNameLength); /** * Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up. */ ! private static byte[] WindowsRegEnumValue1(long hKey, int valueIndex, int maxValueNameLength) { byte[] result = WindowsRegEnumValue(hKey, valueIndex, maxValueNameLength); if (result != null) { return result;
*** 419,440 **** * created. * Logs a warning message, if Windows Registry is unavailable. */ private WindowsPreferences(WindowsPreferences parent, String name) { super(parent, name); ! int parentNativeHandle = parent.openKey(KEY_CREATE_SUB_KEY, KEY_READ); if (parentNativeHandle == NULL_NATIVE_HANDLE) { // if here, openKey failed and logged isBackingStoreAvailable = false; return; } ! int[] result = WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name)); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not create windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Integer.toHexString(rootNativeHandle()) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; return; } --- 419,440 ---- * created. * Logs a warning message, if Windows Registry is unavailable. */ private WindowsPreferences(WindowsPreferences parent, String name) { super(parent, name); ! long parentNativeHandle = parent.openKey(KEY_CREATE_SUB_KEY, KEY_READ); if (parentNativeHandle == NULL_NATIVE_HANDLE) { // if here, openKey failed and logged isBackingStoreAvailable = false; return; } ! long[] result = WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name)); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not create windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Long.toHexString(rootNativeHandle()) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; return; }
*** 449,466 **** * created. * Logs a warning message, if Windows Registry is unavailable. * @param rootNativeHandle Native handle to one of Windows top level keys. * @param rootDirectory Path to root directory, as a byte-encoded string. */ ! private WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) { super(null, ""); ! int[] result = WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open/create prefs root node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Integer.toHexString(rootNativeHandle()) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; return; } --- 449,466 ---- * created. * Logs a warning message, if Windows Registry is unavailable. * @param rootNativeHandle Native handle to one of Windows top level keys. * @param rootDirectory Path to root directory, as a byte-encoded string. */ ! private WindowsPreferences(long rootNativeHandle, byte[] rootDirectory) { super(null, ""); ! long[] result = WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open/create prefs root node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Long.toHexString(rootNativeHandle()) + ". Windows RegCreateKeyEx(...) returned error code " + result[ERROR_CODE] + "."); isBackingStoreAvailable = false; return; }
*** 495,505 **** * @return Windows registry key's handle. * @see #openKey(byte[], int) * @see #openKey(int, byte[], int) * @see #closeKey(int) */ ! private int openKey(int securityMask) { return openKey(securityMask, securityMask); } /** * Opens current node's underlying Windows registry key using a --- 495,505 ---- * @return Windows registry key's handle. * @see #openKey(byte[], int) * @see #openKey(int, byte[], int) * @see #closeKey(int) */ ! private long openKey(int securityMask) { return openKey(securityMask, securityMask); } /** * Opens current node's underlying Windows registry key using a
*** 509,519 **** * @return Windows registry key's handle. * @see #openKey(byte[], int) * @see #openKey(int, byte[], int) * @see #closeKey(int) */ ! private int openKey(int mask1, int mask2) { return openKey(windowsAbsolutePath(), mask1, mask2); } /** * Opens Windows registry key at a given absolute path using a given --- 509,519 ---- * @return Windows registry key's handle. * @see #openKey(byte[], int) * @see #openKey(int, byte[], int) * @see #closeKey(int) */ ! private long openKey(int mask1, int mask2) { return openKey(windowsAbsolutePath(), mask1, mask2); } /** * Opens Windows registry key at a given absolute path using a given
*** 525,558 **** * @return Windows registry key's handle. * @see #openKey(int) * @see #openKey(int, byte[],int) * @see #closeKey(int) */ ! private int openKey(byte[] windowsAbsolutePath, int mask1, int mask2) { /* Check if key's path is short enough be opened at once otherwise use a path-splitting procedure */ if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) { ! int[] result = WindowsRegOpenKey1(rootNativeHandle(), windowsAbsolutePath, mask1); if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1) result = WindowsRegOpenKey1(rootNativeHandle(), windowsAbsolutePath, mask2); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegOpenKey(...) returned error code " + result[ERROR_CODE] + "."); result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE; if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) { throw new SecurityException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ": Access denied"); } } return result[NATIVE_HANDLE]; } else { --- 525,558 ---- * @return Windows registry key's handle. * @see #openKey(int) * @see #openKey(int, byte[],int) * @see #closeKey(int) */ ! private long openKey(byte[] windowsAbsolutePath, int mask1, int mask2) { /* Check if key's path is short enough be opened at once otherwise use a path-splitting procedure */ if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) { ! long[] result = WindowsRegOpenKey1(rootNativeHandle(), windowsAbsolutePath, mask1); if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1) result = WindowsRegOpenKey1(rootNativeHandle(), windowsAbsolutePath, mask2); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegOpenKey(...) returned error code " + result[ERROR_CODE] + "."); result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE; if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) { throw new SecurityException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ": Access denied"); } } return result[NATIVE_HANDLE]; } else {
*** 571,594 **** * @return Windows registry key's handle. * @see #openKey(int) * @see #openKey(byte[],int) * @see #closeKey(int) */ ! private int openKey(int nativeHandle, byte[] windowsRelativePath, int mask1, int mask2) { /* If the path is short enough open at once. Otherwise split the path */ if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) { ! int[] result = WindowsRegOpenKey1(nativeHandle, windowsRelativePath, mask1); if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1) result = WindowsRegOpenKey1(nativeHandle, windowsRelativePath, mask2); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Integer.toHexString(nativeHandle) + ". Windows RegOpenKey(...) returned error code " + result[ERROR_CODE] + "."); result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE; } return result[NATIVE_HANDLE]; --- 571,594 ---- * @return Windows registry key's handle. * @see #openKey(int) * @see #openKey(byte[],int) * @see #closeKey(int) */ ! private long openKey(long nativeHandle, byte[] windowsRelativePath, int mask1, int mask2) { /* If the path is short enough open at once. Otherwise split the path */ if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) { ! long[] result = WindowsRegOpenKey1(nativeHandle, windowsRelativePath, mask1); if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1) result = WindowsRegOpenKey1(nativeHandle, windowsRelativePath, mask2); if (result[ERROR_CODE] != ERROR_SUCCESS) { logger().warning("Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Long.toHexString(nativeHandle) + ". Windows RegOpenKey(...) returned error code " + result[ERROR_CODE] + "."); result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE; } return result[NATIVE_HANDLE];
*** 608,623 **** nextRelativeRoot[separatorPosition] = 0; byte[] nextRelativePath = new byte[windowsRelativePath.length - separatorPosition - 1]; System.arraycopy(windowsRelativePath, separatorPosition+1, nextRelativePath, 0, nextRelativePath.length); ! int nextNativeHandle = openKey(nativeHandle, nextRelativeRoot, mask1, mask2); if (nextNativeHandle == NULL_NATIVE_HANDLE) { return NULL_NATIVE_HANDLE; } ! int result = openKey(nextNativeHandle, nextRelativePath, mask1,mask2); closeKey(nextNativeHandle); return result; } } --- 608,623 ---- nextRelativeRoot[separatorPosition] = 0; byte[] nextRelativePath = new byte[windowsRelativePath.length - separatorPosition - 1]; System.arraycopy(windowsRelativePath, separatorPosition+1, nextRelativePath, 0, nextRelativePath.length); ! long nextNativeHandle = openKey(nativeHandle, nextRelativeRoot, mask1, mask2); if (nextNativeHandle == NULL_NATIVE_HANDLE) { return NULL_NATIVE_HANDLE; } ! long result = openKey(nextNativeHandle, nextRelativePath, mask1,mask2); closeKey(nextNativeHandle); return result; } }
*** 628,644 **** * @param key's Windows registry handle. * @see #openKey(int) * @see #openKey(byte[],int) * @see #openKey(int, byte[],int) */ ! private void closeKey(int nativeHandle) { int result = WindowsRegCloseKey(nativeHandle); if (result != ERROR_SUCCESS) { logger().warning("Could not close windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegCloseKey(...) returned error code " + result + "."); } } --- 628,644 ---- * @param key's Windows registry handle. * @see #openKey(int) * @see #openKey(byte[],int) * @see #openKey(int, byte[],int) */ ! private void closeKey(long nativeHandle) { int result = WindowsRegCloseKey(nativeHandle); if (result != ERROR_SUCCESS) { logger().warning("Could not close windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegCloseKey(...) returned error code " + result + "."); } }
*** 647,657 **** * Puts name-value pair into the underlying Windows registry node. * Logs a warning, if Windows registry is unavailable. * @see #getSpi(String) */ protected void putSpi(String javaName, String value) { ! int nativeHandle = openKey(KEY_SET_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { isBackingStoreAvailable = false; return; } int result = WindowsRegSetValueEx1(nativeHandle, --- 647,657 ---- * Puts name-value pair into the underlying Windows registry node. * Logs a warning, if Windows registry is unavailable. * @see #getSpi(String) */ protected void putSpi(String javaName, String value) { ! long nativeHandle = openKey(KEY_SET_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { isBackingStoreAvailable = false; return; } int result = WindowsRegSetValueEx1(nativeHandle,
*** 660,670 **** logger().warning("Could not assign value to key " + byteArrayToString(toWindowsName(javaName)) + " at Windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegSetValueEx(...) returned error code " + result + "."); isBackingStoreAvailable = false; } closeKey(nativeHandle); --- 660,670 ---- logger().warning("Could not assign value to key " + byteArrayToString(toWindowsName(javaName)) + " at Windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegSetValueEx(...) returned error code " + result + "."); isBackingStoreAvailable = false; } closeKey(nativeHandle);
*** 675,685 **** * Gets a string value from the underlying Windows registry node. * Logs a warning, if Windows registry is unavailable. * @see #putSpi(String, String) */ protected String getSpi(String javaName) { ! int nativeHandle = openKey(KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { return null; } Object resultObject = WindowsRegQueryValueEx(nativeHandle, toWindowsName(javaName)); --- 675,685 ---- * Gets a string value from the underlying Windows registry node. * Logs a warning, if Windows registry is unavailable. * @see #putSpi(String, String) */ protected String getSpi(String javaName) { ! long nativeHandle = openKey(KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { return null; } Object resultObject = WindowsRegQueryValueEx(nativeHandle, toWindowsName(javaName));
*** 697,717 **** * node, if this value still exists. * Logs a warning, if Windows registry is unavailable or key has already * been deleted. */ protected void removeSpi(String key) { ! int nativeHandle = openKey(KEY_SET_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { return; } int result = WindowsRegDeleteValue(nativeHandle, toWindowsName(key)); if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { logger().warning("Could not delete windows registry value " + byteArrayToString(windowsAbsolutePath()) + "\\" + toWindowsName(key) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegDeleteValue(...) returned error code " + result + "."); isBackingStoreAvailable = false; } closeKey(nativeHandle); --- 697,717 ---- * node, if this value still exists. * Logs a warning, if Windows registry is unavailable or key has already * been deleted. */ protected void removeSpi(String key) { ! long nativeHandle = openKey(KEY_SET_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { return; } int result = WindowsRegDeleteValue(nativeHandle, toWindowsName(key)); if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { logger().warning("Could not delete windows registry value " + byteArrayToString(windowsAbsolutePath()) + "\\" + toWindowsName(key) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegDeleteValue(...) returned error code " + result + "."); isBackingStoreAvailable = false; } closeKey(nativeHandle);
*** 723,753 **** * Throws a BackingStoreException and logs a warning, if * Windows registry is unavailable. */ protected String[] keysSpi() throws BackingStoreException{ // Find out the number of values ! int nativeHandle = openKey(KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + "."); } ! int[] result = WindowsRegQueryInfoKey1(nativeHandle); if (result[ERROR_CODE] != ERROR_SUCCESS) { String info = "Could not query windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegQueryInfoKeyEx(...) returned error code " + result[ERROR_CODE] + "."; logger().warning(info); throw new BackingStoreException(info); } ! int maxValueNameLength = result[MAX_VALUE_NAME_LENGTH]; ! int valuesNumber = result[VALUES_NUMBER]; if (valuesNumber == 0) { closeKey(nativeHandle); return new String[0]; } // Get the values --- 723,753 ---- * Throws a BackingStoreException and logs a warning, if * Windows registry is unavailable. */ protected String[] keysSpi() throws BackingStoreException{ // Find out the number of values ! long nativeHandle = openKey(KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + "."); } ! long[] result = WindowsRegQueryInfoKey1(nativeHandle); if (result[ERROR_CODE] != ERROR_SUCCESS) { String info = "Could not query windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegQueryInfoKeyEx(...) returned error code " + result[ERROR_CODE] + "."; logger().warning(info); throw new BackingStoreException(info); } ! int maxValueNameLength = (int)result[MAX_VALUE_NAME_LENGTH]; ! int valuesNumber = (int)result[VALUES_NUMBER]; if (valuesNumber == 0) { closeKey(nativeHandle); return new String[0]; } // Get the values
*** 757,767 **** maxValueNameLength+1); if (windowsName == null) { String info = "Could not enumerate value #" + i + " of windows node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + "."; logger().warning(info); throw new BackingStoreException(info); } valueNames[i] = toJavaName(windowsName); } --- 757,767 ---- maxValueNameLength+1); if (windowsName == null) { String info = "Could not enumerate value #" + i + " of windows node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + "."; logger().warning(info); throw new BackingStoreException(info); } valueNames[i] = toJavaName(windowsName); }
*** 775,805 **** * Throws a BackingStoreException and logs a warning message, * if Windows registry is not available. */ protected String[] childrenNamesSpi() throws BackingStoreException { // Open key ! int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + "."); } // Get number of children ! int[] result = WindowsRegQueryInfoKey1(nativeHandle); if (result[ERROR_CODE] != ERROR_SUCCESS) { String info = "Could not query windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Integer.toHexString(rootNativeHandle()) + ". Windows RegQueryInfoKeyEx(...) returned error code " + result[ERROR_CODE] + "."; logger().warning(info); throw new BackingStoreException(info); } ! int maxKeyLength = result[MAX_KEY_LENGTH]; ! int subKeysNumber = result[SUBKEYS_NUMBER]; if (subKeysNumber == 0) { closeKey(nativeHandle); return new String[0]; } String[] subkeys = new String[subKeysNumber]; --- 775,805 ---- * Throws a BackingStoreException and logs a warning message, * if Windows registry is not available. */ protected String[] childrenNamesSpi() throws BackingStoreException { // Open key ! long nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + "."); } // Get number of children ! long[] result = WindowsRegQueryInfoKey1(nativeHandle); if (result[ERROR_CODE] != ERROR_SUCCESS) { String info = "Could not query windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Long.toHexString(rootNativeHandle()) + ". Windows RegQueryInfoKeyEx(...) returned error code " + result[ERROR_CODE] + "."; logger().warning(info); throw new BackingStoreException(info); } ! int maxKeyLength = (int)result[MAX_KEY_LENGTH]; ! int subKeysNumber = (int)result[SUBKEYS_NUMBER]; if (subKeysNumber == 0) { closeKey(nativeHandle); return new String[0]; } String[] subkeys = new String[subKeysNumber];
*** 810,820 **** maxKeyLength+1); if (windowsName == null) { String info = "Could not enumerate key #" + i + " of windows node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". "; logger().warning(info); throw new BackingStoreException(info); } String javaName = toJavaName(windowsName); children[i] = javaName; --- 810,820 ---- maxKeyLength+1); if (windowsName == null) { String info = "Could not enumerate key #" + i + " of windows node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". "; logger().warning(info); throw new BackingStoreException(info); } String javaName = toJavaName(windowsName); children[i] = javaName;
*** 837,860 **** } if (!isBackingStoreAvailable) { throw new BackingStoreException( "flush(): Backing store not available."); } ! int nativeHandle = openKey(KEY_READ); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + "."); } int result = WindowsRegFlushKey1(nativeHandle); if (result != ERROR_SUCCESS) { String info = "Could not flush windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + ". Windows RegFlushKey(...) returned error code " + result + "."; logger().warning(info); throw new BackingStoreException(info); } --- 837,860 ---- } if (!isBackingStoreAvailable) { throw new BackingStoreException( "flush(): Backing store not available."); } ! long nativeHandle = openKey(KEY_READ); if (nativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + "."); } int result = WindowsRegFlushKey1(nativeHandle); if (result != ERROR_SUCCESS) { String info = "Could not flush windows registry node " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + ". Windows RegFlushKey(...) returned error code " + result + "."; logger().warning(info); throw new BackingStoreException(info); }
*** 889,913 **** * Deletes underlying Windows registry node. * Throws a BackingStoreException and logs a warning, if Windows registry * is not available. */ public void removeNodeSpi() throws BackingStoreException { ! int parentNativeHandle = ((WindowsPreferences)parent()).openKey(DELETE); if (parentNativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open parent windows registry node of " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Integer.toHexString(rootNativeHandle()) + "."); } int result = WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name())); if (result != ERROR_SUCCESS) { String info = "Could not delete windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Integer.toHexString(rootNativeHandle()) + ". Windows RegDeleteKeyEx(...) returned error code " + result + "."; logger().warning(info); throw new BackingStoreException(info); } --- 889,913 ---- * Deletes underlying Windows registry node. * Throws a BackingStoreException and logs a warning, if Windows registry * is not available. */ public void removeNodeSpi() throws BackingStoreException { ! long parentNativeHandle = ((WindowsPreferences)parent()).openKey(DELETE); if (parentNativeHandle == NULL_NATIVE_HANDLE) { throw new BackingStoreException( "Could not open parent windows registry node of " + byteArrayToString(windowsAbsolutePath()) + " at root 0x" + ! Long.toHexString(rootNativeHandle()) + "."); } int result = WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name())); if (result != ERROR_SUCCESS) { String info = "Could not delete windows registry node " + byteArrayToString(windowsAbsolutePath()) + ! " at root 0x" + Long.toHexString(rootNativeHandle()) + ". Windows RegDeleteKeyEx(...) returned error code " + result + "."; logger().warning(info); throw new BackingStoreException(info); }
*** 1087,1097 **** for (int i = 0; i < javaName.length(); i++) { char ch = javaName.charAt(i); if ((ch < 0x0020) || (ch > 0x007f)){ // write \udddd windowsName.append("/u"); ! String hex = Integer.toHexString(javaName.charAt(i)); StringBuilder hex4 = new StringBuilder(hex); hex4.reverse(); int len = 4 - hex4.length(); for (int j = 0; j < len; j++){ hex4.append('0'); --- 1087,1097 ---- for (int i = 0; i < javaName.length(); i++) { char ch = javaName.charAt(i); if ((ch < 0x0020) || (ch > 0x007f)){ // write \udddd windowsName.append("/u"); ! String hex = Long.toHexString(javaName.charAt(i)); StringBuilder hex4 = new StringBuilder(hex); hex4.reverse(); int len = 4 - hex4.length(); for (int j = 0; j < len; j++){ hex4.append('0');
*** 1113,1123 **** } /** * Returns native handle for the top Windows node for this node. */ ! private int rootNativeHandle() { return (isUserNode() ? USER_ROOT_NATIVE_HANDLE : SYSTEM_ROOT_NATIVE_HANDLE); } --- 1113,1123 ---- } /** * Returns native handle for the top Windows node for this node. */ ! private long rootNativeHandle() { return (isUserNode() ? USER_ROOT_NATIVE_HANDLE : SYSTEM_ROOT_NATIVE_HANDLE); }
< prev index next >