at.jta
Class Regor

java.lang.Object
  extended by at.jta.Regor

public final class Regor
extends java.lang.Object

Title: Class is 100% pur Java Registry handle (just can write/read string values)

Description: You can read, delete or create any key in the registry (when you have access rights). But you just can read/delete and set string values! The java.dll doenst provide any other feature

Copyright: Copyright (c) 2006

Company: Taschek Joerg

Version:
2.0 22.03.2007 Methods are renamed and now called by the function they are implementing and the document is now in english, instead of german
Author:
Taschek Joerg

Field Summary
static int DELETE
          Security Mask need by openKey - just for delete
static int ERROR_ACCESS_DENIED
           
static int ERROR_CODE
           
static int ERROR_FILE_NOT_FOUND
           
static int ERROR_SUCCESS
           
static int HKEY_CLASSES_ROOT
          the handle to the HKEY_CLASSES_ROOT registry root node
static int HKEY_CURRENT_USER
          the handle to the HEKY_CURRENT_USER registry root node
static int HKEY_LOCAL_MACHINE
          the handle to the HKEY_LOCAL_MACHINE registry root node
static int KEY_ALL_ACCESS
          Security Mask need by openKey - highest access to do everything (default access by openkey without security mask)
static int KEY_CREATE_SUB_KEY
          Security Mask need by openKey - for creating sub keys
static int KEY_ENUMERATE_SUB_KEYS
          Security Mask need by openKey - for enum sub keys
static int KEY_QUERY_VALUE
          Security Mask need by openKey - just for querying values
static int KEY_READ
          Security Mask need by openKey - for key reading
static int KEY_SET_VALUE
          Security Mask need by openKey - just for setting values
static int KEY_WRITE
          Security Mask need by openKey - for writing keys
static int MAX_KEY_LENGTH
           
static int MAX_VALUE_NAME_LENGTH
           
static int NATIVE_HANDLE
           
static int SUBKEYS_NUMBER
           
static int VALUES_NUMBER
           
 
Constructor Summary
Regor()
          Constructor to handle with windows registry
 
