# Tasks

## Simulating Operations With Custom Java Code

To simulate a model with operations it is possible to use custom Java code that mocks the desired behavior or even to simulate against an existing java backend.
For that to work, it is required to provide one or more custom java classes having a method with a matching signature.

To simulate the statechart above, a new Java Class must be created matching the method signature defined in the statechart. This class must be placed onto the classpath of the
statecharts project.

    package example;
    public class Calculator {
       public int add(int param1, int param2) {
          return param1 + param2;
       }
    }

This custom class can be passed to the run configuration as Operation Class, shown in the figure below. It is possible to pass multiple java classes seperated by a comma.
If the simulation is executed, the variable result gets the value 2.

## Generating Code

For configuring the code generation process, YAKINDU Statechart Tools uses a textual generator model called SGen. It can be created either by using the provided wizard Yakindu Statechart Generator Model or by creating a new text file with the file extension ‚.sgen’.
To create a generator model with the wizard,

1. Click File > New > Other... > Yakindu Statechart Generator Model
2. Type a name and click Next
3. Choose the desired generator, i.e. YAKINDU Java Code Generator
4. Check the model(s) to generate code from and click Finish

The result is an .sgen file of the following format:

    GeneratorModel for [GeneratorId] {
    	statechart [StatechartReference] {
    		feature [Feature] {
    			[ParameterName] = [ParameterValue]
    		}
    	}
    }

The [GeneratorId] is the unique id of the Generator. Currently, the following Generators are supported out of the box:

1. yakindu::java – Generator ID for the Java Code Generator
2. yakindu::c – Generator ID for the C Code Generator
3. yakindu::xpand – Generator ID for custom Xpand based Code Generators
4. yakindu::generic – Generator ID for custom Java based Code Generators

One GeneratorModel can contain several [StatechartReference]s. These are cross references to statechart models for which the code should be generated. For each reference, the generator process can be configured with [Feature]s. Each Feature consists of several parameters. These parameters can be configured with [ParameterName] = [ParameterValue].

The Generator Model is executed by a builder. Thus, the artifacts are generated automatically if Project > Build Automatically is checked. If you want to execute your Generator Model by hand, select Generate Statechart Artifacts from the Package Explorer’s context menu.