com.jniwrapper.win32.registry
Class RegistryKey

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.Pointer.Void
          extended by com.jniwrapper.win32.Handle
              extended by com.jniwrapper.win32.registry.RegistryKey
All Implemented Interfaces:
com.jniwrapper.IntegerParameter, com.jniwrapper.PointerParameter

public class RegistryKey
extends Handle

Class RegistryKey represents a key level node in the Windows registry. Values for a registry key are managed by an RegistryKeyValues instance obtained from the values() method.


Nested Class Summary
static class RegistryKey.RegistryAccessMode
          Provides enumeration of all registry access modes.
 
Field Summary
static RegistryKey CLASSES_ROOT
          Windows registry base key HKEY_CLASSES_ROOT.
static RegistryKey CURRENT_CONFIG
          Windows registry base key HKEY_CURRENT_CONFIG.
static RegistryKey CURRENT_USER
          Windows registry base key HKEY_CURRENT_USER.
static RegistryKey DYN_DATA
          Windows registry base key HKEY_DYN_DATA.
static RegistryKey LOCAL_MACHINE
          Windows registry base key HKEY_LOCAL_MACHINE.
static RegistryKey PERFORMANCE_DATA
          Windows registry base key HKEY_PERFORMANCE_DATA.
static int REG_NOTIFY_CHANGE_ATTRIBUTES
           
static int REG_NOTIFY_CHANGE_LAST_SET
           
static int REG_NOTIFY_CHANGE_NAME
           
static int REG_NOTIFY_CHANGE_SECURITY
           
static RegistryKey USERS
          Windows registry base key HKEY_USERS.
 
Fields inherited from class com.jniwrapper.win32.Handle
INFINITE_TIMEOUT, INVALID_HANDLE_VALUE, STATUS_ABANDONED_WAIT_0, STATUS_TIMEOUT, STATUS_WAIT_0
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Method Summary
 void addRegistryEventListener(RegistryEventListener listener)
          Adds RegistryKey event listener.
protected  void checkError()
           
protected  void checkError(long errorCode)
           
 void close()
          Closes the key and flushes it to disk if the contents have been modified.
 RegistryKey copy(RegistryKey newBase, java.lang.String newName, boolean quietly)
          Copies opened key to another base with new name.
 RegistryKey createSubKey(java.lang.String subKey)
          Creates a new subkey or opens an existing one.
 RegistryKey createSubKey(java.lang.String subKey, boolean writable)
          Creates a new subkey or opens an existing one, with write access as specified.
 RegistryKey createSubKey(java.lang.String subKey, boolean writable, RegistryKey.RegistryAccessMode accessMode)
          Creates a new subkey or opens an existing one, with write access as specified.
 RegistryKey createSubKey(java.lang.String subKey, RegistryKey.RegistryAccessMode accessMode)
          Creates a new subkey or opens an existing one, with write access as specified.
 void deleteSubKey(java.lang.String subKey)
          Deletes the specified subkey is it doesn't include any subkeys.
 void deleteSubKey(java.lang.String subKey, RegistryKey.RegistryAccessMode accessMode)
          Deletes the specified subkey is it doesn't include any subkeys.
 void deleteSubTree(java.lang.String subKey)
          Deletes the specified subkey and all its subkeys.
 boolean equals(java.lang.Object obj)
          Determines whether two Object instances are equal.
 boolean exists(java.lang.String name)
          Checks if the specified subkey exists and can be opened.
 boolean exists(java.lang.String name, RegistryKey.RegistryAccessMode accessMode)
          Checks if the specified subkey exists and can be opened.
