org.rhq.enterprise.communications.util.prefs
Class SetupInstruction

java.lang.Object
  extended by org.rhq.enterprise.communications.util.prefs.SetupInstruction
Direct Known Subclasses:
DefaultSetupInstruction, LocalInetAddressNoDefaultSetupInstruction, LocalInetAddressSetupInstruction, LocalInetHostnameSetupInstruction

public class SetupInstruction
extends Object

Instances of this class represent a single setup instruction that defines a preference that needs to be setup. It defines things like what the preference name is, what its default value should be, a human-readable help text to explain what the preference is for, and other things.

This class can be used as-is or can be subclassed if additional processing needs to be performed during the setup (such as pre-processing to obtain a default value at runtime or post-processing the new user-entered value).

Author:
John Mazzitelli

Constructor Summary
SetupInstruction(String preference_name, String default_value, SetupValidityChecker validity_checker, String prompt_message, String help_message, boolean no_echo_prompt)
          Constructor for SetupInstruction.
 
Method Summary
 String getDefaultValue()
          Returns the default value that is to be assigned to the preference if the answer to the prompt was an empty return.
 String getHelpMessage()
          Returns the human-readable help message that describes the preference being setup in more detail.
 String getPreferenceName()
          Returns the name of the preference that is setup by this instruction.
 Preferences getPreferences()
          Returns the preferences that are being setup according to this instruction.
 String getPromptMessage()
          Returns the human-readable prompt message that asks the question of the user for the new preference value.
 SetupValidityChecker getValidityChecker()
          Returns the optionally defined validity checker object that will be responsible for making sure any new preference value to be set is valid.
 boolean isUsingNoEchoPrompt()
          If true, the prompt will not echo what the user typed (as you would want if the prompt is asking for a password, for example).
 void postProcess()
          This method is called by Setup to inform this object that the preferences have been setup with the information in this instruction - getPreferences() will return the preferences that have been changed.
 void preProcess()
          This method is called by Setup to inform this object that the preferences are about to be setup with the information in this instruction.
protected  void setDefaultValue(String default_value)
          Sets the default value that is to be assigned to the preference if the answer to the prompt was an empty return.
protected  void setHelpMessage(String help_message)
          Sets the human-readable help message that describes the preference being setup in more detail.
 void setPreferences(Preferences preferences)
          Sets the preferences that are being setup according to this instruction object.
protected  void setPromptMessage(String prompt_message)
          Sets the human-readable prompt message that asks the question of the user for the new preference value.
protected  void setUsingNoEchoPrompt(boolean no_echo)
          If true, the prompt will not echo what the user typed (as you would want if the prompt is asking for a password, for example).
protected  void setValidityChecker(SetupValidityChecker validity_checker)
          Sets the validity checker object that will be responsible for making sure any new preference value to be set is valid.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetupInstruction

public SetupInstruction(String preference_name,
                        String default_value,
                        SetupValidityChecker validity_checker,
                        String prompt_message,
                        String help_message,
                        boolean no_echo_prompt)
                 throws IllegalArgumentException
Constructor for SetupInstruction.

Parameters:
preference_name - the name of the preference that this instruction will setup (must not be null)
default_value - the default value of the preference should the user input be an empty return
validity_checker - an optional object that can be used to validate a new preference value (may be null)
prompt_message - the human-readable prompt string that will be shown to the user that asks for the customized preference value the user wants to use (may be null, in which case, the Setup should not stop and ask the user for a value - the default value will be used automatically)
help_message - the human-readable help string that provides more detail on the preference (for the user to see if they don't know what the preference is for)
no_echo_prompt - if true, the prompt is assumed to be for some secure setting that should no be echoed to the screen to avoid spying eyes from seeing it. When true, the prompt will be asked a second time to confirm the answer, since the user won't be able to see what is being typed
Throws:
IllegalArgumentException - if preference_name is null
Method Detail

preProcess

public void preProcess()
This method is called by Setup to inform this object that the preferences are about to be setup with the information in this instruction. Subclasses are free to override this method to perform some pre-processing in case it wants to do things like define a default value based on information it gathers at runtime, define a different prompt message, etc.

This method implementation is a no-op and simply does nothing but return.


postProcess

public void postProcess()
This method is called by Setup to inform this object that the preferences have been setup with the information in this instruction - getPreferences() will return the preferences that have been changed. Subclasses are free to override this method to perform some post-processing in case it wants to do things like modify the preferences based on the new values in the preferences.

This method implementation is a no-op and simply does nothing but return.


getPreferences

public Preferences getPreferences()
Returns the preferences that are being setup according to this instruction.

Returns:
the preferences (will be null if this instruction hasn't been told what preferences are being setup)

setPreferences

public void setPreferences(Preferences preferences)
Sets the preferences that are being setup according to this instruction object.

Parameters:
preferences - the preferences being setup

getPreferenceName

public String getPreferenceName()
Returns the name of the preference that is setup by this instruction.

Returns:
preference name

getDefaultValue

public String getDefaultValue()
Returns the default value that is to be assigned to the preference if the answer to the prompt was an empty return.

Returns:
preference default value

setDefaultValue

protected void setDefaultValue(String default_value)
Sets the default value that is to be assigned to the preference if the answer to the prompt was an empty return.

Parameters:
default_value - the new value of defaultValue

getValidityChecker

public SetupValidityChecker getValidityChecker()
Returns the optionally defined validity checker object that will be responsible for making sure any new preference value to be set is valid. If null, all values are considered valid.

Returns:
the object that performs validation checks on new values of the preference handled by this instruction (may be null)

setValidityChecker

protected void setValidityChecker(SetupValidityChecker validity_checker)
Sets the validity checker object that will be responsible for making sure any new preference value to be set is valid. If null, all values will be considered valid.

Parameters:
validity_checker - the object that performs validation checks on new values of the preference handled by this instruction (may be null)

getPromptMessage

public String getPromptMessage()
Returns the human-readable prompt message that asks the question of the user for the new preference value. If the returned value is null, the user will not be prompted; instead, the default value will be the value to be used as the new preference value.

Returns:
prompt message string (may be null)

setPromptMessage

protected void setPromptMessage(String prompt_message)
Sets the human-readable prompt message that asks the question of the user for the new preference value. If the prompt_message is null, the user will not be prompted; instead, the default value will be the value to be used as the new preference value.

Parameters:
prompt_message - the new prompt message string (may be null)

getHelpMessage

public String getHelpMessage()
Returns the human-readable help message that describes the preference being setup in more detail.

Returns:
help message string

setHelpMessage

protected void setHelpMessage(String help_message)
Sets the human-readable help message that describes the preference being setup in more detail.

Parameters:
help_message - the new help message string

isUsingNoEchoPrompt

public boolean isUsingNoEchoPrompt()
If true, the prompt will not echo what the user typed (as you would want if the prompt is asking for a password, for example).

Returns:
flag to indicate if the prompt will not echo back to the user what is being typed

setUsingNoEchoPrompt

protected void setUsingNoEchoPrompt(boolean no_echo)
If true, the prompt will not echo what the user typed (as you would want if the prompt is asking for a password, for example).

Parameters:
no_echo - flag to indicate if the prompt will not echo back to the user what is being typed

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.