|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opends.server.util.cli.ConsoleApplication
public abstract class ConsoleApplication
This class provides an abstract base class which can be used as the basis of a console-based application.
Field Summary | |
---|---|
protected static int |
CONFIRMATION_MAX_TRIES
The maximum number of times we try to confirm. |
Constructor Summary | |
---|---|
protected |
ConsoleApplication(java.io.BufferedReader in,
java.io.PrintStream out,
java.io.PrintStream err)
Creates a new console application instance. |
protected |
ConsoleApplication(java.io.InputStream in,
java.io.OutputStream out,
java.io.OutputStream err)
Creates a new console application instance. |
Method Summary | ||
---|---|---|
protected boolean |
askConfirmation(Message prompt,
boolean defaultValue,
java.util.logging.Logger logger)
Commodity method that interactively confirms whether a user wishes to perform an action. |
|
boolean |
confirmAction(Message prompt,
boolean defaultValue)
Interactively confirms whether a user wishes to perform an action. |
|
protected javax.naming.ldap.InitialLdapContext |
createAdministrativeContext(java.lang.String host,
int port,
boolean useSSL,
boolean useStartTLS,
java.lang.String bindDn,
java.lang.String pwd,
ApplicationTrustManager trustManager)
Returns an InitialLdapContext using the provided parameters. |
|
protected javax.naming.ldap.InitialLdapContext |
createInitialLdapContextInteracting(LDAPConnectionConsoleInteraction ci)
Creates an Initial LDAP Context interacting with the user if the application is interactive. |
|
java.io.PrintStream |
getErrorStream()
Gets the application error stream. |
|
java.io.BufferedReader |
getInputStream()
Gets the application input stream. |
|
java.io.PrintStream |
getOutputStream()
Gets the application output stream. |
|
abstract boolean |
isAdvancedMode()
Indicates whether or not the user has requested advanced mode. |
|
abstract boolean |
isInteractive()
Indicates whether or not the user has requested interactive behavior. |
|
abstract boolean |
isMenuDrivenMode()
Indicates whether or not this console application is running in its menu-driven mode. |
|
abstract boolean |
isQuiet()
Indicates whether or not the user has requested quiet output. |
|
abstract boolean |
isScriptFriendly()
Indicates whether or not the user has requested script-friendly output. |
|
abstract boolean |
isVerbose()
Indicates whether or not the user has requested verbose output. |
|
void |
pressReturnToContinue()
Interactively prompts the user to press return to continue. |
|
void |
print(Message msg)
Displays a message to the error stream. |
|
void |
println()
Displays a blank line to the error stream. |
|
void |
println(Message msg)
Displays a message to the error stream. |
|
void |
println(Message msg,
int indent)
Displays a message to the error stream indented by the specified number of columns. |
|
void |
printlnProgress()
Displays a blank line to the output stream if we are not in quiet mode. |
|
void |
printProgress(Message msg)
Displays a message to the output stream if we are not in quiet mode. |
|
void |
printVerboseMessage(Message msg)
Displays a message to the error stream if verbose mode is enabled. |
|
java.lang.String |
readInput(Message prompt,
java.lang.String defaultValue)
Commodity method that interactively prompts (on error output) the user to provide a string value. |
|
java.lang.String |
readInput(Message prompt,
java.lang.String defaultValue,
java.util.logging.Logger logger)
Commodity method that interactively prompts (on error output) the user to provide a string value. |
|
java.lang.String |
readLineOfInput(Message prompt)
Interactively retrieves a line of input from the console. |
|
java.lang.String |
readPassword(Message prompt)
Interactively retrieves a password from the console. |
|
protected java.lang.String |
readPassword(Message prompt,
java.util.logging.Logger logger)
Commodity method that interactively retrieves a password from the console. |
|
int |
readPort(Message prompt,
int defaultValue)
Interactively retrieves a port value from the console. |
|
|
readValidatedInput(Message prompt,
ValidationCallback<T> validator)
Interactively prompts for user input and continues until valid input is provided. |
|
|
readValidatedInput(Message prompt,
ValidationCallback<T> validator,
int maxTries)
Interactively prompts for user input and continues until valid input is provided. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int CONFIRMATION_MAX_TRIES
Constructor Detail |
---|
protected ConsoleApplication(java.io.BufferedReader in, java.io.PrintStream out, java.io.PrintStream err)
in
- The application input stream.out
- The application output stream.err
- The application error stream.protected ConsoleApplication(java.io.InputStream in, java.io.OutputStream out, java.io.OutputStream err)
in
- The application input stream.out
- The application output stream.err
- The application error stream.Method Detail |
---|
public final boolean confirmAction(Message prompt, boolean defaultValue) throws CLIException
prompt
- The prompt describing the action.defaultValue
- The default value for the confirmation message. This
will be returned if the application is non-interactive
or if the user just presses return.
true
if the user wishes the action
to be performed, or false
if they refused,
or if an exception occurred.
CLIException
- If the user's response could not be read from the
console for some reason.public final java.io.PrintStream getErrorStream()
public final java.io.BufferedReader getInputStream()
public final java.io.PrintStream getOutputStream()
public abstract boolean isAdvancedMode()
true
if the user has requested
advanced mode.public abstract boolean isInteractive()
true
if the user has requested
interactive behavior.public abstract boolean isMenuDrivenMode()
true
if this console application
is running in its menu-driven mode.public abstract boolean isQuiet()
true
if the user has requested
quiet output.public abstract boolean isScriptFriendly()
true
if the user has requested
script-friendly output.public abstract boolean isVerbose()
true
if the user has requested
verbose output.public final void pressReturnToContinue()
public final void println()
public final void println(Message msg)
msg
- The message.public final void print(Message msg)
msg
- The message.public final void printlnProgress()
public final void printProgress(Message msg)
msg
- The message.public final void println(Message msg, int indent)
msg
- The message.indent
- The number of columns to indent.public final void printVerboseMessage(Message msg)
msg
- The verbose message.public final java.lang.String readLineOfInput(Message prompt) throws CLIException
prompt
- The prompt.
null
if the
end of input has been reached.
CLIException
- If the line of input could not be retrieved for some
reason.public java.lang.String readInput(Message prompt, java.lang.String defaultValue) throws CLIException
prompt
- The prompt to present to the user.defaultValue
- The default value to assume if the user presses ENTER
without typing anything, or null
if
there should not be a default and the user must
explicitly provide a value.
CLIException
- If the line of input could not be retrieved for some
reason.public java.lang.String readInput(Message prompt, java.lang.String defaultValue, java.util.logging.Logger logger)
prompt
- The prompt to present to the user.defaultValue
- The default value to assume if the user presses ENTER
without typing anything, or null
if
there should not be a default and the user must
explicitly provide a value.logger
- the Logger to be used to log the error message.
public final java.lang.String readPassword(Message prompt) throws CLIException
prompt
- The password prompt.
CLIException
- If the password could not be retrieved for some reason.protected final java.lang.String readPassword(Message prompt, java.util.logging.Logger logger)
null
is returned.
prompt
- The password prompt.logger
- the Logger to be used to log the error message.
public final int readPort(Message prompt, int defaultValue) throws CLIException
prompt
- The port prompt.defaultValue
- The port default value.
CLIException
- If the port could not be retrieved for some reason.public final <T> T readValidatedInput(Message prompt, ValidationCallback<T> validator) throws CLIException
T
- The type of decoded user input.prompt
- The interactive prompt which should be displayed on each
input attempt.validator
- An input validator responsible for validating and
decoding the user's response.
CLIException
- If an unexpected error occurred which prevented
validation.public final <T> T readValidatedInput(Message prompt, ValidationCallback<T> validator, int maxTries) throws CLIException
T
- The type of decoded user input.prompt
- The interactive prompt which should be displayed on each
input attempt.validator
- An input validator responsible for validating and
decoding the user's response.maxTries
- The maximum number of tries that we can make.
CLIException
- If an unexpected error occurred which prevented
validation or if the maximum number of tries was reached.protected final boolean askConfirmation(Message prompt, boolean defaultValue, java.util.logging.Logger logger) throws CLIException
prompt
- The prompt describing the action.defaultValue
- The default value for the confirmation message. This
will be returned if the application is non-interactive
or if the user just presses return.logger
- the Logger to be used to log the error message.
true
if the user wishes the action
to be performed, or false
if they refused.
CLIException
- if the user did not provide valid answer after
a certain number of tries
(ConsoleApplication.CONFIRMATION_MAX_TRIES)protected javax.naming.ldap.InitialLdapContext createAdministrativeContext(java.lang.String host, int port, boolean useSSL, boolean useStartTLS, java.lang.String bindDn, java.lang.String pwd, ApplicationTrustManager trustManager) throws javax.naming.NamingException
host
- the host name.port
- the port to connect.useSSL
- whether to use SSL or not.useStartTLS
- whether to use StartTLS or not.bindDn
- the bind dn to be used.pwd
- the password.trustManager
- the trust manager.
javax.naming.NamingException
- if there was an error establishing the connection.protected javax.naming.ldap.InitialLdapContext createInitialLdapContextInteracting(LDAPConnectionConsoleInteraction ci) throws ClientException
ci
- the LDAPConnectionConsoleInteraction object that is assumed
to have been already run.
null
if the user did
not accept to trust the certificates.
ClientException
- if there was an error establishing the connection.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |