com.coi.tools.os.win
Class RegistryImpl

java.lang.Object
  extended by com.coi.tools.os.win.RegistryImpl
Direct Known Subclasses:
Registry

public class RegistryImpl
extends java.lang.Object

System dependent helper for MS Windows registry handling. This class is only vaild on Windows. It declares naitve methods which are implemented in COIOSHelper.dll

Author:
Klaus Bartz

Field Summary
private  int currentRoot
           
private static java.lang.String DEFAULT_PLACEHOLDER
           
private  boolean doLogging
           
static int HKEY_CLASSES_ROOT
           
static int HKEY_CURRENT_CONFIG
           
static int HKEY_CURRENT_USER
           
static int HKEY_DYN_DATA
           
static int HKEY_LOCAL_MACHINE
           
static int HKEY_PERFORMANCE_DATA
           
static int HKEY_USERS
           
private  java.util.List logging
           
 
Constructor Summary
RegistryImpl()
          Creates a new empty RegistryImpl object.
 
Method Summary
 void activateLogging()
          Activates logging.
 void addLoggingInfo(java.util.List info)
          Adds copies of the contents of the given list of RegistryLogItems to the existent internal logging list.
 void createKey(int root, java.lang.String key)
          Creates the given key under the given root.
 void createKey(java.lang.String key)
          Creates the given key under the current root.
private  void createKeyN(int root, java.lang.String key)
           
 void deleteKey(java.lang.String key)
          Deletes a key under the current root if exist and it is empty, else throw an exception.
 void deleteKeyIfEmpty(int root, java.lang.String key)
          Deletes a key if it is empty, else do nothing.
 void deleteKeyIfEmpty(java.lang.String key)
          Deletes a key under the current root if it is empty, else do nothing.
private  void deleteKeyL(int root, java.lang.String key)
          Deletes a key with logging.
private  void deleteKeyN(int root, java.lang.String key)
           
 void deleteValue(java.lang.String key, java.lang.String value)
          Deletes a value.
private  void deleteValueL(int root, java.lang.String key, java.lang.String value)
          Deletes a value with logging.
private  void deleteValueN(int root, java.lang.String key, java.lang.String value)
           
private  boolean exist(int root, java.lang.String key)
           
 java.util.List getLoggingInfo()
          Returns a copy of the colected logging informations.
 int getRoot()
          Returns current root.
private  int getSubkeyCount(int root, java.lang.String key)
           
private  java.lang.String getSubkeyName(int root, java.lang.String key, int index)
           
private  java.lang.String[] getSubkeyNames(int root, java.lang.String key)
           
 java.lang.String[] getSubkeys(java.lang.String key)
          Returns all sub keys under the given key which is under the current root.
private  RegDataContainer getValue(int root, java.lang.String key, java.lang.String value)
           
 RegDataContainer getValue(java.lang.String key, java.lang.String value)
          Returns the value of the given value name as RegDataContainer.
 java.lang.Object getValueAsObject(java.lang.String key, java.lang.String value)
          Returns the value of the given value name as Object.
private  int getValueCount(int root, java.lang.String key)
           
private  java.lang.String getValueName(int root, java.lang.String key, int index)
           
private  java.lang.String[] getValueNames(int root, java.lang.String key)
           
 java.lang.String[] getValueNames(java.lang.String key)
          Returns all value names under the given key which is under the current root.
private  int getValueType(int root, java.lang.String key, java.lang.String value)
           
private  boolean isKeyEmpty(int root, java.lang.String key)
           
 boolean keyExist(int root, java.lang.String key)
          Returns whether the given key under the given root exist or not.
 boolean keyExist(java.lang.String key)
          Returns whether the given key under the current root exist or not.
private  void log(RegistryLogItem item)
          Adds the given item to the beginning of the logging list if logging is enabled, else do nothing.
