Examples

The YAKINDU EA-Bridge contains an example feature that can optionally be installed. It provides several example projects to demonstrate the core functionality and two example scenarios how the YAKINDU EA-Bridge can be used.

Please note that the example feature installs Xtend because it is used for code generation in the examples.

Once installed, the examples are available via the examples wizard: File - New - Example... - YAKINDU EA-Bridge Examples.

Wizard for YAKINDU EA-Bridge example projects

Example Model with UML Profile

The New YAKINDU EA-Bridge Example Project wizard creates a new simple project in your workspace called YAKINDU EA-Bridge Example Project which contains the following files:

readme.txt
Contains a description about the current example project.
YourSystem.eap
An example EA model.

The main purpose of this example project is to provide a model and illustrate some of the features of the YAKINDU EA-Bridge:

  1. The EA model can be opened with the Eclipse EA UML Editor.
  2. The EA model has a custom UML profile applied, e.g. in package Software Model/YourSystem/DATATYPES.
  3. The EA model has annotated requirements in package Blog.
  4. The EA model uses different primitive type languages in package Software Model/YourSystem/COMPONENTS/ComponentB/DATATYPES.

EA example model

Example Project with Live Code Generation

Disclaimer: The YAKINDU EA-Bridge provides an extensive API to load, access, and partially also to modify EA models. This example is only one (very simplified) demonstration to generate some code from EA models that are loaded with the YAKINDU EA-Bridge. This example does neither have proper error handling, nor does scale in size and performance! If you want to create a proper code generator, you should rather access the resource from your own plugins or in a JUnit Plugin test.

The New YAKINDU EA-Bridge Live Codegen Example Project wizard creates a new plugin project in your workspace called YAKINDU EA-Bridge Live Codegen Example which contains the following files, amongst others:

src/com.yakindu.bridges.ea.example.codegen/SampleCodegenTemplates.xtend
The actual code generation templates written in Xtend.
src-gen/*
The generated Java code of the code generator.
model/*
Input models which will be used for code generation.

The main purpose of this project is to illustrate the easy access of EA-models for generating code:

Live code generation

The templates make use of two annotations which demonstrate how code can be generated:

@EACodegen(<file-extension>)
public String <method name>(<UML type> <parameter name>)

All operations annotated with @EACodegen are called for all model elements of the parameter's type, triggered by an Eclipse builder provided with the YAKINDU EA-Bridge example plugin. <UML type> must be a subtype of PackageableElement and it must have a name (because it is used as target file name)! You can either use plain Java for your code generation logic, or you can use Xtend - which provides so-called template expressions to generate Strings:

@EACodegen("java")
def generate(Class c) '''
    ...
'''

This example collects all UML elements of type Class within eap-files of the enclosing project and stores the result in files that are named like the UML classes with the extension java.

By default, the generated files are saved inside the same project in a sub-folder called src-gen. In many cases, it is desirable to use a different target location for the generated files, e.g. another Java project. The optional annotation @EACodegenFile can be used to change the target location of generated files within a template:

@EACodegenFile
public IFile <method name>(<UML type> <parameter name>, IFile <parameter name>)

The example below takes the original path from the enclosing project and replaces the project name with another one.

@EACodegenFile
public IFile mapGeneratedFilePath(PackageableElement element, IFile genFile) {
    String exampleProjectPath = genFile.getFullPath().toString();
    String javaProjectPath = exampleProjectPath.replace(genFile.getProject().getName(), "LibraryInJava");
    return (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(javaProjectPath);
}

Example Project with Live Model Validation

Disclaimer: The YAKINDU EA-Bridge provides an extensive API to load, access, and partially also to modify EA models. This example is only one (very simplified) demonstration to check constraints on EA models that are loaded with the YAKINDU EA-Bridge. This example does neither have proper error handling, nor does scale in size and performance! If you want proper model validation, you should rather access the resource from your own plugins.

The New YAKINDU EA-Bridge Live Validation Project wizard creates a new project in your workspace called YAKINDU EA-Bridge Live Validation Example which contains the following files:

Library.eap
A sample library model.
SampleValidationRules.java
Two custom model validation rules and two different quick fixes for one of them.

The main purpose of this example project is to illustrate model validation capabilities enabled by the YAKINDU EA-Bridge:

Example project with live model validation

The syntax of the annotation @EAValidation which defines the validation methods is defined as follows.

@EAValidation(severity = <severity>)
public String <method name>(<UML type> <parameter name>)

All operations annotated like this are called for all model elements of the parameter's type, triggered by an Eclipse builder provided with the YAKINDU EA-Bridge example plugin. The return value is the error message, or null if the model element is valid. Please see the example below:

@EAValidation(severity = Severity.warning)
public String validateAttributeTypes(Element element) {
    if (element instanceof Property) {
        if (((Property) element).getType() == null) {
            // return message will be the validation message shown in Problems view
            return String.format("Attribute '%s' is missing a type!", ((NamedElement) element).getName());
        }
    }
    return null; // return null if there is no violation
}

The builder collects all eap-files in the enclosing project and calls operation validateAttribuetTypes for all model elements. If the model element is of UML type Property and its type is not set, a validation message is returned that will be reported as a warning on that model element.

It would be nice if the parameter type could be used to filter the model elements already (as it is the case for the code generation annotations below), but this is technically not possible. The EMF validation framework is used to collect the elements and to promote the validation results, and to cover all possible UML types, the highest common UML supertype Element is used.

Example Plugin Project

The New YAKINDU EA-Bridge Example Plugin Project wizard creates a new plugin project in your workspace called com.yakindu.ea.examples.plugin which contains the following files, amongst others:

readme.txt
Contains a description about how to use the current example project.
EAExampleHandler.java
An example handler that is registered for the context menu of eap-files located in the workspace.
HtmlTreeGenerator.java
An example code generator that generates a dynamic SVG tree of your EA model's package structure.

EA example command

This plugin could be the starting point if you intend to process your EA models in a professional way. Please consult the Eclipse Help to learn how to develop and deploy your own Eclipse plugins.

EA example plugin project

Example JUnit Test Plugin Project

The New YAKINDU EA-Bridge Test Plugin Project wizard creates a new JUnit test plugin project in your workspace called com.yakindu.ea.examples.tests which contains the following files, amongst others:

readme.txt
Contains a description about the test project and how to run the tests.
ExampleWithMDGTechnology.eap
A test model which uses a datatype defined in a MDG Technology.
TheMDGTechnology.*
A bunch of EA-specific files that define a MDG Technology; see EA User guide how to use these files in EA.
TheMDGLanguage.uml
The EA programming language datatypes used in the MDG Technology above converted to Eclipse UML; it is registered in plugin.xml.
TheMDGTechnology.profile.uml
The UML profile used in the MDG Technology above converted to Eclipse UML; it is registered in plugin.xml.
LoadAndSaveModelTest.java
The source file that contains the actual tests.

To run the tests, launch class LoadAndSaveModelTest as JUnit Plug-in Test: Run - Run Configurations... - select LoadAndSaveModelTest - press Run.

This project can be used as starting point for your own tests.

EA JUnit test plugin project

Variants Codegen Example Project

The New YAKINDU EA-Bridge Variants Codegen Example Project wizard creates a set of new projects to demonstrate how different variants can be generated from the same model:

com.yakindu.ea.examples.orderingsoftware.template
The project containing the code generation templates.
com.yakindu.ea.examples.orderingsoftware.jpa
The project containing the generated code for the Hibernate persistence option; maven is used to resolve all required dependencies.
com.yakindu.ea.examples.orderingsoftware.jpa.test
Tests for the project above; after a full build, you should be able to run the tests and they should pass.
com.yakindu.ea.examples.orderingsoftware.hbase
The project containing the generated code for the HBase persistence option; maven is used to resolve all required dependencies.
com.yakindu.ea.examples.orderingsoftware.hbase.test
Tests for the project above; after a full build, you should be able to run the tests and they should pass.

(Please note that the hbase-plugins are only enabled if you did not skip the JDK selection option because HBase requires a library that cannot be downloaded by maven.)

To generate the sources, the Eclipse auto-build should be enabled. However, you can also trigger the build manually via Project - Build Project or Build All.

If some the hbase- or jpa-projects still have errors, you could try to re-run maven on them: right click a project - Maven - Update Project... - Select All - OK.

Please see com.yakindu.ea.examples.orderingsoftware.template/readme.txt for more details about the project. This project can be used as starting point for your own code generator.

Variants codegen example project