com.coi.tools.os.win
Class RegistryImpl

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

public class RegistryImpl
extends java.lang.Object
implements MSWinConstants

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. The native methods uses the classes RegDataContainer and AccessControlList as in and output. Do not change the getter and setter methods of them. Do not try to implement a get or setValueACL because it will be nonsense. In the registry only keys have a ACL. not values.

Author:
Klaus Bartz

Field Summary
private  int currentRoot
           
private static java.lang.String DEFAULT_PLACEHOLDER
           
private  boolean doLogging
           
private  java.util.List logging
           
 
Fields inherited from interface com.coi.tools.os.win.MSWinConstants
ACCESS_SYSTEM_SECURITY, DELETE, FILE_ADD_FILE, FILE_ADD_SUBDIRECTORY, FILE_ALL_ACCESS, FILE_APPEND_DATA, FILE_CASE_PRESERVED_NAMES, FILE_CASE_SENSITIVE_SEARCH, FILE_CREATE_PIPE_INSTANCE, FILE_DELETE_CHILD, FILE_EXECUTE, FILE_FILE_COMPRESSION, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_LIST_DIRECTORY, FILE_PERSISTENT_ACLS, FILE_READ_ATTRIBUTES, FILE_READ_DATA, FILE_READ_EA, FILE_SUPPORTS_ENCRYPTION, FILE_SUPPORTS_OBJECT_IDS, FILE_SUPPORTS_REMOTE_STORAGE, FILE_SUPPORTS_REPARSE_POINTS, FILE_SUPPORTS_SPARSE_FILES, FILE_TRAVERSE, FILE_UNICODE_ON_DISK, FILE_VOLUME_IS_COMPRESSED, FILE_VOLUME_QUOTAS, FILE_WRITE_ATTRIBUTES, FILE_WRITE_DATA, FILE_WRITE_EA, GENERIC_ALL, GENERIC_EXECUTE, GENERIC_READ, GENERIC_WRITE, HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, HKEY_USERS, MAXIMUM_ALLOWED, READ_CONTROL, REG_BINARY, REG_DWORD, REG_EXPAND_SZ, REG_LINK, REG_MULTI_SZ, REG_NONE, REG_SZ, SPECIFIC_RIGHTS_ALL, STANDARD_RIGHTS_ALL, STANDARD_RIGHTS_EXECUTE, STANDARD_RIGHTS_READ, STANDARD_RIGHTS_REQUIRED, STANDARD_RIGHTS_WRITE, SYNCHRONIZE, WRITE_DAC, WRITE_OWNER
 
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
 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<java.lang.Object> getLoggingInfo()
          Returns a copy of the colected logging informations.
 int getRoot()
          Returns current root.
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  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  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.
 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

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. It is possible to declare keys without a sub path. This is only possible on roots which are no real roots (e.g. HKEY_CURRENT_USER which is a link to HKEY_USERS\GUID of current user). Therefore this method will be raise an exception if root is a real root and key contains no sub path.

Parameters:
root - to be used
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

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

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<java.lang.Object> getLoggingInfo()
Returns a copy of the colected logging informations.

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.

Parameters:
info - list containing RegistryLogItems to be used for logging

addLoggingInfo

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

Parameters:
info - list containing RegistryLogItems to be used for logging 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 -