private  void logAtEnd(RegistryLogItem item)
          Adds the given item to the end of the logging list if logging is enabled, else do nothing.
 void resetLogging()
          Creates a new (empty) logging list and activates logging.
 void rewind()
          Rewinds all logged actions.
 void setLoggingInfo(java.util.List info)
          Copies the contents of the given list of RegistryLogItems to a newly created internal logging list.
 void setRoot(int i)
          Sets the root id to the given value.
 void setValue(int root, java.lang.String key, java.lang.String value, RegDataContainer contents)
          Sets the given contents to the given registry value.
 void setValue(java.lang.String key, java.lang.String value, byte[] contents)
          Sets the given contents to the given registry value.
 void setValue(java.lang.String key, java.lang.String value, long contents)
          Sets the given contents to the given registry value.
 void setValue(java.lang.String key, java.lang.String value, RegDataContainer contents)
          Sets the given contents to the given registry value under current root.
 void setValue(java.lang.String key, java.lang.String value, java.lang.String contents)
          Sets the given contents to the given registry value.
 void setValue(java.lang.String key, java.lang.String value, java.lang.String[] contents)
          Sets the given contents to the given registry value.
private  void setValueN(int root, java.lang.String key, java.lang.String value, RegDataContainer contents)
           
private  void setValueR(int root, java.lang.String key, java.lang.String value, RegDataContainer contents)
          Sets the given contents to the given registry value.
 void suspendLogging()
          Suspends logging.
 boolean valueExist(java.lang.String key, java.lang.String value)
          Returns whether the given value exist under the current root or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HKEY_CLASSES_ROOT

public static final int HKEY_CLASSES_ROOT
See Also:
Constant Field Values

HKEY_CURRENT_USER

public static final int HKEY_CURRENT_USER
See Also:
Constant Field Values

HKEY_LOCAL_MACHINE

public static final int HKEY_LOCAL_MACHINE
See Also:
Constant Field Values

HKEY_USERS

public static final int HKEY_USERS
See Also:
Constant Field Values

HKEY_PERFORMANCE_DATA

public static final int HKEY_PERFORMANCE_DATA
See Also:
Constant Field Values

HKEY_CURRENT_CONFIG

public static final int HKEY_CURRENT_CONFIG
See Also:
Constant Field Values

HKEY_DYN_DATA

public static final int HKEY_DYN_DATA
See Also:
Constant Field Values

DEFAULT_PLACEHOLDER

private static final java.lang.String DEFAULT_PLACEHOLDER
See Also:
Constant Field Values

currentRoot

private int currentRoot

logging

private java.util.List logging

doLogging

private boolean doLogging
Constructor Detail

RegistryImpl

public RegistryImpl()
Creates a new empty RegistryImpl object.

Method Detail

getRoot

public int getRoot()
Returns current root.

Returns:
current root

setRoot

public void setRoot(int i)
Sets the root id to the given value.

Parameters:
i - root id to be set

getValue

public RegDataContainer getValue(java.lang.String key,
                                 java.lang.String value)
                          throws NativeLibException
Returns the value of the given value name as RegDataContainer.

Parameters:
key - key of the registry entry
value - value name of the registry entry
Returns:
the value of the given value name as RegDataContainer
Throws:
NativeLibException

getValueAsObject

public java.lang.Object getValueAsObject(java.lang.String key,
                                         java.lang.String value)
                                  throws NativeLibException
Returns the value of the given value name as Object. The real type depends to the type of the value.

Parameters:
key - key of the registry entry
value - value name of the registry entry
Returns:
the value of the given value name as RegDataContainer
Throws:
NativeLibException

getSubkeys

public java.lang.String[] getSubkeys(java.lang.String key)
                              throws NativeLibException
Returns all sub keys under the given key which is under the current root.

Parameters:
key - key for which the sub keys should be detected
Returns:
all sub keys under the given key which is under the current root
Throws:
NativeLibException

getValueNames

public java.lang.String[] getValueNames(java.lang.String key)
                                 throws NativeLibException
