public class Registry
extends java.lang.Object
ListBox lb; private void log(String s) { lb.add(s); lb.selectLast(); } public void initUI() { ByteArrayStream bas = new ByteArrayStream(10); DataStreamLE ds = new DataStreamLE(bas); lb = new ListBox(); lb.enableHorizontalScroll(); add(lb, LEFT,TOP,FILL,FILL); try { log("adding int 0x12345678"); Registry.set(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","IntKey",0x12345678); log("added. now retrieving..."); int ires = Registry.getInt(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","IntKey"); log("int retrieved: "+Convert.unsigned2hex(ires,8)); log("adding string \"Bárbara\""); Registry.set(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","StringKey","B�rbara"); log("added. now retrieving..."); String sres = Registry.getString(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","StringKey"); log("string retrieved: "+sres); double dvalue = 1234.56789; log("adding blob double value: "+dvalue); ds.writeDouble(dvalue); Registry.set(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","BlobKey",bas.toByteArray()); log("added. now retrieving..."); byte[] bres = Registry.getBlob(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","BlobKey"); bas.setBuffer(bres); double dres = ds.readDouble(); log("double retrieved: "+dres); log("deleting string value"); Registry.delete(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","StringKey"); log("deleted. trying to retrieve..."); try { sres = Registry.getString(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","StringKey"); log("Failure! delete didn't work"); } catch (ElementNotFoundException enfe) { log("Success: the deleted key was not found (as expected)"); } log("deleting the whole key"); Registry.delete(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test"); log("deleted. trying to retrieve..."); try { sres = Registry.getString(Registry.HKEY_CURRENT_USER, "Software\\TotalCross\\appSettings\\Test","IntKey"); log("Failure! delete didn't work"); } catch (ElementNotFoundException enfe) { log("Success: the deleted key was not found (as expected)"); } log("Tests finished."); } catch (Exception e) { MessageBox.showException(e, true); } }And here's a full sample for Palm OS.
ListBox lb; private void log(String s) { lb.add(s); lb.selectLast(); } public void initUI() { ByteArrayStream bas = new ByteArrayStream(10); DataStreamLE ds = new DataStreamLE(bas); lb = new ListBox(); lb.enableHorizontalScroll(); add(lb, LEFT,TOP,FILL,FILL); try { // retrieves the ROM version from the Feature manager int ret = Registry.getInt(Registry.FEATURE, "psys", "1"); log("rom version: "+Convert.unsigned2hex(ret,8)); log("adding int 0x12345678"); Registry.set(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"1",0x12345678); log("added. now retrieving..."); int ires = Registry.getInt(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"1"); log("int retrieved: "+Convert.unsigned2hex(ires,8)); log("adding string \"Bárbara\""); Registry.set(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"2","B�rbara"); log("added. now retrieving..."); String sres = Registry.getString(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"2"); log("string retrieved: "+sres); double dvalue = 1234.56789; log("adding blob double value: "+dvalue); ds.writeDouble(dvalue); Registry.set(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"3",bas.toByteArray()); log("added. now retrieving..."); byte[] bres = Registry.getBlob(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"3"); bas.setBuffer(bres); double dres = ds.readDouble(); log("double retrieved: "+dres); log("deleting string value"); Registry.delete(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"2"); log("deleted. trying to retrieve..."); try { sres = Registry.getString(Registry.UNSAVED_PREFERENCES, Settings.applicationId,"2"); log("Failure! delete didn't work"); } catch (ElementNotFoundException enfe) { log("Success: the deleted key was not found (as expected)"); } log("Tests finished."); } catch (Exception e) { MessageBox.showException(e, true); } }
Modifier and Type | Field and Description |
---|---|
static int |
FEATURE
PalmOS-specific value to be used in the hk parameter.
|
static int |
HKEY_CLASSES_ROOT
Windows-specific value to be used in the hk parameter.
|
static int |
HKEY_CURRENT_USER
Windows-specific value to be used in the hk parameter.
|
static int |
HKEY_LOCAL_MACHINE
Windows-specific value to be used in the hk parameter.
|
static int |
HKEY_USERS
Windows-specific value to be used in the hk parameter.
|
static int |
SAVED_PREFERENCES
PalmOS-specific value to be used in the hk parameter.
|
static int |
UNSAVED_PREFERENCES
PalmOS-specific value to be used in the hk parameter.
|
Constructor and Description |
---|
Registry() |
Modifier and Type | Method and Description |
---|---|
static boolean |
delete(int hk,
java.lang.String key)
Deletes a key with all its values.
|
static boolean |
delete(int hk,
java.lang.String key,
java.lang.String value)
Deletes a specific value.
|
static byte[] |
getBlob(int hk,
java.lang.String key,
java.lang.String value)
Returns a String at the given location.
|
static int |
getInt(int hk,
java.lang.String key,
java.lang.String value)
Returns an integer at the given location.
|
static java.lang.String |
getString(int hk,
java.lang.String key,
java.lang.String value)
Returns a String at the given location.
|
static java.lang.String[] |
list(int hk,
java.lang.String key)
Lists all children keys of the given key.
|
static void |
set(int hk,
java.lang.String key,
java.lang.String value,
byte[] data)
Sets a byte array (blob) value at the given location.
|
static void |
set(int hk,
java.lang.String key,
java.lang.String value,
int data)
Sets an integer value at the given location.
|
static void |
set(int hk,
java.lang.String key,
java.lang.String value,
java.lang.String data)
Sets a String value at the given location.
|
public static final int HKEY_CLASSES_ROOT
public static final int HKEY_CURRENT_USER
public static final int HKEY_LOCAL_MACHINE
public static final int HKEY_USERS
public static final int FEATURE
public static final int SAVED_PREFERENCES
public static final int UNSAVED_PREFERENCES
public static int getInt(int hk, java.lang.String key, java.lang.String value) throws ElementNotFoundException, java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).ElementNotFoundException
- if the hk, key or value was not found.java.lang.Exception
- if there was an error when retrieving the data.public static java.lang.String getString(int hk, java.lang.String key, java.lang.String value) throws ElementNotFoundException, java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).ElementNotFoundException
- if the hk, key or value was not found.java.lang.Exception
- if there was an error when retrieving the data.public static byte[] getBlob(int hk, java.lang.String key, java.lang.String value) throws ElementNotFoundException, java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).ElementNotFoundException
- if the hk, key or value was not found.java.lang.Exception
- if there was an error when retrieving the data.public static void set(int hk, java.lang.String key, java.lang.String value, int data) throws java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).data
- The data to be written.java.lang.Exception
- if there was an error when setting the data.public static void set(int hk, java.lang.String key, java.lang.String value, java.lang.String data) throws java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).data
- The data to be written. In Palm OS, its limited to 64KB.java.lang.Exception
- if there was an error when setting the data.public static void set(int hk, java.lang.String key, java.lang.String value, byte[] data) throws java.lang.Exception
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.
In Palm OS, can be FEATURE, SAVED_PREFERENCES or UNSAVED_PREFERENCES.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".
In Palm OS, its the application id (E.G.: Settings.applicationId).value
- In Windows, is the value to be retrieved (E.G.: "IntData").
In Palm OS, is an integer representing the number of the preference (from 0 to 32767).data
- The data to be written. In Palm OS, its limited to 64KB.java.lang.Exception
- if there was an error when setting the data.public static boolean delete(int hk, java.lang.String key, java.lang.String value)
public static boolean delete(int hk, java.lang.String key)
public static java.lang.String[] list(int hk, java.lang.String key)
hk
- In Windows, can be HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE or HKEY_USERS.key
- In Windows, its the full path to the key (E.G.: "Software\\TotalCross\\appSettings\\Test".