* <code>null</code>.
* @throws <code>IllegalStateException</code> if the node does not contain
* a valid <code>Entity</code>.
*/
public static Entity decode(ParsedXML node, IGame game) {
QuadMech entity = null;
String attrStr;
int attrVal;
// Did we get a null node?
if (null == node) {
throw new IllegalArgumentException("The QuadMech node is null.");
}
// Make sure that the node is for an Mech unit.
attrStr = node.getAttribute("name");
if (!node.getName().equals("class") || null == attrStr
|| !attrStr.equals("QuadMech")) {
throw new IllegalStateException("Not passed a QuadMech node.");
}
// TODO : perform version checking.
// Create the entity.
entity = new QuadMech();
// Walk the board 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 stunnedTurns node?
else if (childName.equals("mascTurns")) {
// Get the Mech's stunned turns.
attrStr = child.getAttribute("value");
if (null == attrStr) {
throw new IllegalStateException(
"Couldn't decode the mascTurns for a QuadMech unit.");
}
// Try to pull the number from the attribute string
try {
attrVal = Integer.parseInt(attrStr);
} catch (NumberFormatException exp) {
throw new IllegalStateException(
"Couldn't get an integer from " + attrStr);
}
entity.setMASCTurns(attrVal);
}
// Did we find the mascUsed node?
else if (childName.equals("mascUsed")) {
// See if the Mech used MASC.
attrStr = child.getAttribute("value");
if (null == attrStr) {
throw new IllegalStateException(
"Couldn't decode mascUsed for a QuadMech unit.");
}
// If the value is "true", the Mech used MASC.
if (attrStr.equals("true")) {
entity.setMASCUsed(true);
}
}
} // Handle the next element.