Returns all value names under the given key which is under the current root.

Parameters:
key - key for which the values should be detected
Returns:
all value names under the given key which is under the current root
Throws:
NativeLibException

createKey

public void createKey(java.lang.String key)
               throws NativeLibException
Creates the given key under the current root.

Parameters:
key - key to be created
Throws:
NativeLibException

createKey

public void createKey(int root,
                      java.lang.String key)
               throws NativeLibException
Creates the given key under the given root.

Parameters:
key - key to be created
Throws:
NativeLibException

keyExist

public boolean keyExist(java.lang.String key)
                 throws NativeLibException
Returns whether the given key under the current root exist or not.

Parameters:
key - key to be tested
Returns:
true if thekey exist, else false
Throws:
NativeLibException

keyExist

public boolean keyExist(int root,
                        java.lang.String key)
                 throws NativeLibException
Returns whether the given key under the given root exist or not.

Parameters:
root - to be used
key - key to be tested
Returns:
true if thekey exist, else false
Throws:
NativeLibException

valueExist

public boolean valueExist(java.lang.String key,
                          java.lang.String value)
                   throws NativeLibException
Returns whether the given value exist under the current root or not.

Parameters:
key - key of the value for which should be tested
value - value to be tested
Returns:
true if the value exist, else false
Throws:
NativeLibException

setValue

public void setValue(java.lang.String key,
                     java.lang.String value,
                     java.lang.String contents)
              throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. REG_SZ is used as registry value type.

Parameters:
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

setValue

public void setValue(java.lang.String key,
                     java.lang.String value,
                     java.lang.String[] contents)
              throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. REG_MULTI_SZ is used as registry value type.

Parameters:
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

setValue

public void setValue(java.lang.String key,
                     java.lang.String value,
                     byte[] contents)
              throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. REG_BINARY is used as registry value type.

Parameters:
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

setValue

public void setValue(java.lang.String key,
                     java.lang.String value,
                     long contents)
              throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. REG_DWORD is used as registry value type.

Parameters:
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

setValue

public void setValue(java.lang.String key,
                     java.lang.String value,
                     RegDataContainer contents)
              throws NativeLibException
Sets the given contents to the given registry value under current root. If a sub key or the registry value does not exist, it will be created. The used registry value type will be determined by the type of the RegDataContainer.

Parameters:
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

setValue

public void setValue(int root,
                     java.lang.String key,
                     java.lang.String value,
                     RegDataContainer contents)
              throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. The used registry value type will be determined by the type of the RegDataContainer.

Parameters:
root - id for the root of the key
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

deleteKey

public void deleteKey(java.lang.String key)
               throws NativeLibException
Deletes a key under the current root if exist and it is empty, else throw an exception.

Parameters:
key - key to be deleted
Throws:
NativeLibException

deleteKeyIfEmpty

public void deleteKeyIfEmpty(java.lang.String key)
                      throws NativeLibException
Deletes a key under the current root if it is empty, else do nothing.

Parameters:
key - key to be deleted
Throws:
NativeLibException

deleteKeyIfEmpty

public void deleteKeyIfEmpty(int root,
                             java.lang.String key)
                      throws NativeLibException
Deletes a key if it is empty, else do nothing.

Parameters:
root - id for the root of the key
key - key to be deleted
Throws:
NativeLibException

deleteValue

public void deleteValue(java.lang.String key,
                        java.lang.String value)
                 throws NativeLibException
Deletes a value.

Parameters:
key - key of the value which should be deleted
value - value name to be deleted
Throws:
NativeLibException

deleteKeyL

private void deleteKeyL(int root,
                        java.lang.String key)
                 throws NativeLibException
Deletes a key with logging.

Parameters:
root - id for the root of the key
key - key to be deleted
Throws:
NativeLibException

deleteValueL

private void deleteValueL(int root,
                          java.lang.String key,
                          java.lang.String value)
                   throws NativeLibException
