676 + "value " + byteArrayToString(windowsAbsolutePath())+ "\\" +
677 toWindowsName(key) + " at root 0x" +
678 Integer.toHexString(rootNativeHandle()) +
679 ". Windows RegDeleteValue(...) returned error code " +
680 result + ".");
681 isBackingStoreAvailable = false;
682 }
683 closeKey(nativeHandle);
684 }
685
686 /**
687 * Implements <tt>AbstractPreferences</tt> <tt>keysSpi()</tt> method.
688 * Gets value names from the underlying Windows registry node.
689 * Throws a BackingStoreException and logs a warning, if
690 * Windows registry is unavailable.
691 */
692 protected String[] keysSpi() throws BackingStoreException{
693 // Find out the number of values
694 int nativeHandle = openKey(KEY_QUERY_VALUE);
695 if (nativeHandle == NULL_NATIVE_HANDLE) {
696 throw new BackingStoreException("Could not open windows"
697 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
698 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
699 }
700 int[] result = WindowsRegQueryInfoKey1(nativeHandle);
701 if (result[ERROR_CODE] != ERROR_SUCCESS) {
702 String info = "Could not query windows"
703 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
704 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
705 ". Windows RegQueryInfoKeyEx(...) returned error code " +
706 result[ERROR_CODE] + ".";
707 logger().warning(info);
708 throw new BackingStoreException(info);
709 }
710 int maxValueNameLength = result[MAX_VALUE_NAME_LENGTH];
711 int valuesNumber = result[VALUES_NUMBER];
712 if (valuesNumber == 0) {
713 closeKey(nativeHandle);
714 return new String[0];
715 }
716 // Get the values
717 String[] valueNames = new String[valuesNumber];
718 for (int i = 0; i < valuesNumber; i++) {
719 byte[] windowsName = WindowsRegEnumValue1(nativeHandle, i,
720 maxValueNameLength+1);
721 if (windowsName == null) {
722 String info =
725 Integer.toHexString(rootNativeHandle()) + ".";
726 logger().warning(info);
727 throw new BackingStoreException(info);
728 }
729 valueNames[i] = toJavaName(windowsName);
730 }
731 closeKey(nativeHandle);
732 return valueNames;
733 }
734
735 /**
736 * Implements <tt>AbstractPreferences</tt> <tt>childrenNamesSpi()</tt> method.
737 * Calls Windows registry to retrive children of this node.
738 * Throws a BackingStoreException and logs a warning message,
739 * if Windows registry is not available.
740 */
741 protected String[] childrenNamesSpi() throws BackingStoreException {
742 // Open key
743 int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS| KEY_QUERY_VALUE);
744 if (nativeHandle == NULL_NATIVE_HANDLE) {
745 throw new BackingStoreException("Could not open windows"
746 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
747 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
748 }
749 // Get number of children
750 int[] result = WindowsRegQueryInfoKey1(nativeHandle);
751 if (result[ERROR_CODE] != ERROR_SUCCESS) {
752 String info = "Could not query windows"
753 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
754 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
755 ". Windows RegQueryInfoKeyEx(...) returned error code " +
756 result[ERROR_CODE] + ".";
757 logger().warning(info);
758 throw new BackingStoreException(info);
759 }
760 int maxKeyLength = result[MAX_KEY_LENGTH];
761 int subKeysNumber = result[SUBKEYS_NUMBER];
762 if (subKeysNumber == 0) {
763 closeKey(nativeHandle);
764 return new String[0];
765 }
766 String[] subkeys = new String[subKeysNumber];
767 String[] children = new String[subKeysNumber];
768 // Get children
769 for (int i = 0; i < subKeysNumber; i++) {
770 byte[] windowsName = WindowsRegEnumKeyEx1(nativeHandle, i,
771 maxKeyLength+1);
772 if (windowsName == null) {
785 }
786
787 /**
788 * Implements <tt>Preferences</tt> <tt>flush()</tt> method.
789 * Flushes Windows registry changes to disk.
790 * Throws a BackingStoreException and logs a warning message if Windows
791 * registry is not available.
792 */
793 public void flush() throws BackingStoreException{
794
795 if (isRemoved()) {
796 parent.flush();
797 return;
798 }
799 if (!isBackingStoreAvailable) {
800 throw new BackingStoreException(
801 "flush(): Backing store not available.");
802 }
803 int nativeHandle = openKey(KEY_READ);
804 if (nativeHandle == NULL_NATIVE_HANDLE) {
805 throw new BackingStoreException("Could not open windows"
806 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
807 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
808 }
809 int result = WindowsRegFlushKey1(nativeHandle);
810 if (result != ERROR_SUCCESS) {
811 String info = "Could not flush windows "
812 + "registry node " + byteArrayToString(windowsAbsolutePath())
813 + " at root 0x" + Integer.toHexString(rootNativeHandle()) +
814 ". Windows RegFlushKey(...) returned error code " + result + ".";
815 logger().warning(info);
816 throw new BackingStoreException(info);
817 }
818 closeKey(nativeHandle);
819 }
820
821
822 /**
823 * Implements <tt>Preferences</tt> <tt>sync()</tt> method.
824 * Flushes Windows registry changes to disk. Equivalent to flush().
825 * @see flush()
834 * Implements <tt>AbstractPreferences</tt> <tt>childSpi()</tt> method.
835 * Constructs a child node with a
836 * given name and creates its underlying Windows registry node,
837 * if it does not exist.
838 * Logs a warning message, if Windows Registry is unavailable.
839 */
840 protected AbstractPreferences childSpi(String name) {
841 return new WindowsPreferences(this, name);
842 }
843
844 /**
845 * Implements <tt>AbstractPreferences</tt> <tt>removeNodeSpi()</tt> method.
846 * Deletes underlying Windows registry node.
847 * Throws a BackingStoreException and logs a warning, if Windows registry
848 * is not available.
849 */
850 public void removeNodeSpi() throws BackingStoreException {
851 int parentNativeHandle =
852 ((WindowsPreferences)parent()).openKey(DELETE);
853 if (parentNativeHandle == NULL_NATIVE_HANDLE) {
854 throw new BackingStoreException("Could not open parent windows"
855 + "registry node of " + byteArrayToString(windowsAbsolutePath()) +
856 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
857 }
858 int result =
859 WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
860 if (result != ERROR_SUCCESS) {
861 String info = "Could not delete windows "
862 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
863 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
864 ". Windows RegDeleteKeyEx(...) returned error code " +
865 result + ".";
866 logger().warning(info);
867 throw new BackingStoreException(info);
868 }
869 closeKey(parentNativeHandle);
870 }
871
872 /**
873 * Converts value's or node's name from its byte array representation to
874 * java string. Two encodings, simple and altBase64 are used. See
|
676 + "value " + byteArrayToString(windowsAbsolutePath())+ "\\" +
677 toWindowsName(key) + " at root 0x" +
678 Integer.toHexString(rootNativeHandle()) +
679 ". Windows RegDeleteValue(...) returned error code " +
680 result + ".");
681 isBackingStoreAvailable = false;
682 }
683 closeKey(nativeHandle);
684 }
685
686 /**
687 * Implements <tt>AbstractPreferences</tt> <tt>keysSpi()</tt> method.
688 * Gets value names from the underlying Windows registry node.
689 * Throws a BackingStoreException and logs a warning, if
690 * Windows registry is unavailable.
691 */
692 protected String[] keysSpi() throws BackingStoreException{
693 // Find out the number of values
694 int nativeHandle = openKey(KEY_QUERY_VALUE);
695 if (nativeHandle == NULL_NATIVE_HANDLE) {
696 throw new BackingStoreException("Could not open windows "
697 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
698 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
699 }
700 int[] result = WindowsRegQueryInfoKey1(nativeHandle);
701 if (result[ERROR_CODE] != ERROR_SUCCESS) {
702 String info = "Could not query windows "
703 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
704 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
705 ". Windows RegQueryInfoKeyEx(...) returned error code " +
706 result[ERROR_CODE] + ".";
707 logger().warning(info);
708 throw new BackingStoreException(info);
709 }
710 int maxValueNameLength = result[MAX_VALUE_NAME_LENGTH];
711 int valuesNumber = result[VALUES_NUMBER];
712 if (valuesNumber == 0) {
713 closeKey(nativeHandle);
714 return new String[0];
715 }
716 // Get the values
717 String[] valueNames = new String[valuesNumber];
718 for (int i = 0; i < valuesNumber; i++) {
719 byte[] windowsName = WindowsRegEnumValue1(nativeHandle, i,
720 maxValueNameLength+1);
721 if (windowsName == null) {
722 String info =
725 Integer.toHexString(rootNativeHandle()) + ".";
726 logger().warning(info);
727 throw new BackingStoreException(info);
728 }
729 valueNames[i] = toJavaName(windowsName);
730 }
731 closeKey(nativeHandle);
732 return valueNames;
733 }
734
735 /**
736 * Implements <tt>AbstractPreferences</tt> <tt>childrenNamesSpi()</tt> method.
737 * Calls Windows registry to retrive children of this node.
738 * Throws a BackingStoreException and logs a warning message,
739 * if Windows registry is not available.
740 */
741 protected String[] childrenNamesSpi() throws BackingStoreException {
742 // Open key
743 int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS| KEY_QUERY_VALUE);
744 if (nativeHandle == NULL_NATIVE_HANDLE) {
745 throw new BackingStoreException("Could not open windows "
746 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
747 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
748 }
749 // Get number of children
750 int[] result = WindowsRegQueryInfoKey1(nativeHandle);
751 if (result[ERROR_CODE] != ERROR_SUCCESS) {
752 String info = "Could not query windows "
753 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
754 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
755 ". Windows RegQueryInfoKeyEx(...) returned error code " +
756 result[ERROR_CODE] + ".";
757 logger().warning(info);
758 throw new BackingStoreException(info);
759 }
760 int maxKeyLength = result[MAX_KEY_LENGTH];
761 int subKeysNumber = result[SUBKEYS_NUMBER];
762 if (subKeysNumber == 0) {
763 closeKey(nativeHandle);
764 return new String[0];
765 }
766 String[] subkeys = new String[subKeysNumber];
767 String[] children = new String[subKeysNumber];
768 // Get children
769 for (int i = 0; i < subKeysNumber; i++) {
770 byte[] windowsName = WindowsRegEnumKeyEx1(nativeHandle, i,
771 maxKeyLength+1);
772 if (windowsName == null) {
785 }
786
787 /**
788 * Implements <tt>Preferences</tt> <tt>flush()</tt> method.
789 * Flushes Windows registry changes to disk.
790 * Throws a BackingStoreException and logs a warning message if Windows
791 * registry is not available.
792 */
793 public void flush() throws BackingStoreException{
794
795 if (isRemoved()) {
796 parent.flush();
797 return;
798 }
799 if (!isBackingStoreAvailable) {
800 throw new BackingStoreException(
801 "flush(): Backing store not available.");
802 }
803 int nativeHandle = openKey(KEY_READ);
804 if (nativeHandle == NULL_NATIVE_HANDLE) {
805 throw new BackingStoreException("Could not open windows "
806 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
807 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
808 }
809 int result = WindowsRegFlushKey1(nativeHandle);
810 if (result != ERROR_SUCCESS) {
811 String info = "Could not flush windows "
812 + "registry node " + byteArrayToString(windowsAbsolutePath())
813 + " at root 0x" + Integer.toHexString(rootNativeHandle()) +
814 ". Windows RegFlushKey(...) returned error code " + result + ".";
815 logger().warning(info);
816 throw new BackingStoreException(info);
817 }
818 closeKey(nativeHandle);
819 }
820
821
822 /**
823 * Implements <tt>Preferences</tt> <tt>sync()</tt> method.
824 * Flushes Windows registry changes to disk. Equivalent to flush().
825 * @see flush()
834 * Implements <tt>AbstractPreferences</tt> <tt>childSpi()</tt> method.
835 * Constructs a child node with a
836 * given name and creates its underlying Windows registry node,
837 * if it does not exist.
838 * Logs a warning message, if Windows Registry is unavailable.
839 */
840 protected AbstractPreferences childSpi(String name) {
841 return new WindowsPreferences(this, name);
842 }
843
844 /**
845 * Implements <tt>AbstractPreferences</tt> <tt>removeNodeSpi()</tt> method.
846 * Deletes underlying Windows registry node.
847 * Throws a BackingStoreException and logs a warning, if Windows registry
848 * is not available.
849 */
850 public void removeNodeSpi() throws BackingStoreException {
851 int parentNativeHandle =
852 ((WindowsPreferences)parent()).openKey(DELETE);
853 if (parentNativeHandle == NULL_NATIVE_HANDLE) {
854 throw new BackingStoreException("Could not open parent windows "
855 + "registry node of " + byteArrayToString(windowsAbsolutePath()) +
856 " at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
857 }
858 int result =
859 WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
860 if (result != ERROR_SUCCESS) {
861 String info = "Could not delete windows "
862 + "registry node " + byteArrayToString(windowsAbsolutePath()) +
863 " at root 0x" + Integer.toHexString(rootNativeHandle()) +
864 ". Windows RegDeleteKeyEx(...) returned error code " +
865 result + ".";
866 logger().warning(info);
867 throw new BackingStoreException(info);
868 }
869 closeKey(parentNativeHandle);
870 }
871
872 /**
873 * Converts value's or node's name from its byte array representation to
874 * java string. Two encodings, simple and altBase64 are used. See
|