org.openbandy.pref
Class Preferences

java.lang.Object
  extended by org.openbandy.pref.Preferences

public final class Preferences
extends java.lang.Object

The Preferences class provides a simple way to persistently store key (String) value (String, int, boolean) pairs. For this purpose, it uses the RMS in which it creates a record store named 'Preferences'. Note that the whole class is forbidden to use the logger as the log itself uses Preferences!

(c) Copyright P. Bolliger 2007, ALL RIGHTS RESERVED.

Version:
1.0
Author:
Philipp Bolliger (philipp@bolliger.name)

Constructor Summary
Preferences()
           
 
Method Summary
static void add(java.lang.String name, boolean screenModifiable)
          Add a preference to the RMS.
static boolean getBooleanValue(java.lang.String name)
          Reads the boolean preference with the given name from the persistent store.
static int getIntValue(java.lang.String name)
          Reads the int preference with the given name from the persistent store.
static java.lang.String getValue(java.lang.String name)
          Reads the string preference with the given name from the persistent store.
static java.util.Enumeration preferences()
          Returns an enumeration of all preferences currently stored.
static void remove(java.lang.String name)
          Remove the preference with the given name from the persistent store.
static void setBooleanValue(java.lang.String name, boolean value)
          Set the value of the preference that is identified with the given name string to the given value.
static void setIntValue(java.lang.String name, int value)
          Set the value of the preference that is identified with the given name string to the given value.
static void setValue(java.lang.String name, java.lang.String value)
          Set the value of the preference that is identified with the given name string to the given value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Preferences

public Preferences()
Method Detail

add

public static void add(java.lang.String name,
                       boolean screenModifiable)
                throws javax.microedition.rms.RecordStoreNotOpenException,
                       javax.microedition.rms.RecordStoreFullException,
                       javax.microedition.rms.RecordStoreException
Add a preference to the RMS. The preference is identified with the name parameter. If the preference should be modifiable by the user, i.e., appear in the GUI on the preferences form, the parameter screenModifiable must be true. The preference will not have a value after being added.

Parameters:
name - The unique identifier of the preference (make sure it is unique yourself)
screenModifiable - if true, the preference will appear in the PreferencesForm screen (@see PreferencesForm)
Throws:
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.RecordStoreFullException
javax.microedition.rms.RecordStoreException

remove

public static void remove(java.lang.String name)
                   throws UnknownPreferenceException,
                          javax.microedition.rms.RecordStoreException,
                          javax.microedition.rms.InvalidRecordIDException,
                          javax.microedition.rms.RecordStoreNotOpenException
Remove the preference with the given name from the persistent store.

Parameters:
name - The (unique) string used to identify the preference.
Throws:
UnknownPreferenceException - If the preference is not known in the store
javax.microedition.rms.RecordStoreException
javax.microedition.rms.InvalidRecordIDException
javax.microedition.rms.RecordStoreNotOpenException

getValue

public static java.lang.String getValue(java.lang.String name)
                                 throws UnknownPreferenceException
Reads the string preference with the given name from the persistent store.

Parameters:
name - The (unique) name description of the preference
Returns:
The according, stored string value
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not a string value
UnknownPreferenceException - Thrown if no preference value is stored with the given name

getIntValue

public static int getIntValue(java.lang.String name)
                       throws InvalidValueException,
                              UnknownPreferenceException
Reads the int preference with the given name from the persistent store.

Parameters:
name - The (unique) name description of the preference
Returns:
The according, stored int value
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not a int value
UnknownPreferenceException - Thrown if no preference value is stored with the given name

getBooleanValue

public static boolean getBooleanValue(java.lang.String name)
                               throws InvalidValueException,
                                      UnknownPreferenceException
Reads the boolean preference with the given name from the persistent store.

Parameters:
name - The (unique) name description of the preference
Returns:
The according, stored boolean value
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not a boolean value
UnknownPreferenceException - Thrown if no preference value is stored with the given name

setValue

public static void setValue(java.lang.String name,
                            java.lang.String value)
                     throws InvalidValueException,
                            javax.microedition.rms.RecordStoreFullException,
                            javax.microedition.rms.RecordStoreNotOpenException,
                            javax.microedition.rms.RecordStoreException
Set the value of the preference that is identified with the given name string to the given value. If the preference does not already exist, it will be added, however as not screen modifiable.

Parameters:
name - The (unique) name description of the stored preference value
value - The string value to be set
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not a string value
javax.microedition.rms.RecordStoreFullException
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.RecordStoreException

setIntValue

public static void setIntValue(java.lang.String name,
                               int value)
                        throws InvalidValueException,
                               javax.microedition.rms.RecordStoreFullException,
                               javax.microedition.rms.RecordStoreNotOpenException,
                               javax.microedition.rms.RecordStoreException
Set the value of the preference that is identified with the given name string to the given value. If the preference does not already exist, it will be added, however as not screen modifiable.

Parameters:
name - The (unique) name description of the stored preference value
value - The int value to be set
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not an int value
javax.microedition.rms.RecordStoreFullException
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.RecordStoreException

setBooleanValue

public static void setBooleanValue(java.lang.String name,
                                   boolean value)
                            throws InvalidValueException,
                                   javax.microedition.rms.RecordStoreFullException,
                                   javax.microedition.rms.RecordStoreNotOpenException,
                                   javax.microedition.rms.RecordStoreException
Set the value of the preference that is identified with the given name string to the given value. If the preference does not already exist, it will be added, however as not screen modifiable.

Parameters:
name - The (unique) name description of the stored preference value
value - The boolean value to be set
Throws:
InvalidValueException - Thrown if the preference associated with the given name is not a boolean value
javax.microedition.rms.RecordStoreFullException
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.RecordStoreException

preferences

public static java.util.Enumeration preferences()
Returns an enumeration of all preferences currently stored.

Returns:
Enumeration of all preferences currently stored