Delegate Code Generation

The SysML Client includes a utility to auto-generate Java interfaces and classes from the blocks in your model. This significantly decreases development time and ensures accuracy by generating the correct property names and method signatures to match your blocks' properties and operations. You can find the delegate code generator in the Code Generation menu of the SysML Client.

Required inputs

  • Target SysML packages or specific blocks to generate from the Containment Tree in your No Magic modeling tool
  • Output directory
  • Default Java package name

Optional inputs

  • Include @AutoDelegateImplementation
  • Include class implementations
    • Class prefix
    • Class suffix
    • Generate abstract or concrete class?
    • Generate delegate provider?
    • Delegate module name

You can also specify an override for the Java package name for a specific block or package by using the CodeGenerationJavaPackage stereotype from Behavior Execution Engine's base model library. The value you specify for this stereotype's tag will override the package name the code generator will use when generating interfaces and classes and when referencing them from any other generated code. Behavior Execution Engine's model libraries have been annotated in this way so that when you generate your code referencing them, it will use the correct import statements. If you generate code for Behavior Execution Engine's model libraries, it will use package names from com.agi.moxie.*, but you should not include any of those generated interfaces or classes in your delegate modules or you will run into conflicts at runtime.

Interface generation

Since a majority of simple blocks will have implementations provided at runtime, consider generating interfaces for them if you need to reference the automatically implemented properties from other types. This is particularly useful for simple data containers. This also pairs well with the @AutoDelegateImplementation system.

These interfaces are intended to be generated and re-generated whenever the SysML models change. In this way, Behavior Execution Engine supports the traceability and maintainability between the Java and the SysML model. So, ideally, these files would be included into your Java project in a way where they can be re-generated and recompiled easily to highlight any changes in the SysML as compile errors in Java. However, the interfaces can also serve simply as sample code to help streamline the development process so you can pull in the properties and operations that you need to implement.

Class generation

In addition to interface generation, Behavior Execution Engine also provides class generation. These generated classes allow you to get up and running with Behavior Execution Engine as quickly as possible. The created classes will contain implemented properties, annotations, and type hierarchies that are set up in an intelligent way across all classes. These classes are intended to be edited and not regenerated.

You can choose to produce the classes by selecting the desired class type in the Configure Elements window. Only the items that are selected in the Select Element(s) to Generate and the items they contain can have a generated class. If no items are selected in the tree, then all non-auxiliary items in the containment tree will be generated except for the Behavior Execution Engine model libraries. All classes will be produced in a .impl subpackage with interfaces generated in the parent package.

Prior to generating the classes and interfaces, this part of the code generation tool allows you to:

  • Specify a prefix for all generated class names.
  • Specify a suffix for all generated class names. Delegate is the default suffix.
  • Select whether the generated classes should be abstract.
  • Select whether to generate Gradle build files and a delegate provider alongside the interfaces and classes.
  • Specify the name of the delegate module. This only affects the Gradle build files and the delegate provider.

Classes marked as abstract in the SysML will not be generated even if selected in the Configure Elements.

Packages with the MoxieExcludeFromClassGeneration stereotype will have all elements within excluded from class generation.

Build files and delegate provider

The second-to-last option in class generation enables you to generate Gradle build files and a delegate provider for your delegate module. Generating these files can save you time and errors when setting up a way to build your Java delegate code. You should not need to select this option again when regenerating interfaces.

This option generates the following files:

  • A build.gradle file with tasks for installing and debugging your delegate module
  • A gradle.properties file with file paths that you should configure (see the gradle.properties setup steps)

    You will not be able to use the debugging task in build.gradle until you configure the No Magic modeling tool properties in this file.

  • A settings.gradle file with the name of your delegate module, which is used when building
  • A README.txt file with quick instructions on using these build files
  • A delegate provider configured with the list of all the interfaces and classes generated alongside it
  • An SPI file for the delegate provider that is automatically included when building