org.objectweb.jonas.newbean
Class Parameter

java.lang.Object
  extended by org.objectweb.jonas.newbean.Parameter

public abstract class Parameter
extends java.lang.Object

This class represents a parameter the user may be prompted for. It is responsible for asking the user for a value, validating his input, exporting relevant datas into Velocity's context, and deciding what should be the next parameter to ask.

A parameter is created by subclassing this class and overriding the following abstract methods:


Field Summary
protected  java.lang.String value
          This parameter's value, as entered by the user.
protected  org.apache.velocity.VelocityContext vContext
          The Velocity context into which this parameter's variables will be exported.
 
Constructor Summary
Parameter(org.apache.velocity.VelocityContext context)
          Creates a new parameter that will export its variables into the specified Velocity context.
 
Method Summary
abstract  void export()
          Exports the variables managed by this parameter into the associated Velocity context (ie vContext).
abstract  java.lang.String getArgKeyword()
           
abstract  Parameter getNextParameter()
          Returns the parameter the user will be asked for after this one.
abstract  java.lang.String getPrompt()
          Returns the string used to prompt the user for a value.
abstract  boolean isValid()
          Indicates whether this parameter as a valid value.
 void obtainValue()
          Obtains the value of this parameter.
 void setValue(java.lang.String input)
          Sets the value of this parameter.
 void walkThrough()
          Recusively walk through the parameters graph, obtaining parameter (obtainValue()) values and exporting (export()) them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vContext

protected org.apache.velocity.VelocityContext vContext
The Velocity context into which this parameter's variables will be exported.


value

protected java.lang.String value
This parameter's value, as entered by the user.

Constructor Detail

Parameter

public Parameter(org.apache.velocity.VelocityContext context)
Creates a new parameter that will export its variables into the specified Velocity context.

Parameters:
context - the Velocity context into which variables will be exported
Method Detail

walkThrough

public void walkThrough()
Recusively walk through the parameters graph, obtaining parameter (obtainValue()) values and exporting (export()) them.

The path taken through the parameter graph may change depending on the values entered by the user. It is determined after each valid input by a call to getNextParameter().


obtainValue

public void obtainValue()
Obtains the value of this parameter. This method prompts the user for a value, stores it into value through the isValid(). This process is repeated until the value is valid.


setValue

public void setValue(java.lang.String input)
Sets the value of this parameter. This method is called each time a value is entered is entered by the user, before its validity has been checked.

This implementation simply sets value to input. You can override this method if you need to format this input, for example to convert it to uppercase.


getPrompt

public abstract java.lang.String getPrompt()
Returns the string used to prompt the user for a value.

Returns:
the string used to prompt the user for a value.

isValid

public abstract boolean isValid()
Indicates whether this parameter as a valid value. This method can safely assume value is not null.

Returns:
true if value is valid, false otherwise

export

public abstract void export()
Exports the variables managed by this parameter into the associated Velocity context (ie vContext).


getNextParameter

public abstract Parameter getNextParameter()
Returns the parameter the user will be asked for after this one. This method is not invoked before a valid value has been entered for this parameter; therefor it is possible to decide which object to return based on the value of value.

This method returns null if their is no more parameters.

Returns:
the next parameter the user should be prompted for

getArgKeyword

public abstract java.lang.String getArgKeyword()
Returns:
the command line keyword string for this parameter