* @throws <code>IllegalArgumentException</code> if the node is
* <code>null</code>.
* @throws <code>IOException</code> if there's any error on write.
*/
public static void encode(IHex hex, Writer out) throws IOException {
ITerrain terrain = null;
int loop = 0;
// First, validate our input.
if (null == hex) {
throw new IllegalArgumentException("The hex is null.");
}
if (null == out) {
throw new IllegalArgumentException("The writer is null.");
}
// Start the XML stream for this hex
out.write("<hex version=\"1.0\" >");
// OK, so elevation and theme aren't *strictly speaking* part of
// terrain, but it's convenient to store this info here. Cope.
out.write("<terrains count=\"");
out.write(Integer.toString(hex.terrainsPresent()));
out.write("\" elevation=\"");
out.write(Integer.toString(hex.getElevation()));
if (null != hex.getTheme()) {
out.write("\" theme=\"");
out.write(hex.getTheme());
}
out.write("\" >");
for (loop = 0; loop < Terrains.SIZE; loop++) {
// If the hex has this kind of terrain, encode it.
if (hex.containsTerrain(loop)) {
terrain = hex.getTerrain(loop);
out.write("<terrain type=\"");
out.write(Integer.toString(terrain.getType()));
out.write("\" level=\"");
out.write(Integer.toString(terrain.getLevel()));
out.write("\" exits=\"");
out.write(Integer.toString(terrain.getExits()));
out.write("\" exitsSpecified=\"");
out.write(terrain.hasExitsSpecified() ? "true" : "false");
out.write("\" />");
}
}
out.write("</terrains>");
out.write("</hex>");