String attrStr = null;
int attrVal = 0;
boolean attrTrue = false;
Entity entity = null;
Coords coords = null;
ParsedXML actionNode = null;
ParsedXML narcNode = null;
ParsedXML infernoNode = null;
ParsedXML loadedUnitsNode = null;
// Did we get a null node?
if (null == node) {
throw new IllegalArgumentException("The entityData is null.");
}
// Make sure that the node is for a EntityData object.
if (!node.getName().equals("entityData")) {
throw new IllegalStateException("Not passed a entityData node.");
}
// TODO : perform version checking.
// Walk the entityData node's children.
Enumeration<?> children = node.elements();
while (children.hasMoreElements()) {
ParsedXML child = (ParsedXML) children.nextElement();
String childName = child.getName();
// Handle null child names.
if (null == childName) {
// No-op.
}
// Did we find the coords node?
else if (childName.equals("coords")) {
// We can decode the coords immediately.
coords = CoordsEncoder.decode(child, game);
} // End found-"coords"-child
// Did we find the action node?
// TODO : rename me
else if (childName.equals("action")) {
// Save the action node for later decoding.
actionNode = child;
} // End found-"action"-child
// Did we find the narcs node?
else if (childName.equals("narcs")) {
// Save the narc node for later decoding.
narcNode = child;
} // End found-"narc"-child
// Did we find the inferno node?
else if (childName.equals("inferno")) {
// Save the inferno node for later decoding.
infernoNode = child;
} // End found-"inferno"-child
// Did we find the loadedUnits node?
else if (childName.equals("loadedUnits")) {
// Save the loadedUnits node for later decoding.
loadedUnitsNode = child;
} // End found-"loadedUnits"-child
// Did we find the class node?
else if (childName.equals("class")) {
// Create the appropriate sub-class of Entity.
attrStr = child.getAttribute("name");
if (null == attrStr) {
throw new IllegalStateException(
"Couldn't decode the name of a class node.");
} else if (attrStr.equals("BipedMech")) {
entity = BipedMechEncoder.decode(child, game);