Class XMLbase

java.lang.Object
name.moore.kevin.ze.XMLdata.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

public abstract class XMLbase extends Object
XML data is parsed by XStream into the appropriate data object.

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 Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • key

      @XStreamAsAttribute protected String 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 Name component in an entity and is used to lookup the entity when required.

    • description

      private String 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

      public String getKey()
      Returns:
    • getDescription

      public String getDescription()
      Returns:
    • getEntityClass

      public abstract Class 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

      public reference getSpec()
      Derived classes override if they really do want to return a spec reference.
      Returns:
    • readResolve

      protected Object 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

      protected final String defaultXMLmessage(String ele)
      Parameters:
      ele -
      Returns:
    • missingXMLmessage

      protected final String missingXMLmessage(String ele)
      Parameters:
      ele -
      Returns:
    • duplicatedXMLmessage

      protected final String duplicatedXMLmessage(String ele)
      Parameters:
      ele -
      Returns: