tasks.textile 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <link href="../../css/bootstrap.css" rel="stylesheet" />
  2. <link href="../../css/custom.css" rel="stylesheet" />
  3. h1. Tasks
  4. h2. Simulating Operations With Custom Java Code
  5. 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.
  6. For that to work, it is required to provide one or more custom java classes having a method with a matching signature.
  7. !images/operationsExample.png!
  8. 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
  9. statecharts project.
  10. bc.
  11. package example;
  12. public class Calculator {
  13. public int add(int param1, int param2) {
  14. return param1 + param2;
  15. }
  16. }
  17. 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.
  18. If the simulation is executed, the variable result gets the value 2.
  19. !images/runConfiguration.png!
  20. h2. Generating Code
  21. 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'.
  22. To create a generator model with the wizard,
  23. # Click *File* > *New* > *Other...* > *Yakindu Statechart Generator Model*
  24. # Type a name and click *Next*
  25. # Choose the desired generator, i.e. *YAKINDU Java Code Generator*
  26. # Check the model(s) to generate code from and click *Finish*
  27. !images/genmodelwizardchooselanguage.jpg!
  28. The result is an .sgen file of the following format:
  29. bc..
  30. GeneratorModel for [GeneratorId] {
  31. statechart [StatechartReference] {
  32. feature [Feature] {
  33. [ParameterName] = [ParameterValue]
  34. }
  35. }
  36. }
  37. p. The [GeneratorId] is the unique id of the Generator. Currently, the following Generators are supported out of the box:
  38. # yakindu::java - Generator ID for the Java Code Generator
  39. # yakindu::c - Generator ID for the C Code Generator
  40. # yakindu::xpand - Generator ID for custom Xpand based Code Generators
  41. # yakindu::generic - Generator ID for custom Java based Code Generators
  42. 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].
  43. 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.