Class FWSimpleSimComponentCodeGen

java.lang.Object
net.simplace.sim.model.FWSimpleSimComponentCodeGen

public class FWSimpleSimComponentCodeGen extends Object
Generates the Java source of a SimComponent from a FWSimpleSimComponent of a solution (Redmine #61), so a component that was prototyped with JEXL rules in the solution can be turned into a compiled class.

The simple component is chosen by its id. All its rules (process and integrate) are taken over:

  • each rule becomes an output variable and its own commented block in process() (resp. postIntegrate()); a block can be deleted together with its field and its line in createVariables()
  • the variables used in the rules become inputs (i...) or, for solution variables v..., constants (c...), with data type, unit and description of the linked variable
  • the JEXL rules are translated to Java: ${x} to field.getValue(), the word operators eq ne lt le gt ge and or not to Java operators, the namespaces math:, array:, transform:, check:, file: to their classes, single quoted strings to Java strings. Constructs without a direct translation get a TODO comment with the original rule.
Besides the class, the simcomponent element that replaces the simple component in the solution is generated.

Usage (command line): FWSimpleSimComponentCodeGen <solution file> <component id> [package] [class name] [source dir]. Defaults: package "net.simplace.usermodules", class name = component id, source dir = ../simplace_modules/src. The class is written to the source dir, the simcomponent element is printed.

Author:
Andreas Enders, Claude (Anthropic), co-author
  • Field Details

    • DEFAULT_PACKAGE

      public static final String DEFAULT_PACKAGE
      default package of the generated classes
      See Also:
  • Method Details

    • generate

      public static FWSimpleSimComponentCodeGen.GeneratedCode generate(File aSolutionFile, String aComponentId, String aPackage, String aClassName) throws IOException
      Generates the class from a simple component of a solution. The solution is loaded (without running it) to know the data types and units of the variables used in the rules.
      Parameters:
      aSolutionFile - the solution file
      aComponentId - id of the simcomponent with class FWSimpleSimComponent
      aPackage - package of the class, or null for "net.simplace.usermodules"
      aClassName - name of the class, or null for the component id (first letter upper case)
      Returns:
      the generated class and solution element
      Throws:
      IOException - if the solution cannot be loaded
      IllegalArgumentException - if the solution has no simple component with this id (the message lists the available ids)
    • main

      public static void main(String[] aArgs) throws IOException
      Command line: <solution file> <component id> [package] [class name] [source dir]. Writes the class to the source dir (default ../simplace_modules/src) and prints the simcomponent element for the solution.
      Parameters:
      aArgs - the arguments
      Throws:
      IOException - if the solution cannot be loaded or the class cannot be written