protected  void fireRegistryEvent(java.util.EventObject event)
          Notifies listeners about RegistryKey event.
 void flush()
          Writes all the attributes of the specified open RegistryKey into the registry.
 java.lang.String getAbsolutePath()
          Returns absolute path of the key.
 Handle getHandle()
          Deprecated. use this instead of this function
 java.lang.String getName()
          Retrieves the name of the key.
 java.lang.String getPath()
          Returns the path of the key.
 RegistryKey.RegistryAccessMode getRegistryAccessMode()
          Returns current registry access mode.
 RegistryKey getRootKey()
          Returns the Root of this registry key.
 int getSubKeyCount()
          Retrieves the count of subkeys at the base level for the current key.
 java.util.List getSubKeyNames()
          Retrieves List of strings that contains all the subkey names.
 java.util.List getSubkeys()
          Returns a list of RegistryKey that are subkeys of the current RegistryKey.
 int hashCode()
           
 RegistryKey openSubKey(java.lang.String name)
          Opens a subkey by the specified name (as read-only).
 RegistryKey openSubKey(java.lang.String name, boolean writable)
          Opens a subkey by the specified name.
 RegistryKey openSubKey(java.lang.String name, boolean writable, boolean quietly)
          Opens a subkey by the specified name.
 RegistryKey openSubKey(java.lang.String name, boolean writable, boolean quietly, RegistryKey.RegistryAccessMode accessMode)
          Opens a subkey by the specified name.
 RegistryKey openSubKey(java.lang.String name, boolean writable, RegistryKey.RegistryAccessMode accessMode)
          Opens a subkey by the specified name.
 RegistryKey openSubKey(java.lang.String name, RegistryKey.RegistryAccessMode accessMode)
          Opens a subkey by the specified name.
 void removeRegistryEventListener(RegistryEventListener listener)
          Removes RegistryKey event listener.
 void rename(java.lang.String newName)
          Renames opened registry key.
 void startChangeListening()
          Starts listening for changes in the RegistryKey.
 void startChangeListening(boolean watchSubtree, int filter)
          Starts listening for changes in the RegistryKey.
 void stopChangeListening()
          Stops listening for events in the RegistryKey.
 java.lang.String toString()
           
 RegistryKeyValues values()
          Returns RegistryKeyValues.
 
Methods inherited from class com.jniwrapper.win32.Handle
clone, closeHandle, waitFor, waitFor
 
Methods inherited from class com.jniwrapper.Pointer.Void
asFunction, asFunction, asTypedPointer, castTo, castTo, getDebugInfo, getLength, getValue, isNull, read, setValue, write
 
Methods inherited from class com.jniwrapper.Parameter
, a, a, acceptIOPerformer, asReturnValue, b, dataBufferAssigned, getAlignedLength, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, indent, pop, push, read, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASSES_ROOT

public static final RegistryKey CLASSES_ROOT
Windows registry base key HKEY_CLASSES_ROOT.


CURRENT_USER

public static final RegistryKey CURRENT_USER
Windows registry base key HKEY_CURRENT_USER.


LOCAL_MACHINE

public static final RegistryKey LOCAL_MACHINE
Windows registry base key HKEY_LOCAL_MACHINE.


USERS

public static final RegistryKey USERS
Windows registry base key HKEY_USERS.


PERFORMANCE_DATA

public static final RegistryKey PERFORMANCE_DATA
Windows registry base key HKEY_PERFORMANCE_DATA.


CURRENT_CONFIG

public static final RegistryKey CURRENT_CONFIG
Windows registry base key HKEY_CURRENT_CONFIG.


DYN_DATA

public static final RegistryKey DYN_DATA
Windows registry base key HKEY_DYN_DATA.


REG_NOTIFY_CHANGE_NAME

public static final int REG_NOTIFY_CHANGE_NAME
See Also:
Constant Field Values

REG_NOTIFY_CHANGE_ATTRIBUTES

public static final int REG_NOTIFY_CHANGE_ATTRIBUTES
See Also:
Constant Field Values

REG_NOTIFY_CHANGE_LAST_SET

public static final int REG_NOTIFY_CHANGE_LAST_SET
See Also:
Constant Field Values

REG_NOTIFY_CHANGE_SECURITY

public static final int REG_NOTIFY_CHANGE_SECURITY
See Also:
Constant Field Values
Method Detail

getRegistryAccessMode

