net.sf.freecol.common.model
Class FreeColGameObject

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
Direct Known Subclasses:
Building, ColonyTile, Europe, Game, GoodsContainer, Map, Market, Monarch, Player, PlayerExploredTile, Region, Settlement, Tile, TileItem, TileItemContainer, TradeRoute, Unit

public abstract class FreeColGameObject
extends FreeColObject

The superclass of all game objects in FreeCol.


Field Summary
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
FreeColGameObject(Game game)
          Creates a new FreeColGameObject with an automatically assigned ID and registers this object at the specified Game.
FreeColGameObject(Game game, org.w3c.dom.Element e)
          Initiates a new FreeColGameObject from an Element.
FreeColGameObject(Game game, java.lang.String id)
          Initiates a new FreeColGameObject with the given ID.
FreeColGameObject(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new FreeColGameObject from an Element.
 
Method Summary
 void addToRemoveElement(org.w3c.dom.Element removeElement)
          Convenience function to add this object to an element intended to signal removal of the object.
 void dispose()
          Removes all references to this object.
 boolean equals(FreeColGameObject o)
          Checks if the given FreeColGameObject equals this object.
 boolean equals(java.lang.Object o)
          Checks if the given FreeColGameObject equals this object.
<T extends FreeColGameObject>
T
getFreeColGameObject(javax.xml.stream.XMLStreamReader in, java.lang.String attributeName, java.lang.Class<T> returnClass)
           
<T extends FreeColGameObject>
T
getFreeColGameObject(javax.xml.stream.XMLStreamReader in, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)
           
 Game getGame()
          Gets the game object this FreeColGameObject belongs to.
 GameOptions getGameOptions()
          Gets the GameOptions that is associated with the Game owning this FreeColGameObject.
 java.lang.Integer getIntegerID()
          Gets the ID's integer part of this object.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 int hashCode()
           
 boolean hasID(java.lang.String id)
          Checks if this object has the specified ID.
 boolean isDisposed()
          Checks if this object has been disposed.
 boolean isUninitialized()
          Checks if this FreeColGameObject is uninitialized.
 void readFromXML(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setGame(Game game)
          Sets the game object this FreeColGameObject belongs to.
 void setId(java.lang.String newID)
          Sets the unique ID of this object.
 void toSavedXML(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream for the purpose of storing this object as a part of a saved game.
 java.lang.String toString()
          Returns a string representation of the object.
 void toXML(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
<T extends FreeColGameObject>
T
updateFreeColGameObject(javax.xml.stream.XMLStreamReader in, java.lang.Class<T> returnClass)
           
 void updateID()
          Updates the id.
 
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, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FreeColGameObject

public FreeColGameObject(Game game)
Creates a new FreeColGameObject with an automatically assigned ID and registers this object at the specified Game.

Parameters:
game - The Game in which this object belong.

FreeColGameObject

public FreeColGameObject(Game game,
                         javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Initiates a new FreeColGameObject from an Element.

Parameters:
game - The Game in which this object belong.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

FreeColGameObject

public FreeColGameObject(Game game,
                         org.w3c.dom.Element e)
Initiates a new FreeColGameObject from an Element.

Parameters:
game - The Game in which this object belong.
e - An XML-element that will be used to initialize this object.

FreeColGameObject

public FreeColGameObject(Game game,
                         java.lang.String id)
Initiates a new FreeColGameObject with the given ID. The object should later be initialized by calling either readFromXML(XMLStreamReader) or FreeColObject.readFromXMLElement(Element).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

getGame

public Game getGame()
Gets the game object this FreeColGameObject belongs to.

Returns:
The game.

getGameOptions

public GameOptions getGameOptions()
Gets the GameOptions that is associated with the Game owning this FreeColGameObject.

Returns:
The same GameOptions-object as returned by getGame().getGameOptions().

setGame

public void setGame(Game game)
Sets the game object this FreeColGameObject belongs to.

Parameters:
game - The game.

dispose

public void dispose()
Removes all references to this object.


isDisposed

public boolean isDisposed()
Checks if this object has been disposed.

Returns:
true if this object has been disposed.
See Also:
dispose()

isUninitialized

public boolean isUninitialized()
Checks if this FreeColGameObject is uninitialized. That is: it has been referenced by another object, but has not yet been updated with readFromXML(javax.xml.stream.XMLStreamReader).

Returns:
true if this object is not initialized.

updateID

public void updateID()
Updates the id. This method should be overwritten by server model objects.


toSavedXML

public void toSavedXML(javax.xml.stream.XMLStreamWriter out)
                throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream for the purpose of storing this object as a part of a saved game.

Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
See Also:
toXML(XMLStreamWriter, Player, boolean, boolean)

toXML

public final void toXML(javax.xml.stream.XMLStreamWriter out,
                        Player player,
                        boolean showAll,
                        boolean toSavedGame)
                 throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Overrides:
toXML in class FreeColObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXML

public final void readFromXML(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXML in class FreeColObject
Parameters:
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getIntegerID

public java.lang.Integer getIntegerID()
Gets the ID's integer part of this object. The age of two FreeColGameObjects can be compared by comparing their integer IDs.

Returns:
The unique ID of this object.

setId

public final void setId(java.lang.String newID)
Sets the unique ID of this object. When setting a new ID to this object, it it automatically registered at the corresponding Game with the new ID.

Parameters:
newID - the unique ID of this object,

hasID

public boolean hasID(java.lang.String id)
Checks if this object has the specified ID.

Parameters:
id - The ID to check against.
Returns:
true if the specified ID match the ID of this object and false otherwise.

equals

public boolean equals(FreeColGameObject o)
Checks if the given FreeColGameObject equals this object.

Parameters:
o - The FreeColGameObject to compare against this object.
Returns:
true if the two FreeColGameObject are equal and false otherwise.

equals

public boolean equals(java.lang.Object o)
Checks if the given FreeColGameObject equals this object.

Overrides:
equals in class java.lang.Object
Parameters:
o - The FreeColGameObject to compare against this object.
Returns:
true if the two FreeColGameObject are equal and false otherwise.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
The String

getFreeColGameObject

public <T extends FreeColGameObject> T getFreeColGameObject(javax.xml.stream.XMLStreamReader in,
                                                            java.lang.String attributeName,
                                                            java.lang.Class<T> returnClass)

getFreeColGameObject

public <T extends FreeColGameObject> T getFreeColGameObject(javax.xml.stream.XMLStreamReader in,
                                                            java.lang.String attributeName,
                                                            java.lang.Class<T> returnClass,
                                                            T defaultValue)

updateFreeColGameObject

public <T extends FreeColGameObject> T updateFreeColGameObject(javax.xml.stream.XMLStreamReader in,
                                                               java.lang.Class<T> returnClass)

addToRemoveElement

public void addToRemoveElement(org.w3c.dom.Element removeElement)
Convenience function to add this object to an element intended to signal removal of the object.

Parameters:
removeElement - The remove element.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object. This method should be overwritten by any sub-class, preferably with the name of the class with the first letter in lower case.

Returns:
"unknown".