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:
AbstractMission, Game, GoodsContainer, Map, Market, MarketData, Monarch, Player, PlayerExploredTile, Region, TileItem, TileItemContainer, TradeRoute, Unit, UnitLocation

public abstract class FreeColGameObject
extends FreeColObject

The superclass of all game objects in FreeCol.


Field Summary
private  boolean disposed
           
private  Game game
           
private static java.util.logging.Logger logger
           
private  boolean uninitialized
           
static java.lang.String UNITS_TAG_NAME
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
protected FreeColGameObject()
           
  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 dispose()
          Removes all references to this object.
 java.util.List<FreeColGameObject> disposeList()
          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.
 void fundamentalDispose()
          Low level base dispose.
<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.
 java.lang.Integer getIntegerID()
          Gets the ID's integer part of this object.
private  java.lang.String getRealXMLElementTagName()
           
 Specification getSpecification()
          Describe getSpecification method here.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 int hashCode()
           
 boolean isDisposed()
          Checks if this object has been disposed.
 boolean isUninitialized()
          Checks if this FreeColGameObject is uninitialized.
protected  Location newLocation(java.lang.String locationString)
           
 void readFromXML(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLPartialByClass(javax.xml.stream.XMLStreamReader in, java.lang.Class<?> theClass)
          Common routine for FreeColGameObject descendants to update an object from a partial XML-representation which includes only mandatory and server-supplied fields.
protected  void setDefaultId(Game game)
          Sets the Id from the real type and the next Id in the server.
 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.
 java.lang.String toString()
          Gets 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.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Makes an XML-representation of this object.
protected abstract  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
protected  void toXMLPartialByClass(javax.xml.stream.XMLStreamWriter out, java.lang.Class<?> theClass, java.lang.String[] fields)
          Common routine for FreeColGameObject descendants to write an XML-representation of this object to the given stream, including only the mandatory and specified fields.
<T extends FreeColGameObject>
T
updateFreeColGameObject(javax.xml.stream.XMLStreamReader in, java.lang.Class<T> returnClass)
           
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

UNITS_TAG_NAME

public static final java.lang.String UNITS_TAG_NAME
See Also:
Constant Field Values

game

private Game game

disposed

private boolean disposed

uninitialized

private boolean uninitialized
Constructor Detail

FreeColGameObject

protected FreeColGameObject()

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

setDefaultId

protected void setDefaultId(Game game)
Sets the Id from the real type and the next Id in the server. Split out only to help out a backward compatibility reader.

Parameters:
game - The Game this object is in.

getGame

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

Returns:
The game.

getSpecification

public Specification getSpecification()
Describe getSpecification method here.

Overrides:
getSpecification in class FreeColObject
Returns:
a Specification value

setGame

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

Parameters:
game - The game.

fundamentalDispose

public void fundamentalDispose()
Low level base dispose.


disposeList

public java.util.List<FreeColGameObject> disposeList()
Removes all references to this object.

Returns:
A list of disposed objects.

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.

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.

Overrides:
setId in class FreeColObject
Parameters:
newID - the unique ID of this object,

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

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)

newLocation

protected Location newLocation(java.lang.String locationString)

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.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Makes an XML-representation of this object.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The output stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

toXMLImpl

protected abstract void toXMLImpl(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.

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.

getRealXMLElementTagName

private java.lang.String getRealXMLElementTagName()

toXMLPartialByClass

protected void toXMLPartialByClass(javax.xml.stream.XMLStreamWriter out,
                                   java.lang.Class<?> theClass,
                                   java.lang.String[] fields)
                            throws javax.xml.stream.XMLStreamException
Common routine for FreeColGameObject descendants to write an XML-representation of this object to the given stream, including only the mandatory and specified fields. All attributes are considered visible as this is server-to-owner-client functionality, but it depends ultimately on the presence of a getFieldName() method that returns a type compatible with String.valueOf.

Parameters:
out - The target stream.
theClass - The real class of this object, required by the Introspector.
fields - The fields to write.
Throws:
javax.xml.stream.XMLStreamException - if there are problems writing the stream.

readFromXMLPartialByClass

protected void readFromXMLPartialByClass(javax.xml.stream.XMLStreamReader in,
                                         java.lang.Class<?> theClass)
                                  throws javax.xml.stream.XMLStreamException
Common routine for FreeColGameObject descendants to update an object from a partial XML-representation which includes only mandatory and server-supplied fields. All attributes are considered visible as this is server-to-owner-client functionality. It depends ultimately on the presence of a setFieldName() method that takes a parameter type T where T.valueOf(String) exists.

Parameters:
in - The input stream with the XML.
theClass - The real class of this object, required by the Introspector.
Throws:
javax.xml.stream.XMLStreamException - If there are problems reading the stream.

toString

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

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the object.

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".