Class RMASNode

java.lang.Object
com.reportmill.flash.RMASNode

public final class RMASNode extends Object
RMASNode is the class used by the parser to construct a tree representation of an ActionScript file based on the parser grammar.

Encoding a tree of nodes to the binary Flash file format is performed in four stages:

1. First the nodes in the tree are re-ordered. This is used to move function definitions to the start of the block they are defined in - matching the behaviour performed by the Flash authoring application and making regression testing of the code generated against the code generated by Flash much easier.

2. then the node tree is searched for string literals, identifier and function names to construct a table of strings that is added to the start of the script, References to strings can then be made by specifying an index into the table rathe than pushing the string onto the Flash Player's stack - greatly reducing the size of the code.

3. The node tree is translated into an array of action objects. This intermediate step is required to calculate the relative branches and jumps performed when implementing if..else statements and construct such as for and while loops.

4. The array of actions generated by the translation step is then encoded to the binary data format support by Flash.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static HashMap
     
    static HashMap
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RMASNode(int nodeType)
    Constructs an RMASNode with the specified type.
    RMASNode(int nodeType, int value)
    Constructs an RMASNode with the specified type and integer value.
    RMASNode(int nodeType, RMASNode node)
    Constructs an RMASNode with the specified type and adds the child node.
    RMASNode(int nodeType, RMASNode node1, RMASNode node2)
    Constructs an RMASNode with the specified type and adds the child nodes.
    RMASNode(int nodeType, String value)
    Constructs an RMASNode with the specified type and string value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(RMASNode aNode)
    Adds a node to the array of children.
    int
    Return the number of child nodes contained by this node.
    void
    displayTree is used to display the structure of the node tree, with the root starting at the current node.
    byte[]
    encode(int version)
    The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player.
    get(int index)
    Returns the node at the specified index from the array of child nodes.
    int
    Get the integer value assigned to a node.
    int
    Get the number assigned to a node.
    Gets the parent node of this one.
    Get the string value assigned to a node.
    int
    Gets the type of the node.
    int
    Returns the index position of a node in the array of child nodes.
    void
    insert(int index, RMASNode aNode)
    Inserts a node at position i in the array of children.
    void
    remove(int index)
    Removes the node at position i in the array of children.
    void
    set(int i, RMASNode aNode)
    Replaces the node at position i in the array of children.
    void
    setIntValue(int value)
    Set the integer value assigned to a node.
    void
    setNumber(int value)
    Set the number assigned to a node.
    void
    Set the string value assigned to a node.
    void
    setType(int type)
    Sets the type of the node.
    Returns a string containing the type of node, any associated value and the number of children.
    void
    validate is used to provide additional error checking not covered in the parser grammar.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • RMASNode

      public RMASNode(int nodeType)
      Constructs an RMASNode with the specified type.
      Parameters:
      nodeType - the type of node being constructed.
    • RMASNode

      public RMASNode(int nodeType, int value)
      Constructs an RMASNode with the specified type and integer value. This constructor is primarily used to create nodes representing integer literals.
      Parameters:
      nodeType - the type of node being constructed.
      value - the integer value assigned to the node.
    • RMASNode

      public RMASNode(int nodeType, String value)
      Constructs an RMASNode with the specified type and string value. This constructor is primarily used to create string literals and identifiers.
      Parameters:
      nodeType - the type of node being constructed.
      value - the string assigned to the node.
    • RMASNode

      public RMASNode(int nodeType, RMASNode node)
      Constructs an RMASNode with the specified type and adds the child node.
      Parameters:
      nodeType - the type of node being constructed.
      node - a child node which will be added to the new node.
    • RMASNode

      public RMASNode(int nodeType, RMASNode node1, RMASNode node2)
      Constructs an RMASNode with the specified type and adds the child nodes.
      Parameters:
      nodeType - the type of node being constructed.
      node1 - a child node which will be added to the new node.
      node2 - a child node which will be added to the new node.
  • Method Details

    • getType

      public int getType()
      Gets the type of the node.
      Returns:
      the type assigned to the node.
    • setType

      public void setType(int type)
      Sets the type of the node.
      Parameters:
      type - the type assigned to the node.
    • getIntValue

      public int getIntValue()
      Get the integer value assigned to a node.
      Returns:
      the integer value assigned to a node.
    • setIntValue

      public void setIntValue(int value)
      Set the integer value assigned to a node.
      Parameters:
      value - a value that will be assigned to the node.
    • getStringValue

      public String getStringValue()
      Get the string value assigned to a node.
      Returns:
      the string value assigned to a node.
    • setNumber

      public void setNumber(int value)
      Set the number assigned to a node.
      Parameters:
      value - a unique number that will be assigned to the node.
    • getNumber

      public int getNumber()
      Get the number assigned to a node.
      Returns:
      the number assigned to a node.
    • setStringValue

      public void setStringValue(String value)
      Set the string value assigned to a node.
      Parameters:
      value - a string that will be assigned to the node.
    • get

      public RMASNode get(int index)
      Returns the node at the specified index from the array of child nodes. If the index is outside the range of the array then an ArrayIndexOutOfBounds exception is thrown.
      Parameters:
      index - the index of the child node to return.
      Returns:
      the ith node in the array of children.
      Throws:
      ArrayIndexOutOfBoundsException - if (index < 0 || index >= length).
    • set

      public void set(int i, RMASNode aNode)
      Replaces the node at position i in the array of children. If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.
      Parameters:
      i - the index of the child node to replace.
      aNode - the node to replace the ith node.
      Throws:
      ArrayIndexOutOfBoundsException - if (index < 0 || index >= length).
    • add

      public void add(RMASNode aNode)
      Adds a node to the array of children. If the node is null then it is ignored.
      Parameters:
      aNode - the node to be added.
    • insert

      public void insert(int index, RMASNode aNode)
      Inserts a node at position i in the array of children. The size of the array is increased by one and the nodes from the insertion point onwards are moved to the right.

      If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.

      Parameters:
      index - the index of the child node to replace.
      aNode - the node to replace the ith node.
      Throws:
      ArrayIndexOutOfBoundsException - if (index < 0 || index >= length).
    • remove

      public void remove(int index)
      Removes the node at position i in the array of children. The size of the array is decreased by one and the nodes from the insertion point onwards are moved to the left.

      If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.

      Parameters:
      index - the index of the child node to remove.
      Throws:
      ArrayIndexOutOfBoundsException - if (index < 0 || index >= length).
    • indexOf

      public int indexOf(RMASNode aNode)
      Returns the index position of a node in the array of child nodes. If the node is not one of the current nodes children then -1 is returned.
      Parameters:
      aNode - the node to search the array of children for.
      Returns:
      the index of the node in the array of children, -1 if the node is not a child of this node.
    • getParent

      public RMASNode getParent()
      Gets the parent node of this one. If no parent is define then null is returned.
      Returns:
      the parent node of this one.
    • count

      public int count()
      Return the number of child nodes contained by this node.
      Returns:
      the number of child nodes.
    • toString

      public String toString()
      Returns a string containing the type of node, any associated value and the number of children.
      Overrides:
      toString in class Object
      Returns:
      the string representation of the node.
    • displayTree

      public void displayTree(String prefix)
      displayTree is used to display the structure of the node tree, with the root starting at the current node. The prefix argument is used to ident the text displayed. The level of indent is increased by appending the string " " before calling the displayTree method on each child node. This illustrates the tree structure with nodes at the same level in the tree displayed with the same level of indent.
      Parameters:
      prefix - the string prepended to the text representation for this node.
    • encode

      public byte[] encode(int version)
      The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player. The actions are then encoded to generate the binary data that can be added to an encoded Flash file.

      The version of Flash for which the actions are generated is specified to ensure compatibility with future release of Flash.

      IMPORTANT: The programming model changed with Flash version 5 to support stack-based actions. Earlier versions of Flash are not support. An IllegalArgumentexception will be thrown if the version is earlier than 5.

      Parameters:
      version - the version of Flash that control the actions that are generated.
      version - the version of Flash that the script should be encoded for.
      Returns:
      an array of bytes containing encoded action objects.
      Throws:
      IllegalArgumentexception - is the version is less than 5.
    • validate

      public void validate() throws ParseException
      validate is used to provide additional error checking not covered in the parser grammar.
      Throws:
      ParseException