Class XMLbase
- Direct Known Subclasses:
engine,engineSpec,faction,hull,hullSpec,industry,industrySpec,orbiting,planet,planetSpec,reference,shield,shieldSpec,ship,shipSpec,shipyard,shipyardSpec,species,speciesSpec,star,starmap,starSpec,weapon,weaponSpec
So for instance the XML <planet> element is processed by the planet
class to create a planet data object with properties set from the XML. These
properties are fixed and thus have no public setter methods since there is no
in-game reason to change them or create them.
Once loaded, the data object can be converted into a usable entity with components
via by creating the appropriate entity factory eg a planetEF and using the
baseEF.fromXML(name.moore.kevin.ze.XMLdata.XMLbase)
with the XML data object as a the parameter.
Once transferred into the entity-component database, the data object can be discarded.
- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringdefaultXMLmessage(String ele)protected StringduplicatedXMLmessage(String ele)abstract ClassDerived classes have to override this and say what class eg engine.class they are.getKey()getSpec()Derived classes override if they really do want to return a spec reference.protected StringmissingXMLmessage(String ele)protected ObjectCalled automatically when loading from XML as part of JDK serialisation.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
key
All XML objects have this mandatory unique key for this object eg "Earth" as the name of the planet.Stored in XML as an attribute < ... key="something">. Required.
Becomes a
Namecomponent in an entity and is used to lookup the entity when required. -
description
All XML objects have this mandatory description of what the entity is eg "Neutron beam weapon".Optional, defaulted to "". Appears as <description/> in XML.
-
-
Constructor Details
-
XMLbase
public XMLbase()
-
-
Method Details
-
getKey
- Returns:
-
getDescription
- Returns:
-
getEntityClass
Derived classes have to override this and say what class eg engine.class they are. This allows us to use this base class but discover the derived class.- Returns:
-
getSpec
Derived classes override if they really do want to return a spec reference.- Returns:
-
readResolve
Called automatically when loading from XML as part of JDK serialisation.Used to do some validation of that incoming XML by asserting that properties are set and have defaults as required. Output warning messages if a default is applied. Output error messages if a required XML element is missing and return null to indicate an invalid object.
- Returns:
- null if we can't create a valid object
-
defaultXMLmessage
- Parameters:
ele-- Returns:
-
missingXMLmessage
- Parameters:
ele-- Returns:
-
duplicatedXMLmessage
- Parameters:
ele-- Returns:
-