net.sf.freecol.common.option
Class OptionMap

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption
          extended by net.sf.freecol.common.option.OptionGroup
              extended by net.sf.freecol.common.option.OptionMap
All Implemented Interfaces:
Option
Direct Known Subclasses:
ClientOptions, GameOptions, MapGeneratorOptions

public abstract class OptionMap
extends OptionGroup

Used for grouping objects of Option.


Field Summary
 
Fields inherited from class net.sf.freecol.common.option.AbstractOption
NO_ID
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
OptionMap(org.w3c.dom.Element element, java.lang.String xmlTagName)
          Creates an OptionMap from an XML representation.
OptionMap(java.lang.String xmlTagName)
          Creates a new OptionMap.
OptionMap(javax.xml.stream.XMLStreamReader in, java.lang.String xmlTagName)
          Creates an OptionMap from an XML representation.
 
Method Summary
 void addToMap(OptionGroup og)
          Adds the Options from the given OptionGroup to the Map.
 boolean getBoolean(java.lang.String id)
          Gets the boolean value of an option.
 java.io.File getFile(java.lang.String id)
          Gets the File specified by an option.
 int getInteger(java.lang.String id)
          Gets the integer value of an option.
 Option getObject(java.lang.String id)
          Gets the object identified by the given id.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 void load(java.io.File loadFile)
          Reads the options from the given file.
 void putOption(Option option)
           
 void save(java.io.File saveFile)
          Writes the options to the given file.
 void setFile(java.lang.String id, java.io.File newFileValue)
          Allow a File to be set in other ways, as from the user using the Client.
 void toXML(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.option.OptionGroup
add, getName, getShortDescription, iterator, removeAll
 
Methods inherited from class net.sf.freecol.common.option.AbstractOption
getGroup, isPreviewEnabled, setGroup, setPreviewEnabled, toString
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readFromXML, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
addPropertyChangeListener, getId, readFromXML, readFromXMLElement, removePropertyChangeListener, toXMLElement
 

Constructor Detail

OptionMap

public OptionMap(java.lang.String xmlTagName)
Creates a new OptionMap.

Parameters:
xmlTagName - The tag name that should be used for the parent XML-element returned by Option.toXMLElement(org.w3c.dom.Document).

OptionMap

public OptionMap(javax.xml.stream.XMLStreamReader in,
                 java.lang.String xmlTagName)
          throws javax.xml.stream.XMLStreamException
Creates an OptionMap from an XML representation.

Parameters:
in - The XML stream to read the data from.
xmlTagName - The tag name that should be used for the parent XML-element returned by Option.toXMLElement(org.w3c.dom.Document).
Throws:
javax.xml.stream.XMLStreamException - if an error occured during parsing.

OptionMap

public OptionMap(org.w3c.dom.Element element,
                 java.lang.String xmlTagName)
Creates an OptionMap from an XML representation.

Parameters:
element - The XML Element from which this object should be constructed.
xmlTagName - The tag name that should be used for the parent XML-element returned by Option.toXMLElement(org.w3c.dom.Document).
Method Detail

getObject

public Option getObject(java.lang.String id)
Gets the object identified by the given id.

Parameters:
id - The ID.
Returns:
The Object with the given ID.

getInteger

public int getInteger(java.lang.String id)
Gets the integer value of an option.

Parameters:
id - The id of the option.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If there is no integer value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

getBoolean

public boolean getBoolean(java.lang.String id)
Gets the boolean value of an option.

Parameters:
id - The id of the option.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If there is no boolean value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

getFile

public java.io.File getFile(java.lang.String id)
Gets the File specified by an option.

Parameters:
id - The id of the option.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If there is no File associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

addToMap

public void addToMap(OptionGroup og)
Adds the Options from the given OptionGroup to the Map. This is done recursively if the specified group has any sub-groups.

Parameters:
og - The OptionGroup to be added.

putOption

public void putOption(Option option)

load

public void load(java.io.File loadFile)
Reads the options from the given file.

Parameters:
loadFile - The File to read the options from.

save

public void save(java.io.File saveFile)
Writes the options to the given file.

Parameters:
saveFile - The file where the client options should be written.
See Also:
ClientOptions

toXML

public void toXML(javax.xml.stream.XMLStreamWriter out)
           throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXML in interface Option
Overrides:
toXML in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
See Also:
FreeColObject.toXML(XMLStreamWriter, Player, boolean, boolean)

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Throws:
java.lang.UnsupportedOperationException - at any time, since this class should get it's XML tag name in the constructor

setFile

public void setFile(java.lang.String id,
                    java.io.File newFileValue)
Allow a File to be set in other ways, as from the user using the Client.

Parameters:
id -
newFileValue -