org.moyoman.helper
Class HelperConfig

java.lang.Object
  |
  +--org.moyoman.helper.HelperConfig

public class HelperConfig
extends Object

Read and write configuration information related to helpers. This class is responsible for the following types of information:

  1. The helper names and their order for a helper type and mode.
  2. The component type that each helper type is associated with.
  3. The location and structure of the permanent storage of this information.


Field Summary
private  HashMap allHelpers
          The key is a String (simple name) and the value is a HelperName object.
private  ArrayList allHelperTypes
          Each element is a HelperType object.
private  HashMap hashmaps
          The key is the mode name.
private static HelperConfig hc
          The HelperConfig object.
private  HashMap hhMapping
          The key is the HelperType child, and the value the HelperType parent.
private  HashMap hmMapping
          The key is the HelperType child, and the value the ModuleType parent.
private static ServerConfig sc
          The ServerConfig object.
private static String topDir
          The top directory of the Moyoman software.
 
Constructor Summary
protected HelperConfig()
          Create a HelperConfig object.
 
Method Summary
protected  void addHelperName(HelperName hn)
          Add the helper name at the end of the list for the given helper type.
protected  void addHelperType(HelperType ht, ComponentType parent)
          Add helper type to the list.
protected  void addMode(Mode newMode, Mode oldMode)
          Create a new user defined mode.
protected  void associate(HelperType ht, ComponentType parent)
          Associate a helper type with a component type as its parent.
protected  void cancel()
          Undo all operations performed since the last save() or cancel() call.
protected  void deleteHelperName(HelperName hn)
          Delete the helper name from the list for the given helper type.
 void deleteHelperType(HelperType ht)
          Delete the HelperType object from the list.
protected  void deleteMode(String name)
          Delete the mode.
 HelperName[] getAllHelperNames()
          Get all the HelperName objects.
 HelperType[] getAllHelperTypes()
          Get all the HelperType objects.
protected  HelperType[] getAllHelperTypes(HelperType ht)
          Return all of the helper types which have the specified helper type as a parent.
protected  HelperType[] getAllHelperTypes(ModuleType mt)
          Return all of the helper types which have the specified module type as a parent.
 HelperName getFirstHelperName(Mode mode, HelperType type)
          Get the most preferred HelperName object for this mode and helper type.
static HelperConfig getHelperConfig()
          Get the singleton HelperConfig object.
 HelperName[] getHelperNames(Mode mode, HelperType type)
          Get the helper names for the mode and helper type.
private  HelperName[] getHelperNamesForTypeAndMode(Element elem, HelperType ht, Properties props)
          Get the HelperType objects in order for the HelperType and mode.
 ComponentType getParent(HelperType ht)
          Get the parent type of this type.
private  void indentLine(BufferedWriter bw, int level)
          Convenience method to write out the appropriate number of spaces.
private  void processNodes(NodeList nl, HelperType ht, Properties props)
          This method processes the helper.xml entry for a single helper type.
protected  void save()
          Save the information on all operations performed since the last save() or cancel() call.
 void setHelperNameOrder(Mode mode, HelperType type, HelperName[] names)
          Set the helper name order for a given helper type and mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hashmaps

private HashMap hashmaps
The key is the mode name. The value is a HashMap object, in which the key is the HelperType object, and the value is an array of HelperName objects ordered from most to least preferred.


hhMapping

private HashMap hhMapping
The key is the HelperType child, and the value the HelperType parent.


hmMapping

private HashMap hmMapping
The key is the HelperType child, and the value the ModuleType parent.


allHelpers

private HashMap allHelpers
The key is a String (simple name) and the value is a HelperName object.


allHelperTypes

private ArrayList allHelperTypes
Each element is a HelperType object.


topDir

private static String topDir
The top directory of the Moyoman software.


sc

private static ServerConfig sc
The ServerConfig object.


hc

private static HelperConfig hc
The HelperConfig object.

Constructor Detail

HelperConfig

protected HelperConfig()
                throws InternalErrorException
Create a HelperConfig object.

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

processNodes

private void processNodes(NodeList nl,
                          HelperType ht,
                          Properties props)
                   throws InconsistentStateException
This method processes the helper.xml entry for a single helper type.

Parameters:
nl - A NodeList object obtained by the XML parser.
ht - The HelperType being parsed.
props - - A properties object containing the helper name information.
Throws:
InconsistentStateException - Thrown if some of the data for this helper type is inconsistent in some way.

getHelperConfig

public static HelperConfig getHelperConfig()
Get the singleton HelperConfig object.

Returns:
The HelperConfig object.

getAllHelperTypes

public HelperType[] getAllHelperTypes()
Get all the HelperType objects.

Returns:
An array of HelperType objects.

getAllHelperNames

public HelperName[] getAllHelperNames()
Get all the HelperName objects.

Returns:
An array of HelperName objects.

