Class PythonGenerator

java.lang.Object
edu.nps.moves.dis7.source.generator.pdus.AbstractGenerator
edu.nps.moves.dis7.source.generator.pdus.PythonGenerator

public class PythonGenerator extends AbstractGenerator
This class autogenerates Python source code from XML PDU definitions, specifically producing most source code needed for the open-dis7-python distribution. TODO see JavaGenerator for related functionality that will be needed in Python. Constructor, not fully implemented.
Author:
DMcG
See Also:
  • Field Details

    • INDENT

      public String INDENT
      Standard python indent is four spaces
    • marshalTypes

      public Properties marshalTypes
      Properties of interest
    • unmarshalTypes

      public Properties unmarshalTypes
      Properties of interest
  • Constructor Details

    • PythonGenerator

      public PythonGenerator(Map<String,GeneratedClass> pClassDescriptions, Properties languagePropertiesPython)
      Given the input object, something of an abstract syntax tree, this generates a source code file in the Python language.It has ivars, getters, setters, and serialization/deserialization methods.Warning: only partially implemented.
      Parameters:
      pClassDescriptions - String Map of class descriptions
      languagePropertiesPython - special language properties
  • Method Details

    • writeClasses

      public void writeClasses()
      Description copied from class: AbstractGenerator
      Overridden by the subclasses to generate the code specific to that language.
      Specified by:
      writeClasses in class AbstractGenerator
    • writeClass

      public void writeClass(PrintWriter printWriter, GeneratedClass aClass)
      Create custom output
      Parameters:
      printWriter - output
      aClass - class of interest
    • writeMarshal

      public void writeMarshal(PrintWriter pw, GeneratedClass aClass)
      The method that writes out the python marshalling code
      Parameters:
      pw - PrintWriter
      aClass - of interest
    • writeUnmarshal

      public void writeUnmarshal(PrintWriter printWriter, GeneratedClass aClass)
      Create custom method
      Parameters:
      printWriter - output
      aClass - class of interest
    • writeClassComments

      public void writeClassComments(PrintWriter printWriter, GeneratedClass aClass)
      Create custom output
      Parameters:
      printWriter - output
      aClass - class of interest
    • writeFlagMethods

      public void writeFlagMethods(PrintWriter pw, GeneratedClass aClass)
      Some fields have integers with bit fields defined, eg an integer where bits 0-2 represent some value, while bits 3-4 represent another value, and so on. This writes accessor and mutator methods for those fields.
      Parameters:
      pw - PrintWriter
      aClass - of interest
    • writeLicense

      public void writeLicense(PrintWriter printWriter)
      Create output
      Parameters:
      printWriter - output
    • sortClasses

      public List sortClasses()
      Python doesn't like forward-declaring classes, so a subclass must be declared after its superclass.This reorders the list of classes so that this is the case. This re-creates the semantic class inheritance tree structure, then traverses the tree in preorder fashion to ensure that a base class is written before a subclass. The implementation is a little wonky in places. // TODO alternative is to provide __inii.py list of classes
      Returns:
      sorted List of classes