org.moyoman.framework
Class ServerConfigTool

java.lang.Object
  |
  +--org.moyoman.framework.ServerConfigTool

public class ServerConfigTool
extends Object

This class provides methods for reading and writing the parameters in the system.properties file. A graphical user interface for editing the system.properties file should use this class as opposed to using the ServerConfig class directly.

Currently, this class is not implemented in a general purpose way, but the values are hard coded for each of the six variables currently supported. At some point, a more general method, such as XML Schema, should be used to specify this information. The api of this class will not change though, only the implementation. Thus, XML Schema or some other technology can be added without the user interface having to be modified.


Field Summary
static short ENUM
          Returned by getParameterType() if the parameter is an enumeration.
static short FLOAT
          Returned by getParameterType() if the parameter is a float.
static short INT
          Returned by getParameterType() if the parameter is an int.
private  ServerConfig sc
          The singleton ServerConfig object.
static short STRING
          Returned by getParameterType() if the parameter is a String.
 
Constructor Summary
ServerConfigTool(ServerConfig config)
          Initialize the tool.
 
Method Summary
 void cancel()
          Cancel all operations performed since the last call to save() or cancel().
 String[] getAllParameters()
          Return an array of all the parameter names.
 String[] getEnumValues(String param)
          Get the enumerated values for the parameter.
 int getMaximumInt(String param)
          Get the maximum legal integer value to which this parameter can be set.
 int getMinimumInt(String param)
          Get the minimum legal integer value to which this parameter can be set.
 short getParameterType(String param)
          Get the type of the parameter.
 String getParameterValue(String param)
          Get the value of a parameter.
private  boolean isValueLegalEnumValue(String param, String value)
          Determine if the value is in the legal range for the parameter.
static void main(String[] args)
          Test the application from the command line.
 void save()
          Save all operations performed since the last call to save() or cancel().
 void setParameter(String name, String val)
          Set the parameter to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT

public static final short INT
Returned by getParameterType() if the parameter is an int.

See Also:
Constant Field Values

FLOAT

public static final short FLOAT
Returned by getParameterType() if the parameter is a float.

See Also:
Constant Field Values

STRING

public static final short STRING
Returned by getParameterType() if the parameter is a String.

See Also:
Constant Field Values

ENUM

public static final short ENUM
Returned by getParameterType() if the parameter is an enumeration.

See Also:
Constant Field Values

sc

private ServerConfig sc
The singleton ServerConfig object.

Constructor Detail

ServerConfigTool

public ServerConfigTool(ServerConfig config)
Initialize the tool.

Parameters:
config - The object that contains the config information.
Method Detail

main

public static void main(String[] args)
Test the application from the command line.

Parameters:
args - Command line arguments to the application.

getAllParameters

public String[] getAllParameters()
Return an array of all the parameter names.

Returns:
An array of String objects.

getParameterValue

public String getParameterValue(String param)
                         throws NoSuchDataException
Get the value of a parameter.

Parameters:
param - The parameter name.
Returns:
A String which is the parameter value.
Throws:
NoSuchDataException - Thrown if the parameter name is invalid.

getParameterType

public short getParameterType(String param)
                       throws NoSuchDataException
Get the type of the parameter.

Parameters:
param - The name of the parameter.
Returns:
A short which is one of INT, FLOAT, STRING, or ENUM.
Throws:
NoSuchDataException - Thrown if the parameter name is invalid.

getMinimumInt

public int getMinimumInt(String param)
                  throws NoSuchDataException,
                         IllegalArgumentException
Get the minimum legal integer value to which this parameter can be set.

Returns:
An int.
Throws:
NoSuchDataException - Thrown if the parameter is unknown.
IllegalArgumentException - Thrown if the parameter is not an integer.

getMaximumInt

public int getMaximumInt(String param)
                  throws NoSuchDataException,
                         IllegalArgumentException
Get the maximum legal integer value to which this parameter can be set.

Returns:
An int.
Throws:
NoSuchDataException - Thrown if the parameter is unknown.
IllegalArgumentException - Thrown if the parameter is not an integer.

isValueLegalEnumValue

private boolean isValueLegalEnumValue(String param,
                                      String value)
                               throws IllegalArgumentException,
                                      NoSuchDataException
Determine if the value is in the legal range for the parameter.

Parameters:
param - The name of the parameter.
value - The value to be checked.
Returns:
true if the value is legal, or false.
Throws:
IllegalArgumentException - Thrown if the parameter is not of type enum.
NoSuchDataException - Thrown if the parameter is unknown.

getEnumValues

public String[] getEnumValues(String param)
                       throws IllegalArgumentException,
                              NoSuchDataException
Get the enumerated values for the parameter.

Returns:
An array of String objects which are the legal values.
Throws:
IllegalArgumentException - Thrown if the parameter is not of type enum.
NoSuchDataException - Thrown if the parameter is unknown.

setParameter

public void setParameter(String name,
                         String val)
                  throws IllegalArgumentException,
                         NoSuchDataException
Set the parameter to the given value.

Parameters:
val - The new value of the parameter.
Throws:
IllegalArgumentException - Thrown if the value is not in the legal range for the parameter.
NoSuchDataException - Thrown if the parameter is unknown.

cancel

public void cancel()
            throws InternalErrorException
Cancel all operations performed since the last call to save() or cancel().

Throws:
InternalErrorException - Thrown if the operation fails for any reason.

save

public void save()
          throws Exception
Save all operations performed since the last call to save() or cancel().

Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Exception