megamek.common.xml
Class GameEncoder

java.lang.Object
  extended by megamek.common.xml.GameEncoder

public class GameEncoder
extends java.lang.Object

Objects of this class can encode a IGame object as XML into an output writer and decode one from a parsed XML node. It is used for saving games into a version- neutral format and may someday become the mechanism for handling advance scenario options. Please note that order of the XML elements matters because I'm trying to be efficient, not flexible.

Author:
James Damour

Constructor Summary
GameEncoder()
           
 
Method Summary
static IGame decode(gd.xml.tiny.ParsedXML node)
          Decode a IGame object from the passed node.
static void encode(IGame game, java.io.Writer out)
          Encode a IGame object to an output writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameEncoder

public GameEncoder()
Method Detail

encode

public static void encode(IGame game,
                          java.io.Writer out)
                   throws java.io.IOException
Encode a IGame object to an output writer.

Parameters:
game - - the IGame to be encoded. This value must not be null.
out - - the Writer that will receive the XML. This value must not be null.
Throws:
IllegalArgumentException - if the node is null.
IOException - if there's any error on write.
java.io.IOException

decode

public static IGame decode(gd.xml.tiny.ParsedXML node)
Decode a IGame object from the passed node.

Parameters:
node - - the ParsedXML node for this object. This value must not be null.
Returns:
the IGame object based on the node.
Throws:
IllegalArgumentException - if the node is null.
IllegalStateException - if the node does not contain a valid IGame.