getHelperNamesForTypeAndMode

private HelperName[] getHelperNamesForTypeAndMode(Element elem,
                                                  HelperType ht,
                                                  Properties props)
                                           throws InconsistentStateException
Get the HelperType objects in order for the HelperType and mode. The first entry is the most preferred, and the last entry is the least preferred.

Parameters:
elem - - The Element corresponding to the Mode entry.
ht - The HelperType being processed.
props - The properties object with the helper name information.
Throws:
InconsistentStateException - Thrown if the ranking information does not consist of one value for each integer between 1 and the number of HelperName objects.

getFirstHelperName

public HelperName getFirstHelperName(Mode mode,
                                     HelperType type)
                              throws NoSuchDataException
Get the most preferred HelperName object for this mode and helper type.

Parameters:
mode - The mode in question.
type - The helper type.
Returns:
A HelperName object.
Throws:
NoSuchDataException - Thrown if there is no HelperName object for this helper type and mode.

getHelperNames

public HelperName[] getHelperNames(Mode mode,
                                   HelperType type)
Get the helper names for the mode and helper type.

Parameters:
mode - The mode of the game, such as BEST.
type - The helper type.

addHelperType

protected void addHelperType(HelperType ht,
                             ComponentType parent)
                      throws InconsistentStateException,
                             DataAlreadyExistsException
Add helper type to the list.

Parameters:
ht - The HelperType object to be added.
parent - The ComponentType that this HelperType is to be associated with.
Throws:
InconsistentStateException - Thrown if the parent is of an unknown type.
DataAlreadyExistsException - Thrown if this HelperType object has already been added.

deleteHelperType

public void deleteHelperType(HelperType ht)
                      throws PermissionsException,
                             NoSuchDataException
Delete the HelperType object from the list. If it has any associated HelperName objects, throw an exception.

Parameters:
ht - The HelperType object to delete.
Throws:
PermissionsException - Thrown if there are any HelperName objects associated with this HelperType object.
NoSuchDataException - Thrown if the HelperType is not associated.

addHelperName

protected void addHelperName(HelperName hn)
Add the helper name at the end of the list for the given helper type.

Parameters:
hn - The HelperName object.

deleteHelperName

protected void deleteHelperName(HelperName hn)
Delete the helper name from the list for the given helper type.

Parameters:
hn - The helper name to be deleted.

addMode

protected void addMode(Mode newMode,
                       Mode oldMode)
                throws NoSuchDataException
Create a new user defined mode.

Parameters:
newMode - The new mode.
oldMode - The mode to copy data from.
Throws:
NoSuchDataException - Thrown if either mode has been deleted.

deleteMode

protected void deleteMode(String name)
                   throws NoSuchDataException
Delete the mode.

Parameters:
name - The name of the mode.
Throws:
NoSuchDataException - Thrown if the mode does not exist.

cancel

protected void cancel()
               throws InternalErrorException
Undo all operations performed since the last save() or cancel() call.

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

save

protected void save()
             throws InternalErrorException
Save the information on all operations performed since the last save() or cancel() call.

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

indentLine

private void indentLine(BufferedWriter bw,
                        int level)
                 throws InternalErrorException
Convenience method to write out the appropriate number of spaces. This has no effect on parsing, and just makes the file easier to read.

Parameters:
bw - The BufferedWriter to write the spaces out to.
level - The number of levels to indent.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

setHelperNameOrder

public void setHelperNameOrder(Mode mode,
                               HelperType type,
                               HelperName[] names)
Set the helper name order for a given helper type and mode. Note that calling this method has no effect on permanent storage until save() is called.

Parameters:
mode - The mode of the game, such as FAST.
type - The helper type.
names - The helper names in order from most preferred to least preferred.

getParent

public ComponentType getParent(HelperType ht)
                        throws InconsistentStateException
Get the parent type of this type.

Parameters:
ht - The helper type being queried.
Returns:
A ComponentType object.
Throws:
InconsistentStateException - Thrown if the parent cannot be determined.

associate

protected void associate(HelperType ht,
                         ComponentType parent)
                  throws InconsistentStateException,
                         DataAlreadyExistsException
Associate a helper type with a component type as its parent.

Parameters:
ht - The helper type to be associated with its parent
parent - The parent of the helper type.
Throws:
InconsistentStateException - Thrown if the parent is of an unknown type.
DataAlreadyExistsException - Thrown if the helper type is already associated with a parent.

getAllHelperTypes

protected HelperType[] getAllHelperTypes(HelperType ht)
Return all of the helper types which have the specified helper type as a parent.

Parameters:
ht - The parent helper type.
Returns:
An array of HelperType objects.

getAllHelperTypes

protected HelperType[] getAllHelperTypes(ModuleType mt)
Return all of the helper types which have the specified module type as a parent.

Parameters:
mt - The parent module type.
Returns:
An array of HelperType objects.