public RegistryKey.RegistryAccessMode getRegistryAccessMode()
Returns current registry access mode.

Returns:
registry access mode.

getName

public java.lang.String getName()
Retrieves the name of the key.

Returns:
The absolute (qualified) name of the key.

getPath

public java.lang.String getPath()
Returns the path of the key.

Returns:
the path of the key.

getAbsolutePath

public java.lang.String getAbsolutePath()
Returns absolute path of the key. Absolute path is a concatenation of the path and name.

Returns:
absolute path of the key. Absolute path is a concatenation of the path and name.

checkError

protected void checkError()

checkError

protected void checkError(long errorCode)

getSubKeyCount

public int getSubKeyCount()
Retrieves the count of subkeys at the base level for the current key.

Returns:
count of subkeys for the current key.

close

public void close()
Closes the key and flushes it to disk if the contents have been modified.


createSubKey

public RegistryKey createSubKey(java.lang.String subKey,
                                boolean writable)
Creates a new subkey or opens an existing one, with write access as specified.

Parameters:
subKey - the name of the subkey to create.
writable - set to true if you need write access to the key.
Returns:
the subkey.

createSubKey

public RegistryKey createSubKey(java.lang.String subKey,
                                RegistryKey.RegistryAccessMode accessMode)
Creates a new subkey or opens an existing one, with write access as specified.

Parameters:
subKey - the name of the subkey to create.
accessMode - specifies registry access mode.
Returns:
the subkey.

createSubKey

public RegistryKey createSubKey(java.lang.String subKey,
                                boolean writable,
                                RegistryKey.RegistryAccessMode accessMode)
Creates a new subkey or opens an existing one, with write access as specified.

Parameters:
subKey - the name of the subkey to create.
writable - set to true if you need write access to the key.
accessMode - specifies registry access mode.
Returns:
the subkey.

createSubKey

public RegistryKey createSubKey(java.lang.String subKey)
Creates a new subkey or opens an existing one.

Parameters:
subKey - a sub-key path string.
Returns:
the subkey instance.

deleteSubKey

public void deleteSubKey(java.lang.String subKey)
Deletes the specified subkey is it doesn't include any subkeys. If it is necessary to delete whole subtree call deleteSubTree(java.lang.String).

Parameters:
subKey - the name of the subkey to delete.

deleteSubKey

public void deleteSubKey(java.lang.String subKey,
                         RegistryKey.RegistryAccessMode accessMode)
Deletes the specified subkey is it doesn't include any subkeys. If it is necessary to delete whole subtree call deleteSubTree(java.lang.String).

Parameters:
subKey - the name of the subkey to delete.
accessMode - specifies registry access mode.

deleteSubTree

public void deleteSubTree(java.lang.String subKey)
Deletes the specified subkey and all its subkeys.

Parameters:
subKey - the name of the subkey to delete.

rename

public void rename(java.lang.String newName)
Renames opened registry key.

Parameters:
newName -

getRootKey

public RegistryKey getRootKey()
Returns the Root of this registry key.

Returns:
the Root of this registry key

equals

public boolean equals(java.lang.Object obj)
Determines whether two Object instances are equal.

Overrides:
equals in class Handle
Parameters:
obj - The Object to compare with the current Object.
Returns:
true if the specified Object is equal to the current Object; otherwise, false.

hashCode

public int hashCode()
Overrides:
hashCode in class com.jniwrapper.Pointer.Void

flush

public void flush()
Writes all the attributes of the specified open RegistryKey into the registry.


getSubKeyNames

public java.util.List getSubKeyNames()
Retrieves List of strings that contains all the subkey names.

Returns:
a list containing the names of the subkeys for the current key.

toString

public java.lang.String toString()
Overrides:
toString in class com.jniwrapper.Pointer.Void
Returns:
a string representing the key.

openSubKey

public RegistryKey openSubKey(java.lang.String name)
Opens a subkey by the specified name (as read-only).

Parameters:
name - the name of the subkey to open.
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened.

