VASSAL.build.module
Class BasicCommandEncoder

java.lang.Object
  |
  +--VASSAL.build.module.BasicCommandEncoder
All Implemented Interfaces:
Buildable, CommandEncoder

public class BasicCommandEncoder
extends java.lang.Object
implements CommandEncoder, Buildable

A CommandEncoder that handles the basic commands: AddPiece, RemovePiece, ChangePiece. If a module defines custom GamePiece classes, then this class may be overriden and imported into the module. Subclasses should override the createDecorator(java.lang.String, VASSAL.counters.GamePiece) method or, less often, the createBasic(java.lang.String) or createPiece(java.lang.String) methods to allow instantiation of the custom GamePiece classes.


Constructor Summary
BasicCommandEncoder()
           
 
Method Summary
 void add(Buildable b)
          Adds a child component.
 void addTo(Buildable parent)
          Adds this component to its parent.
 void build(org.w3c.dom.Element e)
          Build the object
protected  GamePiece createBasic(java.lang.String type)
          Create a GamePiece instance that is not a Decorator @param type the type of the GamePiece.
protected  Decorator createDecorator(java.lang.String type, GamePiece inner)
          Creates a Decorator instance @param type the type of the Decorator to be created.
protected  GamePiece createPiece(java.lang.String type)
          Creates a GamePiece instance from the given type information.
 Command decode(java.lang.String command)
          Translate a String into a Command
 java.lang.String encode(Command c)
          Translate a Command into a String
 org.w3c.dom.Element getBuildElement(org.w3c.dom.Document doc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicCommandEncoder

public BasicCommandEncoder()
Method Detail

createDecorator

protected Decorator createDecorator(java.lang.String type,
                                    GamePiece inner)
Creates a Decorator instance @param type the type of the Decorator to be created. Once created, the Decorator should return this value from its method. @param inner the inner piece of the Decorator @see Decorator


createBasic

protected GamePiece createBasic(java.lang.String type)
Create a GamePiece instance that is not a Decorator @param type the type of the GamePiece. The created piece should return this value from its GamePiece.getType() method


createPiece

protected GamePiece createPiece(java.lang.String type)
Creates a GamePiece instance from the given type information. Determines from the type whether the represented piece is a Decorator or not and forwards to createDecorator(java.lang.String, VASSAL.counters.GamePiece) or createBasic(java.lang.String). This method should generally not need to be overridden. Instead, override createDecorator or createBasic


build

public void build(org.w3c.dom.Element e)
Description copied from interface: Buildable
Build the object

Specified by:
build in interface Buildable
Parameters:
e - the XML element containing the object data

addTo

public void addTo(Buildable parent)
Description copied from interface: Buildable
Adds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class.

Specified by:
addTo in interface Buildable

add

public void add(Buildable b)
Description copied from interface: Buildable
Adds a child component. Both this method and Buildable.addTo(VASSAL.build.Buildable) are invoked when adding a child to a parent

Specified by:
add in interface Buildable

getBuildElement

public org.w3c.dom.Element getBuildElement(org.w3c.dom.Document doc)
Specified by:
getBuildElement in interface Buildable
Returns:
an XML element from which this component can be built

decode

public Command decode(java.lang.String command)
Description copied from interface: CommandEncoder
Translate a String into a Command

Specified by:
decode in interface CommandEncoder

encode

public java.lang.String encode(Command c)
Description copied from interface: CommandEncoder
Translate a Command into a String

Specified by:
encode in interface CommandEncoder