Deletes a value with logging.

Parameters:
root - id for the root of the key
key - key of the value which should be deleted
value - value name to be deleted
Throws:
NativeLibException

rewind

public void rewind()
            throws java.lang.IllegalArgumentException,
                   NativeLibException
Rewinds all logged actions.

Throws:
java.lang.IllegalArgumentException
NativeLibException

setValueR

private void setValueR(int root,
                       java.lang.String key,
                       java.lang.String value,
                       RegDataContainer contents)
                throws NativeLibException
Sets the given contents to the given registry value. If a sub key or the registry value does not exist, it will be created. The used registry value type will be determined by the type of the RegDataContainer.

Parameters:
root - id for the root of the key
key - the registry key which should be used or created
value - the registry value into which the contents should be set
contents - the contents for the value
Throws:
NativeLibException

exist

private boolean exist(int root,
                      java.lang.String key)
               throws NativeLibException
Throws:
NativeLibException

createKeyN

private void createKeyN(int root,
                        java.lang.String key)
                 throws NativeLibException
Throws:
NativeLibException

setValueN

private void setValueN(int root,
                       java.lang.String key,
                       java.lang.String value,
                       RegDataContainer contents)
                throws NativeLibException
Throws:
NativeLibException

getValueType

private int getValueType(int root,
                         java.lang.String key,
                         java.lang.String value)
                  throws NativeLibException
Throws:
NativeLibException

getValue

private RegDataContainer getValue(int root,
                                  java.lang.String key,
                                  java.lang.String value)
                           throws NativeLibException
Throws:
NativeLibException

deleteValueN

private void deleteValueN(int root,
                          java.lang.String key,
                          java.lang.String value)
                   throws NativeLibException
Throws:
NativeLibException

deleteKeyN

private void deleteKeyN(int root,
                        java.lang.String key)
                 throws NativeLibException
Throws:
NativeLibException

isKeyEmpty

private boolean isKeyEmpty(int root,
                           java.lang.String key)
                    throws NativeLibException
Throws:
NativeLibException

getSubkeyCount

private int getSubkeyCount(int root,
                           java.lang.String key)
                    throws NativeLibException
Throws:
NativeLibException

getValueCount

private int getValueCount(int root,
                          java.lang.String key)
                   throws NativeLibException
Throws:
NativeLibException

getSubkeyName

private java.lang.String getSubkeyName(int root,
                                       java.lang.String key,
                                       int index)
                                throws NativeLibException
Throws:
NativeLibException

getValueName

private java.lang.String getValueName(int root,
                                      java.lang.String key,
                                      int index)
                               throws NativeLibException
Throws:
NativeLibException

getSubkeyNames

private java.lang.String[] getSubkeyNames(int root,
                                          java.lang.String key)
                                   throws NativeLibException
Throws:
NativeLibException

getValueNames

private java.lang.String[] getValueNames(int root,
                                         java.lang.String key)
                                  throws NativeLibException
Throws:
NativeLibException

resetLogging

public void resetLogging()
Creates a new (empty) logging list and activates logging.


suspendLogging

public void suspendLogging()
Suspends logging.


activateLogging

public void activateLogging()
Activates logging.


getLoggingInfo

public java.util.List getLoggingInfo()
Returns a copy of the colected logging informations.


setLoggingInfo

public void setLoggingInfo(java.util.List info)
Copies the contents of the given list of RegistryLogItems to a newly created internal logging list.


addLoggingInfo

public void addLoggingInfo(java.util.List info)
Adds copies of the contents of the given list of RegistryLogItems to the existent internal logging list.


log

private void log(RegistryLogItem item)
Adds the given item to the beginning of the logging list if logging is enabled, else do nothing.

Parameters:
item -

logAtEnd

private void logAtEnd(RegistryLogItem item)
Adds the given item to the end of the logging list if logging is enabled, else do nothing.

Parameters:
item -