Method Summary
 int closeKey(int key)
          Close an obtained key for right usage
 int createKey(int key, java.lang.String subkey)
          Create new key/subkey in the registry with the specified name Attentition: if the key is successfully returned, you should close and open the key again, because the obtained key doesnt have a high access level (so maybe creating or deleting a key/value wouldn´t be successful)
 int delKey(int key, java.lang.String subkey)
          deletes a key/subkey from the registry
 int delValue(int key, java.lang.String valueName)
          Method deletes the specified String value
 byte[] enumKeys(int key, int subkeyIndex, int maxKeyNameLength)
          Reading the subkey name out of the registry (to obtain the count and the maxKeyNameLength use getChildInformation method
 byte[] enumValueName(int key, int valueNameIndex, int maxValueNameLength)
          Reading every valueName (not only the string value) out of the registry handle (for maximum value index and maxValueNameLength use the getChildInformation method
 int flushKey(int key)
          Flush method - dont know what the method exactly does just implemented because i found it in the java sun source
 int[] getChildInformation(int key)
          Reads information about the current opened key (use it when you want to enumKey or enumValueName to determine the maximum key length and the count of keys)
 java.util.List listKeys(int key)
          Returns all subkeys from the given key
 java.util.List listKeys(int key, java.lang.String subkey)
          Returns all subkeys from the given key and subkey
 java.util.List listValueNames(int key)
          Returns every valueName (not only the String value names)
 java.util.List listValueNames(int key, java.lang.String subkey)
          Returns every valueName (not only the String value names)
static void main(java.lang.String[] args)
          main for testing and some examples are stored here
 int openKey(int key, java.lang.String subkey)
          Opens a registry key
 int openKey(int key, java.lang.String subkey, int security_mask)
          Opens a registry key
static java.lang.String parseValue(byte[] buf)
          Method removes the trailing \0 which is returned from the java.dll (just if the last sign is a \0)
 byte[] readValue(int key, java.lang.String valueName)
          Reads the value of an string value
 int setValue(int key, java.lang.String valueName, java.lang.String value)
          Method set the specified string value Methode setzt (oder erstellt) einen Wert auf eine Zeichenfolge Will man den defaulteintrag ändern, so muss man valueName "" übergeben
 
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
the handle to the HKEY_CLASSES_ROOT registry root node

See Also:
Constant Field Values

HKEY_CURRENT_USER

public static final int HKEY_CURRENT_USER
the handle to the HEKY_CURRENT_USER registry root node

See Also:
Constant Field Values

HKEY_LOCAL_MACHINE

public static final int HKEY_LOCAL_MACHINE
the handle to the HKEY_LOCAL_MACHINE registry root node

See Also:
Constant Field Values

ERROR_SUCCESS

public static final int ERROR_SUCCESS
See Also:
Constant Field Values

ERROR_FILE_NOT_FOUND

public static final int ERROR_FILE_NOT_FOUND
See Also:
Constant Field Values

ERROR_ACCESS_DENIED

public static final int ERROR_ACCESS_DENIED
See Also:
Constant Field Values

NATIVE_HANDLE

public static final int NATIVE_HANDLE
See Also:
Constant Field Values

ERROR_CODE

public static final int ERROR_CODE
See Also:
Constant Field Values

SUBKEYS_NUMBER

public static final int SUBKEYS_NUMBER
See Also:
Constant Field Values

VALUES_NUMBER

public static final int VALUES_NUMBER
See Also:
Constant Field Values

MAX_KEY_LENGTH

public static final int MAX_KEY_LENGTH
See Also:
Constant Field Values

MAX_VALUE_NAME_LENGTH

public static final int MAX_VALUE_NAME_LENGTH
See Also:
Constant Field Values

DELETE

public static final int DELETE
Security Mask need by openKey - just for delete

See Also:
Constant Field Values

KEY_QUERY_VALUE

public static final int KEY_QUERY_VALUE
Security Mask need by openKey - just for querying values

See Also:
Constant Field Values

KEY_SET_VALUE

public static final int KEY_SET_VALUE
Security Mask need by openKey - just for setting values

See Also:
Constant Field Values

KEY_CREATE_SUB_KEY

public static final int KEY_CREATE_SUB_KEY
Security Mask need by openKey - for creating sub keys

See Also:
Constant Field Values

KEY_ENUMERATE_SUB_KEYS

public static final int KEY_ENUMERATE_SUB_KEYS
Security Mask need by openKey - for enum sub keys

See Also:
Constant Field Values

KEY_READ

public static final int KEY_READ
Security Mask need by openKey - for key reading

See Also:
Constant Field Values

KEY_WRITE

public static final int KEY_WRITE
Security Mask need by openKey - for writing keys

See Also:
Constant Field Values

KEY_ALL_ACCESS

public static final int KEY_ALL_ACCESS
Security Mask need by openKey - highest access to do everything (default access by openkey without security mask)

See Also:
Constant Field Values
Constructor Detail

Regor

public Regor()
      throws RegistryErrorException
Constructor to handle with windows registry

Throws:
RegistryErrorException - throws an registryerrorException when its not able to get a handle to the registry methods
NotSupportedOSException - throws an notSupportedOSException if the registry is not used in windows
Method Detail

enumValueName

public byte[] enumValueName(int key,
                            int valueNameIndex,
                            int maxValueNameLength)
                     throws RegistryErrorException
Reading every valueName (not only the string value) out of the registry handle (for maximum value index and maxValueNameLength use the getChildInformation method

Parameters:
key - the handle to the parent key obtained from openKey
valueNameIndex - the index of the valueName name - starting from 0 going to the maximum count from the getChildInformation stored in array index 2
maxValueNameLength - maximum length of valueName name (used because for memory allocating in the java.dll - if you obtain the size from getChildInformation increase the [4] int array by 1)
Returns:
byte[] either the name of the valueName or null if not found or an error occurs or if the maxValueNameLength is to short
Throws:
RegistryErrorException

listValueNames

public java.util.List listValueNames(int key,
                                     java.lang.String subkey)
                              throws RegistryErrorException
Returns every valueName (not only the String value names)

Parameters:
key - either one of the root nodes or a key obtained from openKey
subkey - a string to a subkey - if the subkey is empty or null the information will be obtained from the given key
Returns:
List on success and found a filled list with strings will be returned - on error or nothing found null will be returned
Throws:
RegistryErrorException

listValueNames

public java.util.List listValueNames(int key)
                              throws RegistryErrorException
Returns every valueName (not only the String value names)

Parameters:
key - either one of the root nodes or a key obtained from openKey
Returns:
List on success and found a filled list with strings will be returned - on error or nothing found null will be returned
Throws:
RegistryErrorException

enumKeys

public byte[] enumKeys(int key,
                       int subkeyIndex,
                       int maxKeyNameLength)
                throws RegistryErrorException
Reading the subkey name out of the registry (to obtain the count and the maxKeyNameLength use getChildInformation method

Parameters:
key - the handle to the key obtained by openKey
subkeyIndex - index from the subkey from which you want to obtain the name (start with 0 - the maximum count you get from getChildInformation method in array [0])
maxKeyNameLength - the maximum length of a subkey name (used because for memory allocating in the java.dll - if you obtain the size from getChildInformation increase the [3] int array by 1 )
Returns:
byte[] on error or not found or the maxKeyNameLength is to short it will returns null, on success the name of the subkey
Throws:
RegistryErrorException

listKeys

public java.util.List listKeys(int key,
                               java.lang.String subkey)
                        throws RegistryErrorException
Returns all subkeys from the given key and subkey

Parameters:
key - either one of the root nodes or a key obtained from openKey
subkey - a string to a subkey - if the subkey is empty or null the information will be obtained from the given key
Returns:
List on success and found a filled list with strings will be returned - on error or nothing found null will be returned
Throws:
RegistryErrorException

listKeys

public java.util.List listKeys(int key)
                        throws RegistryErrorException
Returns all subkeys from the given key

Parameters:
key - either one of the root nodes or a key obtained from openKey
Returns:
List on success and found a filled list with strings will be returned - on error or nothing found null will be returned
Throws:
RegistryErrorException

getChildInformation

public int[] getChildInformation(int key)
                          throws RegistryErrorException
Reads information about the current opened key (use it when you want to enumKey or enumValueName to determine the maximum key length and the count of keys)

Parameters:
key - the key which you obtained from openKey
Returns:
int[0] the count of the subkeys,[2] count of valuenames, [3] the maximum length of a subkey! the maximum length of valuename is stored in[4] (for other operations you should increase the [3] or [4] value by 1 because of the terminating \0 in C - because you handle with the java.dll) if nothing found or illegal key, the values are -1 of the array (at index 1 the value would be 6 the other -1)
Throws:
RegistryErrorException

delValue

public int delValue(int key,
                    java.lang.String valueName)
             throws RegistryErrorException
Method deletes the specified String value

Parameters:
key - the key obtained by openKey
valueName - name of String value you want to delete (if the string is empty or null the default entry will be deleted)
Returns:
int
Throws:
RegistryErrorException

setValue

public int setValue(int key,
                    java.lang.String valueName,
                    java.lang.String value)
             throws RegistryErrorException
Method set the specified string value Methode setzt (oder erstellt) einen Wert auf eine Zeichenfolge Will man den defaulteintrag ändern, so muss man valueName "" übergeben

Parameters:
key - obtained by openKey
valueName - the string value name in the registry you want to set
value - the new value you want to set
Returns:
on success, return is ERROR_SUCCESS if not -1 or sth else will be returned
Throws:
RegistryErrorException

readValue

public byte[] readValue(int key,
                        java.lang.String valueName)
                 throws RegistryErrorException
Reads the value of an string value

Parameters:
key - obtained from openKey
valueName - the string value which you want to read (if you want to obtain the default entry the valueName should be empty or NULL)
Returns:
byte[] if found the data in the string value will be returned (to get a string use the class method parseValue(byte[])) on error NULL will be returned
Throws:
RegistryErrorException

flushKey

public int flushKey(int key)
             throws RegistryErrorException
Flush method - dont know what the method exactly does just implemented because i found it in the java sun source

Parameters:
key - obtained the key from openKey
Returns:
on success, ERROR_SUCESS will be returned! on error -1 or sth else
Throws:
RegistryErrorException

delKey

public int delKey(int key,
                  java.lang.String subkey)
           throws RegistryErrorException
deletes a key/subkey from the registry

Parameters:
key - the parent key obtained by openKey
subkey - the key name you want to delete
Returns:
int ERROR_SUCCESS wenn erfolgreich
Throws:
RegistryErrorException - if subkey is empty or null or any other exception occurs

createKey

public int createKey(int key,
                     java.lang.String subkey)
              throws RegistryErrorException
Create new key/subkey in the registry with the specified name Attentition: if the key is successfully returned, you should close and open the key again, because the obtained key doesnt have a high access level (so maybe creating or deleting a key/value wouldn´t be successful)

Parameters:
key - handle to parent key obtained from openKey
subkey - name of the key/subkey you want to create
Returns:
on success the handle to the new key will be returned, otherwhise it will be -1
Throws:
RegistryErrorException

closeKey

public int closeKey(int key)
             throws RegistryErrorException
Close an obtained key for right usage

Parameters:
key - the key handle
Returns:
int on error it will be -1
Throws:
RegistryErrorException

openKey

public int openKey(int key,
                   java.lang.String subkey,
                   int security_mask)
            throws RegistryErrorException
Opens a registry key

Parameters:
key - one of the registry root nodes - either HKEY_CLASSES_ROOT, HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
subkey - the name of the key/subkey like SOFTWARE or HARDWARE - for subkeys use the \\ as delimiter f.e. : SOFTWARE\\MICROSOFT if subkey name is "" or null it returns the handle to the root node
security_mask - the security mask to handle with the opened key (see security mask doc at the begin for detailed information)
Returns:
int on error -1 (when not found or not allowed) otherwhise the handle to the obtained key
Throws:
RegistryErrorException

openKey

public int openKey(int key,
                   java.lang.String subkey)
            throws RegistryErrorException
Opens a registry key

Parameters:
key - one of the registry root nodes - either HKEY_CLASSES_ROOT, HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
subkey - the name of the key/subkey like SOFTWARE or HARDWARE - for subkeys use the \\ as delimiter f.e. : SOFTWARE\\MICROSOFT if subkey name is "" or null it returns the handle to the root node
Returns:
int -1 if not found or not allowed (attention here this methods allways uses the KEY_ALL_ACCESS security mask) on success the handle to key will be returned
Throws:
RegistryErrorException

parseValue

public static java.lang.String parseValue(byte[] buf)
Method removes the trailing \0 which is returned from the java.dll (just if the last sign is a \0)

Parameters:
buf - the byte[] buffer which every read method returns
Returns:
String a parsed string without the trailing \0

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
main for testing and some examples are stored here

Parameters:
args - String[]
Throws:
java.lang.Exception