org.jbind.util.other
Class Prefs

java.lang.Object
  extended byorg.jbind.util.other.Prefs
Direct Known Subclasses:
PrefsConfig

public abstract class Prefs
extends java.lang.Object

Base class for managing preferences. Derived classes can use the doMain(java.lang.String[]) method to easily create a main method to manage the preferences.


Constructor Summary
protected Prefs(boolean aSystemNotUser)
          Creates a prefs object that manages the preferences of class this instance belongs to.
 
Method Summary
protected  int doAcceptArgument(java.lang.String[] anArgs, int anIndex)
          Hook method to accept an argument.
protected  void doMain(java.lang.String[] anArgs)
          Manages the preferences by applying the arguments supplied in an argument array.
protected  void doResetPrefs()
          Hook method that is called if the "reset" option is handled.
protected  java.util.prefs.Preferences getPrefs()
          Gets the preferences of the class of this instance.
protected  java.util.prefs.Preferences getPrefs(java.lang.String aPath)
          Gets preferences addressed by an either relative or absolute path.
protected  void resetPrefs()
           
protected  void usage()
          Prints usage information for the doMain(java.lang.String[]) method on Console.err.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Prefs

protected Prefs(boolean aSystemNotUser)
Creates a prefs object that manages the preferences of class this instance belongs to.

Parameters:
aSystemNotUser - Determines if user or system preferences are to be managed.
Method Detail

getPrefs

protected java.util.prefs.Preferences getPrefs()
Gets the preferences of the class of this instance.

Returns:
(required).

resetPrefs

protected void resetPrefs()

getPrefs

protected java.util.prefs.Preferences getPrefs(java.lang.String aPath)
Gets preferences addressed by an either relative or absolute path.

Parameters:
aPath - (required).
Returns:
(required).

usage

protected void usage()
Prints usage information for the doMain(java.lang.String[]) method on Console.err.


doMain

protected void doMain(java.lang.String[] anArgs)
Manages the preferences by applying the arguments supplied in an argument array. The argument array may contain the following options: The arguments are processed in the same sequence as they appear in the argument array.

Parameters:
anArgs - (required).

doResetPrefs

protected void doResetPrefs()
Hook method that is called if the "reset" option is handled. Before the hook method is called the current preferences are removed and new preferences will be created on demand.

Subclasses should implement this method by setting default values for the various preferences. This enables one to first reset the preferences and then to export them. The exported preferences should contain enough structural information to allow manual editing, i.e. ideally all possible preference keys with default values are present.

The default implementation does nothing.


doAcceptArgument

protected int doAcceptArgument(java.lang.String[] anArgs,
                               int anIndex)
Hook method to accept an argument. This hook method is called if an argument is not known to the base class.

The default implementation returns -1, indicating that it can not handle the argument.

Parameters:
anArgs - (required). The argument array that was supplied to the doMain(java.lang.String[]) method.
anIndex - The index of the argument in the argument array that has to be accept.
Returns:
The new index. A negative value indicates that the hook method could not handle the argument. If the hook method can handle the argument then it returns the index of the last argument in the argument array that was processed by the call. For example if the hook method accepts an argument with no additional parameters then the supplied index paramter "anIndex" is returned. If the hook method handled the argument with an additional parameter then the returned index is one more than the supplied index.