org.moyoman.module
Class Mode

java.lang.Object
  |
  +--org.moyoman.module.Mode
All Implemented Interfaces:
Serializable

public class Mode
extends Object
implements Serializable

This class represents the different modes that the server can use. The ordering of module and helper implementations for a given type is done per mode. There are standard modes, and there can be user-defined modes as well.

See Also:
Serialized Form

Field Summary
static Mode BEST
           
static Mode FAST
           
private  String mode
          The name of the mode, e.g, Best.
private static HashMap standard
          The key is the mode name converted to lower case, and the value is the mode object.
private static HashMap user
          The key is the mode name converted to lower case, and the value is the mode object.
 
Constructor Summary
protected Mode(String type)
          Create a user defined mode.
private Mode(String type, boolean isStandard)
          Create a new Mode object.
 
Method Summary
protected static void addMode(String name)
          Add a new user defined mode.
protected static void cancel()
          Cancel any changes to the user defined modes, and reread the information from file.
protected  void deleteMode()
          Delete the user defined mode.
 boolean equals(Object o)
          Override the Object.equals() method.
static Mode get(String name)
          Get the Mode object of the given name.
static Mode[] getAllModes()
          Return an array of all of the modes.
private static String getFileName()
          Get the name of the file in which the user defined modes are listed.
static Mode[] getUserModes()
          Return an array of all of the user defined modes.
 int hashCode()
          Return a hash code value for the mode.
 boolean isUserMode()
          Determine if the mode is a user mode.
private static void readUserModes()
          Read the file which lists the user defined modes.
protected static void save()
          Write out any user defined mode information to a file.
private  void setVars(String type, boolean isStandard)
          Set the internal variables of this object.
 String toString()
          Return a String representation of the mode.
private static void writeUserModes()
          Write out the user defined mode information to a file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BEST

public static final Mode BEST

FAST

public static final Mode FAST

standard

private static HashMap standard
The key is the mode name converted to lower case, and the value is the mode object. This HashMap contains standard modes.


user

private static HashMap user
The key is the mode name converted to lower case, and the value is the mode object. This HashMap contains user defined modes.


mode

private String mode
The name of the mode, e.g, Best.

Constructor Detail

Mode

private Mode(String type,
             boolean isStandard)
Create a new Mode object. This constructor does not do any error checking, so it is called after the checking has already been done.

Parameters:
type - The name of the mode.
isStandard - If true, then this is a standard mode, otherwise, false.

Mode

protected Mode(String type)
        throws DataAlreadyExistsException
Create a user defined mode.

Parameters:
type - The mode to be used.
Throws:
DataAlreadyExistsException - Thrown if the mode already exists.
Method Detail

setVars

private void setVars(String type,
                     boolean isStandard)
Set the internal variables of this object.

Parameters:
type - The mode name
isStandard - if true, then the mode is a standard mode.

addMode

protected static void addMode(String name)
                       throws DataAlreadyExistsException
Add a new user defined mode.

Parameters:
name - The name of the mode.
Throws:
DataAlreadyExistsException - Thrown if the mode name is already in use.

deleteMode

protected void deleteMode()
                   throws NoSuchDataException,
                          PermissionsException
Delete the user defined mode. Standard modes can not be deleted, and an attempt to do so will result in an exception.

Throws:
PermissionsException - - Thrown if the mode is a standard one.
NoSuchDataException

get

public static Mode get(String name)
                throws NoSuchDataException
Get the Mode object of the given name.

Parameters:
name - The name of the mode.
Returns:
A Mode object.
Throws:
NoSuchDataException - - Thrown if there is no such mode.

getAllModes

public static Mode[] getAllModes()
Return an array of all of the modes.

Returns:
An array of Mode objects.

getUserModes

public static Mode[] getUserModes()
Return an array of all of the user defined modes.

Returns:
An array of Mode objects.

readUserModes

private static void readUserModes()
Read the file which lists the user defined modes.


writeUserModes

private static void writeUserModes()
Write out the user defined mode information to a file.


save

protected static void save()
Write out any user defined mode information to a file.


cancel

protected static void cancel()
Cancel any changes to the user defined modes, and reread the information from file.


getFileName

private static String getFileName()
Get the name of the file in which the user defined modes are listed.

Returns:
A String which is the absolute file name.

isUserMode

public boolean isUserMode()
Determine if the mode is a user mode.

Returns:
true if the mode is a user mode, or false.

toString

public String toString()
Return a String representation of the mode.

Overrides:
toString in class Object
Returns:
A String which represents the mode.

hashCode

public int hashCode()
Return a hash code value for the mode. An int which is the hashcode.

Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Override the Object.equals() method. If two objects represent the same mode, then return true, otherwise, return false.

Overrides:
equals in class Object
Parameters:
o - The object being tested.
Returns:
true if the two modes are the same, or false.