openSubKey

public RegistryKey openSubKey(java.lang.String name,
                              boolean writable)
Opens a subkey by the specified name.

Parameters:
name - the name of the subkey to open.
writable - set to true if you need write access to the key.
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened.

openSubKey

public RegistryKey openSubKey(java.lang.String name,
                              boolean writable,
                              boolean quietly)
Opens a subkey by the specified name.

Parameters:
name - the name of the subkey to open.
writable - set to true if you need write access to the key.
quietly - if true, instructs the function not to throw RegistryException if there is an error during opening the key; if false, the exception is thrown.
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened and parameter is false.

openSubKey

public RegistryKey openSubKey(java.lang.String name,
                              boolean writable,
                              boolean quietly,
                              RegistryKey.RegistryAccessMode accessMode)
Opens a subkey by the specified name.

Parameters:
name - the name of the subkey to open.
writable - set to true if you need write access to the key.
quietly - if true, instructs the function not to throw RegistryException if there is an error during opening the key; if false, the exception is thrown.
accessMode - specifies registry access mode
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened and parameter is false.

openSubKey

public RegistryKey openSubKey(java.lang.String name,
                              boolean writable,
                              RegistryKey.RegistryAccessMode accessMode)
Opens a subkey by the specified name.

Parameters:
name - the name of the subkey to open.
writable - set to true if you need write access to the key.
accessMode - specifies registry access mode
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened and parameter is false.

openSubKey

public RegistryKey openSubKey(java.lang.String name,
                              RegistryKey.RegistryAccessMode accessMode)
Opens a subkey by the specified name.

Parameters:
name - the name of the subkey to open.
accessMode - specifies registry access mode
Returns:
subkey requested.
Throws:
RegistryException - if a sub key cannot be opened and parameter is false.

exists

public boolean exists(java.lang.String name)
Checks if the specified subkey exists and can be opened.

Parameters:
name - the name of the subkey to check.
Returns:
true if subkey exists; false if otherwise.

exists

public boolean exists(java.lang.String name,
                      RegistryKey.RegistryAccessMode accessMode)
Checks if the specified subkey exists and can be opened.

Parameters:
name - the name of the subkey to check.
accessMode - specifies registry access mode
Returns:
true if subkey exists; false if otherwise.

copy

public RegistryKey copy(RegistryKey newBase,
                        java.lang.String newName,
                        boolean quietly)
Copies opened key to another base with new name.

Parameters:
newBase - is a target registry base or null to leave key in the current base.
newName - is a target key name.
quietly - if true, instructs the function not to throw RegistryException if there the specified key already exists; if false, the exception is thrown.
Returns:
handle to the copy of registry key.

getSubkeys

public java.util.List getSubkeys()
Returns a list of RegistryKey that are subkeys of the current RegistryKey.

Returns:
a list of RegistryKey that are subkeys of the current RegistryKey.

values

public RegistryKeyValues values()
Returns RegistryKeyValues.

Returns:
values map.

getHandle

public Handle getHandle()
Deprecated. use this instead of this function

Returns handle of the RegistryKey.

Returns:
handle of the RegistryKey.

addRegistryEventListener

public void addRegistryEventListener(RegistryEventListener listener)
Adds RegistryKey event listener.

Parameters:
listener -

removeRegistryEventListener

public void removeRegistryEventListener(RegistryEventListener listener)
Removes RegistryKey event listener.

Parameters:
listener -

fireRegistryEvent

protected void fireRegistryEvent(java.util.EventObject event)
Notifies listeners about RegistryKey event.

Parameters:
event -

startChangeListening

public void startChangeListening(boolean watchSubtree,
                                 int filter)
Starts listening for changes in the RegistryKey.

Parameters:
watchSubtree -
filter -

startChangeListening

public void startChangeListening()
Starts listening for changes in the RegistryKey. It watches subtree and listens for all the changes.


stopChangeListening

public void stopChangeListening()
Stops listening for events in the RegistryKey.