Subsections of Actifsource

Subsections of Manual

Eclipse Manual

icons1 icons1

Manual Actifsource User Manual
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

actifsource-point-large actifsource-point-large

Subsections of Eclipse Manual

Overview

Working with models

Actifsource is a comprehensive design and code generator tool, covering all aspects of domain-driven software development from domain analysis through to the design models, code generating, testing, refactoring and maintenance.

Actifsource allows you to define your domain-specific software specification.

image5 image5

This software specification is also called domain model, or specific model. The domain model shall be independent from any used technology (i.e. programming language, operating system, etc.).

image6 image6

As the domain model is domain-specific by definition, we need to specify the structure for every domain. This task is done in the so called meta-model.

image7 image7

The meta-model is built upon concepts of the Actifsource core model (aka Meta Meta-Model). Note that the core model is self-describing, i.e., it is the meta-model of itself.

image8 image8

To find an adequate meta-model, you need to analyze your business domain. If you like to create a Service Oriented Architecture (SAO), your meta-model might will contain services. If you like to model state machines, your meta-model will define states, event and transitions.

Note that the Meta-Model is an abstraction of your business domain, and defines the business classes and their relationships.

As we do not know your meta-model in advance, we cannot generate any suitable code for you. This means, that you have to define your own code templates according to the meta-model. Defining code templates is as easy as writing normal code.

image9 image9

Since everything depends on the meta-model you have to start by analyzing your business domain. Once the meta-model is defined, you are able to enter you domain specific software specification accordingly. Also template code is written along the meta-model. From this three models (meta-model, domain model, code template) your code is generated by the Actifsource code generator.

image10 image10

Resource

Every model consists of so called resources. A resource is like an object and the most abstract entity from the Actifsource core model. In fact, every model element is a resource.

Every resource is identified by a globally unique identifier (GUID) which is automatically assigned, if you create a new resource. Therefore changing resource names never affects any relation between resources.

Getting started

To get started with Actifsource, we suggest our tutorials on the Actifsource web site. Please visit www.actifsource.com/tutorials.

image11 image11

Actifsource Environment

Actifsource Eclipse Plugin

Actifsource is shipped as Eclipse Plugin. Please make sure to install Eclipse first. Choose Help/Install new Software… to install Actifsource from one of the following Eclipse Update Sites:

If you are not familiar with the Eclipse environment, please consult the Installing Actifsource.

Memory Usage

The Actifsource technology allows you to track any keystroke in real-time. As a result of this feature the memory consumption might be quite high for larger models. Make sure to adopt the memory given to Eclipse if necessary in the eclipse.ini file in the Eclipse directory. We suggest at least 4 GB of ram.

image12 image12

To observe the memory while working with Actifsource enable Window/Preferences/General/Show heap status.

image13 image13

Make sure to enable Show Max Heap to track the maximum memory usage by using the context menu on the heap status display.

image14 image14

Perspectives

Since Eclipse is a general software development tool, you must be able to select different perspectives. Make sure that the Actifsource Perspective is selected when working with Actifsource.

image15 image15

Actifsource Preferences

The preferences dialog (Window/Preferences/Actifsource) provides the following configuration options.

Statistics

Selecting the Actifsource menu shows a statistic of the resources.

image16 image16

  • Reources The number of resources in the project.
  • RootResources The number of root resources in the project. A root resource is a non-aggregated resource.
  • Statements The number of statements in the project. The statement declares three resources as follows: Subject-Predicate-Object.

Generator

image17 image17

  • Always clear generator console before generate Actifsource cleans the console output before generating code. This makes it easier to scroll to the top of the output to find error messages.

Style Configuration

The style configuration let you define your own colors.

image18 image18

  • Profile Shows all built-in and user-defined profiles.
  • Edit Edit user-defined profiles. Note that you cannot edit built-in profiles.
  • Copy Copy built-in or user-defined profiles. Use copy on a built-in profile to create a user-defined profile.
  • Remove Removes user-defined profiles. Note that you cannot remove built-in profiles.

Validator

image19 image19

  • Revalidation Delay (ms) Actifsource validates every keystroke. The validation might lead to a high CPU load for large models. For this reason you can configure the delay between validations.

Project Wizard

The project wizard allows you to create a new Actifsource project from scratch. Select File/new/Actifsource Project.

Project Name and Location

image20 image20

  • Project name This is the name of the new project. We suggest that the project name is given in the eclipse-like manner: com.company.project.subproject. Note that the dotted name automatically leads to a corresponding package structure. image21 image21
  • Location This is the location of the project. The default location is in the workspace.
  • Working Set You might add the project to an existing working set. A working set is a dedicated view to the projects of the workspace.

Resource Paths

image22 image22

All Actifsource resources are saved in Resource Files with the ending .asr in an xml format. The resource path defines where to find the model resources.

  • Add Resource Path Adds a new resource path to the project.
  • Edit… Edits an existing resource path.
  • Remove Removes an existing resource path.
  • Generate javamodel Actifsource builds internal Java classes to handle your model. Do not switch off this option unless you know exactly what you do.

Target Folder

Generated code is written to target folders. You might specify any existing or new folder in your project as a target folder.

image23 image23

  • Add Target Folder… Adds a new target folder to your project.

  • Add Build Config Adds a new build configuration to your target folder.
    A build configuration is kind of a make file that tells actifsource which templates to build. If no build configuration is defined, Actifsource automatically generates code for all templates from the current project, combined with all matching resources from the current project (see Build Config, see Template Editor).

  • Add Package… Adds a new package to your build configuration. Code is only generated for matching resources found in the specified packages.

    • com.actifsource.statemachine.specific.* (all resources in the package)
    • com.actifsource.statemachine.specific.** (all resources in the package and its subpackages)

    If no package is defined, Actifsource generates code for all matching resources found in all packages of the current project.

Info

Note that you need to reference packages from other projects explicitly. Set the project dependencies first accordingly.

  • Add Resource… Adds a single resource to your build configuration. If no resource is defined, Actifsource generates code for all matching resources found in all packages of the current project.
Info

Note that you need to reference resources from other project explicitly. Set the project dependencies first (see Chapter 2.5.5 Project Dependencies).

  • Edit… Edits the current entry.
  • Remove Removes the current entry.
  • Ignore Whitespaces Actifsource calculates a checksum (MD5 hash) for every generated file.
    If this option is checked, Actifsource will ignore whitespaces when calculating the checksum.
  • Execute Save Actions Eclipse supports so called Save Actions after a file has been saved (i.e. code formatting). If this option is checked, save actions are executed after generating the files.

Template Folders

image24 image24

This feature is for beta users and developers only and might be used to reference folders for templates of third party products.

Project Dependencies

image25 image25

Use the project dependencies if you like to split your model in different Actifsource projects. Note that you have to set the project dependencies, before you might reference packages and resources from other projects in the target folder.

  • Add Project Adds a new project dependency.
  • Edit… Edits the current project dependency.
  • Remove Removes the current project dependency.

Built-in Dependencies

image26 image26

Use the built-in dependencies to reference any Actifsource built-in models.

Built-In Description
CORE The Actifsource core model (do not remove)
DIAGRAM Domain Diagram
CIP Embedded real-time state engine
DEC Modelling I/O connection and scheduling for embedded systems
OCUMENTATION_METAMODEL Creates meta-model documentation from class diagrams
JAVAMODEL Creates Java classes for model access (shipped with Core built-in)
GRAPHVIZ Generator for graphviz
WORKSPACE File/folder operations and generating Eclipse projects
DATATYPE Common data type meta-model
UML UML state engine and code generator
ECORE ECore meta-model
MODVIS Visualization and animation of domain diagrams in the web browser
FREEMARKER Generator for freemarker templates
XPAND Generator for xpand templates
  • Add Builtin Adds a new built-in project dependency.
  • Edit… Edits the current built-in project dependency.
  • Remove Removes the current built-in project dependency.

Project Properties

All settings shown in Chapter 2.5 Project Wizard can be found in Project/Properties/Actifsource.

image27 image27

Standard Package Structure

We suggest the following package structure.

image28 image28

  • Generic The generic package contains the meta-model.
  • Specific The specific package contains the domain model.
  • Template The template package contains the code templates.

Project Menu

Use the project menu to control the build system of Eclipse and Actifsource.

image29 image29

  • Build Automatically If Build Automatically is switched on, Eclipse will build the project automatically after changed files have been saved.

    Actifsource also generates Java classes for internal use. Generating these internal classes is also switched off by Build Automatically and you can’t expect Actifsource to work correctly. Therefore, please make sure that Build Automatically is switched on.

    Please make yourself familiar with the Eclipse Builder concept. See Project/Properties/Builders to see the active builders for your project and their execution order (see Chapter 7.7 Eclipse Builder).

image30 image30

  • Generate Automatically If Generate Automatically is switched on, Actifsource will generate code after saving changed files. If Generate Automically is not switched on, you have to trigger code generation manually (Right-click on the Eclipse project and select Generate Code).

    Actifsource also generates Java classes for internal use. Generating these internal classes is not switched off by Generate Automatically.

  • Enable External Builder This feature is for beta users and developers only. Since Actifsource is developed by Actifsource, we must be able to build ourselves with the current version. The external builder is compiled at development time and ensures that every change in the Actifsource workspace affects the next code generation run.

Toolbar

The Actifsource toolbar provides you with two important tools.

  • New Actifsource Resource image31 image31 The new resource tool lets you create a new Actifsource resource in the selected package. The new resource tool only allows creating so called root classes.

  • Open Actifsource Resource image32 image32 This tool shows all resources and allows filtering by name. Please note that this operation might be slow for a large amount of resources.

Project Explorer

The project explorer let you access your resource files. Resources are stored as xml files and named by the GUID (Globally Unique Identifier) of the resource. Since this format is incomprehensible for humans, the Project Explorer shows the name for named resources.

image33 image33

Switch on the option Link with Editor to synchronize the project explorer with the currently active editor.

Actifsource Presentation

Actifsource allows you to show aggregated resources sorted by relation or just by their occurrence in the containing class.

  • Group Aggregation By Relation switched on

    image34 image34

  • Group Aggregation By Relation switched off

    image35 image35

Package Presentation

image36 image36

  • Flat Package Presentation Using the flat package presentation, all packages are shown as a flat list.

    image37 image37

  • Hierarchical Package Presentation Using the hierarchical package presentation, the hierarchy is preserved. Note that folders which do not contain files are shown flat anyhow. This might lead to problems if you like to add new files or folders in a collapsed package. Just switch to the flat package presentation to solve this problem.

    image38 image38

Drag and Drop

Use drag and drop to move resources between packages. All references to the resource are kept automatically.

image39 image39

Project Explorer Context Menu

The context menu of the project explorer supports several important operations on packages and resources.

New Dialog

The new/Actifsource dialog creates different types of actifsource files. For some types of resources, you can create new resources based on existing resources.

  • New Actifsource Project Creates a new Actifsource project in the current workspace with the project wizard, as shown in Chapter 2.5 Project Wizard.
  • New BuildConfig Creates a new BuildConfig which can be referenced in target folders (see Chapter 2.5.3 Target Folder and Chapter 7 Build Config).
  • New Class Diagram Creates a new class diagram for UML-like Meta-Model design. The class diagram is the easiest way to create Meta-Models.
  • New Diagram Type Creates a new diagram type which defines a user specific domain diagram. Creating a new diagram type on an existing class preselects this class as the RootClass.
  • New Domain Diagram Creates a new domain diagram. Domain diagrams are based on diagram types.Creating a domain diagram on an existing resource preselects this resource as the singleRoot. The diagram type is automatically selected by the type of the singleRoot. If no singleRoot is defined, it is created automatically with the type defined by the diagram type.
  • New FunctionSpace Creates a new function space (see Chapter 9.2 Function Space).
  • New Package Creates a new package.
  • New Resource Creates a new resource of any type.
  • New Resource Folder Creates a new resource folder (see Chapter 2.5.2 Resource Paths).
  • New Template Creates a new code template (see Chapter Template Editor). Creating a new template on an existing class preselects this class as the base type.

Open with

The Open with dialog forces eclipse to open files with a specific editor. The first element in the Open With list is the default editor. Once opened with another than the default editor Eclipse reminds this setting when double clicking the file to open. Just select Open With/Default Editor to restore the settings.

image40 image40

Actifsource supports the following editor types:

  • Resource Editor The Actifsource Resource Editor is the standard editor which opens all types of Actifsource resources.
  • Class Diagram Editor The Actifsource Class Diagram Editor opens resources of type ClassDiagram.
  • Domain Diagram Editor The Actifsource Domain Diagram Editor opens resources of type DomainDiagram.
  • Template Editor The Actifsource Template Editor opens resources of type Template.

Rename Resources and Packages

image41 image41

You may rename any resource or package via the context menu/rename or by pressing F2 (Windows).

Generic Refactoring

If you change your meta-model, any depending domain model might become invalid. Actifsource lets you register a piece of Java code, which transforms all existing domain models to fit the new meta-model.

Actifsource also uses this feature intensely if there are changes in the core model (meta meta-model). Please make sure to check the release notes to see if you need to run a Generic Refactoring after updating to a new Actifsource Version.

image42 image42

Compare With

image43 image43

Working together in a team, you might have collisions when checking Actifsource resource files (.asr) into your version control system (i.e. CVS, SVN, GIT etc.).

Actifsource lets you compare resources and resolve conflicts in the compare view of the Resource Editor.

Show Resource Dependencies

In the context menu of the selected resource you will find the following commands to show specific dependencies.

  • Show Instances image44 image44 Shows all instances of the selected resource. Note that a resource must be of type Class to have instances. See also Chapter 2.12.2.
  • Show Types image45 image45 Shows all types of the selected resource (typeof statement). See also Chapter 2.12.2.
  • Show Subclasses image46 image46 Shows all sub classes of the selected resource (extend statement). Note that a resource must be of type Class to have sub classes. See also Chapter 2.12.2.
  • Show Superclasses image47 image47 Shows all super classes of the selected resource (extend statement). Note that a resource must be of type Class to have super classes. See also Chapter 2.12.2.
  • Show References image48 image48 Shows all resources that are referencing the selected resource. See also Chapter 2.12.6.
  • Sot Property image49 image49 Sorts resources referenced by a relation. Note that you can sort according to any literal attribute (i.e. name).

image50 image50

Info

Note that you have to switch on Group Aggregation By Relation (see Chapter 2.10.2 Actifsource Presentation) to see the relations.

Actifsource Views

AQL Query

image51 image51

The Actifsource Query Language let you query the model.

Hierarchy

image52 image52

Shows the hierarchy between resources.

Model Inconsistencies

image53 image53

Shows all model inconsistencies calculated by the validator. Make sure that this view is always visible to check whether your model is valid or not. Note that the code generator could throw an exception if your model is invalid.

Model Navigator

image54 image54

The model navigator shows all resources sorted by projects, packages and types. Use the model navigator to find classes outside your project.

Protected Regions

image55 image55

Shows all protected regions from a generated file. Click on the entry to navigate to the protected region in the selected file.

References

image56 image56

Shows all references to a specific resource in the form Subject-Predicate-Object while object is the referenced resource.

Resource Editor

Overview

The Actifsource Resource Editor allows you to view and/or edit any Actifsource resource. Since everything is a resource in Actifsource this is the most important editor.

The Actifsource Resource Editor shows resources as tree (similar to the Windows Explorer).

image57 image57

Aggregated vs. Referenced Resource

Actifsource distinguish between aggregated and referenced resources. An aggregated resource lives in the context of the parent resource. Deleting the parent resource will delete all aggregated resources.

Referenced resource may live anywhere in the model and are just referenced. Delete the referencing class will not affect the lifetime of the referenced resource.

Property

All information is grouped by properties (see also Chapter Property). Actifsource distinguish the following property types.

image58 image58

Class Meaning
Property Base class for all properties
Relation Base class for all relations
Composition Leads to aggregated resources (UML: Aggregation, Composition)
UseRelation Leads to referenced resources (UML: Association)
Attribute Primitive literals (String, Boolean, Integer, etc.)

Open/Close Folding

To work with large resources efficiently, Actifsource can expand or collapse aggregated resources.

image59 image59

Use the following possibilities to expand/collapse resources.

Device Action
Mouse Klick the [+] [-] sign\ DoubleClick the property
Context menu Open/Close Folding
Keyboard Enter (Open/Close Folding)\ Backspace (Close Folding)

The typeOf Statement

The typeOf statement of a resource shows the instantiation relation and declares the type of this resource.

image60 image60

Actifsource only allows a typeOf relation to resources of type Class.

image61 image61

Read Only View

image62 image62

Deploying Actifsource Models as an Eclipse Plugin (see Chapter 15 Plugin Project) leads to a read only view of the models. Models that are read-only are displayed in gray colors.

Info

Note that the Actifsource Core Model is read-only for you.

The breadcrumb helps you navigating large resources.

image63 image63

Clicking on the arrow in the breadcrumb allows you navigating all resources from the same property.

image64 image64

Focusing aggregated resources

Clicking on a resource in the breadcrumb allows you to focus only on this aggregated resource. Use this feature to work with large resource files.

image65 image65

Browse resource

Actifsource allows you to browse any resource in any editor.

image66 image66

To browse any resources in actifsource use the following possibilities.

Device Action
Mouse Ctrl+LeftClick
Context menu Browse Into
Keyboard F3

Insert resource

Insert on the empty line

Actifsource shows an empty line for all properties which might have another instance (depends on the subject cardinality; see Chapter 4.4.1 Property).

image67 image67

To insert a resources on the empty line use the following possibilities.

Device Action
Mouse Ctrl+DoubleLeftClick on the property
Context menu Insert here
Keyboard Enter

Insert before or after properties

Actifsource allows inserting resources before or after existing properties.

image68 image68

To insert an aggregated resource before or after an existing resource use the following possibilities.

Device Action
Mouse Ctrl+DoubleLeftClick to insert after the current resource\ Ctrl+Shift+DoubleLeftClick to before after the current resource
Context menu Insert after to insert after the current resource\ Insert before to insert before the current resource
Keyboard Ctrl+Enter to insert after the current resource\ Ctrl+Shift+Enter to insert before the current resource

Reference resource

image69 image69

To reference any resource use the content assist.

Device Action
Context menu Open Content Assist
Keyboard Ctrl+Space

You may also type some letters to filter the resources.

Info

Note that Actifsource supports content assist in many different situations. Just try Ctrl+Space to activate content assist via keyboard

image70 image70

New referenced resource

You are able to create new referenced resources just by typing the named and select new from the content assist.

image71 image71

The place where the resource is created depends on the UseRangeRestrictionAspect (see Chapter 4.4.4 UseRelation). If there is no UseRangeRestrictionAspect defined, the new resource is created in the same package as the referencing resource.

Move resource

If you need to change the order you can simple move resources up and down within the same property.

image72 image72

To move resources up and down use the following possibilities.

Device Action
Context menu Move Down\ Move Up
Keyboard Alt+CursorDown\ Alt+CursorUp

Sort property

Actifsource lets you sort all resources of the same property by any literal (i.e. name property).

image73 image73

Info

Note that Actifsource supports content assist in many different situations. Just try Ctrl+Space to activate content assist via keyboard

Quick Assist

Sometimes Actifsource offers a quick assist to fix common issues. Hoover the mouse pointer over the light bulb symbol image74 image74 to get a tooltip with a short description of the problem.

image75 image75

Click on the bulb symbol to get the possible solutions.

image76 image76

Device Action
Mouse Click on the bulb symbol
Keyboard Ctrl+1

Core Model Meta Meta-Model

Overview Core Model

Every meta-model is based on the Actifsource Core Model. Make sure that you understand the concepts of Resource, Class and Property before you start creating your own meta-model.

image77 image77

Resource

In Actifsource everything is a Resource. That means that every Resource you create extends the Resource. Even Resource extends Resource, so that the core model can describe itself.

image78 image78

If the Resource shall has a name you can extend from NamedResource.

image79 image79

Class

Creating your own meta-model you have to specify a set of classes and their relationships. The Core Model therefore provides you a NamedResource called Class. Class is the only Resource in Actifsource that can be instantiated where in this context we mean by instantiate that there is a typeOf relation. For that reason Resource is of type Class and Class extends NamedResource.

This recursive definition becomes necessary as the Actifsource core model has to describe itself. You can say that the Actifsource core model is meta-model of itself.

image80 image80

Property

Any information is modelled by a property. Specifying your own class therefore also means specifying all properties of this class.

image81 image81

There are different types of properties.

image82 image82

Property

The property acts as an abstract base class. Please note that properties are fully typed. In Actifsource the type of a property is named range.

image83 image83

Every resource that can be referenced by a range has to be of type AbstractType. One abstract type you already know by now is Class.

image84 image84

  • SubjectCardinality The Property defines the subject cardinality which determines how many resources of type B can be referenced by a resource of type A via relation b.
    image85 image85
    You may choose one of the following predefined cardinality instances.
    image86 image86
    It is also possible to define any other cardinality just by specifying minCardinality and maxCardinality.
    image87 image87

  • Relation The relation acts as an abstract base class for any relation property between classes.

  • Extends The relation extends allows you to define sub-properties of existing properties in a super class.
    image88 image88
    ASub.bSub extends A.b in the following example. That means that instances of ASub can have only references to resources of type BSub while it is still possible to access the ASub.bSub resources via A.b as type of B
    image89 image89
    It is also possible to have more than one sub-property that extends the same super-property, as long as the sum of cardinalities of the sub-properties complies with the cardinality of the super-property.
    image90 image90
    Please note that is it only allowed to extend a property of the same type (i.e. UseRelation extends UseRelation, Composition extends Composition).

  • ObjectCardinality The Relation defines the object cardinality which determines how many resources of type A can reference a resource of type B via relation b
    image91 image91
    You may choose one of the following predefined cardinality instances.
    image92 image92

UseRelation

The UseRelation (UML: Association) references another resource without affecting the lifetime of this resource. Deleting the referencing resource will not delete the referenced resource.

image93 image93

The range of UseRelation is AbstractType.

image94 image94

  • UseRangeRestrictionAspect You may want to restrict resources that can be referenced by a UseRelation depending on their context. Consider a state machine where only target states of the own state machine shall be selected.
    image95 image95
    Let’s define a UseRangeRestriction aspect for Transition.state that allows only states of the own state machine. Select the ResourceSelectorAspectImplementation for the easy to use Selector-Syntax (see Chapter 9.3.2 SelectorFunction) or the JavaAspectImplementation for a powerful Java implementation.
    image96 image96
    Starting from Transition navigating backwards via transition and state (note the minus sign for backward navigation) to Statemachine where navigating forward to all States.

Composition

The Composition (UML: Aggregation, Composition) aggregates another resource. Deleting the aggregating resource of type A will delete the referenced resources of type B

image97 image97

Please note that you have to adjust the ObjectCardinality if B may be owned either from A1 or A2

image98 image98

The range of Composition is Class.

image99 image99

DecoratingRelation

Combining two existing models together is a very important task. Sometimes this is done by so called model transformation. Actifsource chooses another way, because model transformation often only works in one direction. Actifsource allows decorating existing resources with other ones. That means that we can add any auxiliary information to already existing information. You will find out that this is a very powerful concept.

The DecoratingRelation allows building a homomorphism. A homomorphism is a structure-preserving map between two structures. The word homomorphism comes from the ancient Greek language: ὁμός (homos) meaning "same" and μορφή (morphe) meaning "shape".

Consider a resource A1 with a list b1 of resources of type B1 Consider a second List A2 that has a reference a1 to a resource of type A1 The decorating relation A2.b2 shall have 0..1 resources of type B2 for any resources reached via A2.a1.b1

image100 image100

The decorating relation A2.b2 needs a decorating aspect which defines where to find the resources that shall be decorated.

image101 image101

Let us create a resource TestA1 of type A1 first.

image102 image102

Now let us create a resource TestA2 of type A2 with a reference to TestA1 Please note that A2.b2 is now decorating A2.a1.b1 what is indicated by the brackets (i.e. b1[B1_1]).

image103 image103

Creating a decorated resource will automatically fill in the target property b1

image104 image104

Please note that the decorating relation needs a subclass of type Decorator.

image105 image105

If your decorating relation does not point to a resource which fits the requirements Actifsource comes up with a quick assist (see also Chapter 3.10 Quick Assist).

image106 image106

The quick assist extends the range of the decorating relation from Decorator and adds a sub relation to Decorator.target with type of the target of your decorating aspect.

image107 image107

SelectorRelation

[TBD]

Attribute

The Attribute allows creating simple literals. There are some predefined literal instances that you might use. Please note that the range of an attribute is Literal where Literal is also an AbstractType as already seen for Class (see Chapter 4.4.1 Property).

image108 image108

  • BooleanLiteral The Boolean literal allows the values true or false only.
  • DoubleLiteral The double literal is a 64 bit floating point value.
  • IntegerLiteral The integer literal is a 32 bit integral value.
  • LongLiteral The long literal is a 64 bit integral value.
  • StringLiteral The string literal is a single-line string value.
  • TextLiteral The text literal is a multi-line string value.
  • ScopePathLiteral The scope literal allows referencing any file in the current project.
  • JavaTypeLiteral The Java type literal allows referencing a Java class or interface.
  • JavaClassLiteral The Java type literal allows referencing a Java class.
  • JavaInterfaceLiteral The Java type literal allows referencing a Java interface.

AbstractType

image109 image109

As we have seen before, Class and Literal both extend AbstractType. Furthermore, AbstractLiteral is of type Literal and Resource is of type Class. To complete this picture, we can add Any which is of type AbstractType.

Core Resources

The Actifsource Core provides a set of resources that allows you to build your own meta-model. The most important resources are Class with its Properties and Enum.

ch.actifsource.core.Class

image110 image110

  • typeOf To act as a class a resource has to be of type Class. To be type something of means to be an instance of something.
  • comment The comment text literal let you comment your classes and literals. Comments are shown in tooltips when hovering the mouse pointer over class and property names.
Info

Note that the comment property is inherited by extending from Commentable. Extending from Commentable allows writing comment for any resource and activates the tooltip functionality.

  • aspect[InitializationAspect] The initialization aspect initializes a resource during creation. To be provided as Java class.
  • aspect[ResourceValidationAspect] The resource validation aspect defines specific validation rules for a resource. To be provided as Java class.
  • aspect[NameAspect] The name aspect defines the name of a resource. To be provided as Java class or in the simple selector syntax.
Info

Note that you might define a selector aspect pointing to a TemplateFunction (see Chapter 9.3.6 TemplateFunction) or a TemplateLineFunction (see Chapter 9.3.7 TemplateLineFunction).

  • extends Defines the base class and inherits all properties when instantiating.
  • modifier The modifier defines if a class can be instantiated or sub classed.\
Modifier Description
Abstract No instance allowed of this class.
Final No subclass allowed of this class.
  • property Defines the property of this class. Properties carry the data when instantiating the class. Choose the property type you need (see also Chapter Property).

    image111 image111

  • definesAspect Defines aspects for instances of this class (see also aspect[InitializationAspect], aspect[ResourceValidationAspect], aspect\NameAspect] which are defined in the aspect property of the class Class.

  • allowRoot A Class is a root class if it is not aggregated exclusively (that mean owned by an ownRelation with ObjectCardinality1_1). Set this flag to true or false if you want to overwrite the Actifsource logic.
    Please note that only root classes can be created directly via the New Actifsource Resource Tool (see Chapter 2.9.1 New Actifsource Resource).

  • classIcon Sets an icon for this class and all instances. You can select an icon project by using content assist to browse the current project. The icon size shall be 16 x 16 pixels.

  • lineColor Deprecated.

  • fillColor Deprecated.

  • shape Deprecated.

ch.actifsource.core.Enum

The enum is a class with a set of values.

image112 image112

  • Value Technically the value is an instance of the enum and therefore fully typed.
Info

Note that you might define properties in your enum which are than accessible in the values.

image113 image113

Diagram Editor

Overview

Actifsource offers graphical editors to view and edit the meta-model and model. For editing the model it is possible to define domain-specific editors.

Class Diagram Editor

The class diagram editor allows you to create new meta-models based on Actifsource classes.

New Class Diagram

You can create a new class diagram via context menu in the project explorer or File/New.

image114 image114

Preselecting a package will directly fill in the resource path and package in the wizard.

image115 image115

Palette

Use the palette to edit your diagram.

image116 image116

  • Select Selects one or many classes from the diagram. Use Ctrl+Click for multi select.

  • Marquee Selects classes from the diagram within a rectangle.

  • Extension Derives a class from another class by adding a Class.extend statement in the sub class.

    image117 image117

    Inserting an extends-relation from MySubClass to MyClass would add an extends-relation from MySubClass to MyClass as expected. At the same time the extends-relation from MySubSubClass to NamedResource is removed because MyClass already extends NamedResource.
    The same rule also applies when extending from Resource.

Info

Note that are special rules for your convenience. Consider creating two new Classes MyClass and MySubClass Both are extending NamedResource by default.

image118 image118

  • Relation Inserts a relation from a class to another. Select one of the relation types or a base relation. Selecting a base relation automatically selects the relation type needed (see Chapter Property).

image119 image119

  • Note Connects class to any note. See also New Note.
  • New Class Inserts a new class on the diagram and in the model. Note that the preselected namespace (package and/or containing resource) is the same as the package of the class diagram.
Info

Note that you can directly select the super class in this dialog. While NamedResource is the default you may select**Resource** to create an unnamed resource, or any other Class. For other properties see also Chapter 4.6.1 ch.actifsource.core.Class.

image120 image120

  • New Enum Inserts a new enum on the diagram and in the model. For other properties see also Chapter 4.6.2 ch.actifsource.core.Enum.
  • New Note Inserts a new note on the diagram. Click on the first text line of the note to enter the edit mode.

image121 image121

Drag and Drop

Use the drag and drop feature from the project explorer to add an existing class to your diagram.

image122 image122

Context Menu

Use the context menu on the diagram background.

image123 image123

  • Show Shows any existing resource in the scope of your project. Use this feature to insert resources from third party or Actifsource models to your diagram (i.e. Actifsource Core Model).

Class Context Menu

Use the content menu on any class.

image124 image124

  • Delete from Diagram Deletes this class from the diagram only but not from the model. Use Delete on the keyboard to delete selected classes from the diagram.
  • Delete from Model Deletes this class from the diagram and from the model. Use Shift+Delete on the keyboard to delete selected classes from the diagram and from the model.
  • Show Attributes Shows attributes (literals) in an UML-like style.

image125 image125

  • Hide Attributes Hides shown attribute (see also Show Attributes).

  • Instances Inserts instances of a specific class on the diagram.

    image126 image126

  • Types Shows the types (Class.typeOf statement) of a specific class.

  • Super Class Shows the superclass (Class.extend statement) of a specific class. You this feature repeatedly to show the inheritance hierarchy.

Browse Resource

Open any class in the resource editor by Ctrl+Click on the class name.

image127 image127

Domain Diagram Editor

The domain diagram editor allows you to create new models based on your meta-model.

New Domain Diagram

You can create a new class diagram via context menu in the project explorer or File/New.

image128 image128

Preselecting a package will directly fill in the resource path and package in the wizard.

image129 image129

  • Name The name of the domain diagram.
  • Diagram Type Every domain uses its own diagram styles. The DiagramType lets you define your domain-specific domain diagrams (see Chapter 6 Domain Diagram Type).
    If there is no diagram type defined, the diagram editor has a default behavior and shows resources and their relationships (use and own relation, dependencies).

image130 image130

As a very simple example, let us define a diagram type for a state machine meta-model.

image131 image131

As the root class (see also Single Root) we choose Statemachine. This means that we can only edit elements that are part of the state machine.

The allowed class is State since we like to edit states. Between states there are transitions. A Transition is an indirect relation from State via Transition to State.

image132 image132

The minimal diagram type shown above leads to a domain specific state event diagram.

image133 image133

  • SingleRoot If there is a single root defined, every resource is created in the context of the single root. If no single root is defined, resources are created in the same package as the domain diagram.
Info

Note that defining a rootClass in the DiagramType demands for a singleRoot in the domain diagram.

New Domain Diagram for Resource

image134 image134

You can create a new domain diagram for a single root directly by calling New/Domain Diagram on a resource.

image135 image135

Info

Note that the single root is preselected in the wizard and the diagram type is automatically detected if there is a diagram type which has a root class of the same type as the chosen single root.

Palette

Use the palette to edit the domain diagram.

image136 image136

  • Select Selects one or many classes from the diagram. Use Ctrl+Click for multi select.
  • Edit Edits figures with a FigureEditableLabelSelector.
Info

Note that you can also enter the edit mode with the Select tool. Click on the text to alter – wait for one second until the cursor changes to text mode – and click again.

  • Marquee Selects classes from the diagram within a rectangle.
  • Relation Inserts a relation from a resource to another.
  • Resources Inserts a new resource on the diagram and in the model.
Info

Note that you control the palette by AllowedClass.paletteEntry in your diagram type. image137 image137

  • Search Searches allowed classes with a defined search path.\

Drag and Drop

Use the drag and drop feature from the project explorer to add an existing resource to your diagram.

image138 image138

Context Menu

image139 image139

  • Delete from Model Deletes this resource from the diagram and from the model. Use Shift+Delete on the keyboard to delete selected resources from the diagram and from the model.

  • Hide Resource Deletes this resource from the diagram but not from the model. Use Delete on the keyboard to hide selected resources from the diagram.

  • Show Resource Shows any hidden resource in the scope of the selected resource. If this action is called on the background of the diagram, the scope is your single root.

  • Show/Hide Resource Part Shows or hides aggregated parts (see Chapter 4.4.5 Composition).

    image140 image140

    image141 image141

  • Router Selects between different routing algorithms.\

    Router Description Image
    Default Manual routing by dragging image142 image142
    Manhatten Lines are routed with 90° image143 image143
    NoIntersection As few intersections as image144 image144

Browse Resource

Open any class in the resource editor by Ctrl+Click on the class name.

image145 image145

Browse Diagram

Actifsource automatically detects resources that are also shown on other diagrams. Simply click on the diagram symbol to list and browse the other diagrams.

image146 image146

Domain Diagram Type

Overview

Domain diagrams are domain-specific by definition. This means that you can define your own domain-specific diagrams.

Shape

Figure

Build Config

Overview

The Actifsource BuildConfig acts like a make file. It tells Actifsource which build tasks shall be executed. The most important build task for code generation is the TemplateGeneratorTask.

New BuildConfig

You can create a new build configuration via context menu in the project explorer or File/New.

image147 image147

Actifsource suggests adding templates to the build configuration which are not assigned to any other build configuration yet.

image148 image148

For every selected template, Actifsource creates a so called a TemplateGeneratorTask as shown below.

image149 image149

BuildConfig and TargetFolder

Build configurations have to be registered with target folders to take any effect (see also Chapter 2.5.3 Target Folder and Chapter 2.6 Project Properties).

image150 image150

Output Encoding

For every build configuration you may select the output encoding.

image151 image151

If no output encoding has been set, the one from the parent build configuration (see also Chapter 7.6.2 NestedBuildConfigGeneratorTask), folder, parent folder, project, or workspace is taken (in this order).

Check Properties/Resource/Text file encoding on folder or project.

image152 image152

Check Window/Preferences/General/Workspace/Text file encoding on workspace.

image153 image153

Line Break

For every build configuration you may select the line break style.

image154 image154

If no line break has been set, the one from the parent build configuration (see also Chapter 7.6.2 NestedBuildConfigGeneratorTask), project, or workspace is taken.

image155 image155

BuildTask

The build configuration lists all build tasks. Build tasks are executed in the order as listed. There are different types of build tasks. The most important one is the TemplateGeneratorTask.

Template Generator Task

The template generator task defines which templates have to be built.

image156 image156

  • Template References the template.

  • Omit File Id Actifsource normally inserts an id at the end of every generated file. This file id helps identify and track generated code.

    image157 image157

    The Actifsource ID is assembled as follows.
    /* Actifsource ID=\[TemplateGUID,SuperContextGUID\*,BaseContextGUID,MD5Hash\] */

    Element Descriptiom
    Comment Tags The comment tags (i.e. /* */) are given by the language
    Actifsource ID Static identifier
    TemplateGUID GUID of the template which created this file
    SuperContextGUID GUID of the resources which contains the base resource
    BaseContextGUID GUID of the base resources of this file
    MD5Hash A hash code over the generated code but not including protected regions to detect if the generated code has been changed manually. To ignore white spaces when building the MD5 hash check Chapter 2.5.3 Target Folder.
Info

Note that you can open the resource for any GUID in an Eclipse text editor or in the Eclipse console by Ctrl+Click on the GUID.

image158 image158

NestedBuildConfigGeneratorTask

The nested build configurator task let you reference and execute existing build configurations.

image159 image159

  • Build Config References any existing build configuration.
  • Target Sub Path Defines a sub path to the target folder (see also Chapter 2.5.3 Target Folder).

CopyTask

Copies a file or a folder to a specified target path. Please note that this tasks needs a built-in dependency to WORKSPACE (see Chapter 2.5.6 Built-in Dependencies).

image160 image160

  • Resource The file or folder to copy. There are different resource types.\
Resource Type Description
BundleResource File or folders found in a bundle (plugin project).
OutputScopeResource File or folders found in the target folder.
TemplateScopeResource File or folders found in the template folder.
WorkspaceResource File or folders found in the workspace.
  • Recursive All subfolders are copied if set to true.
  • Merge Duplicate Folders When enabled, the generator allows merging content from different folders into one folder. Otherwise an error will occur.
  • Target The target to copy the files or folders. There are different target types.\
Target Type Description
ResourcePathTarget Target path relative to copied resources.
ZipTarget File and folders are copied into a zip file.

DeleteFolderTask

Deletes the specified folders relative to the target folder. Please note that this tasks needs a built-in dependency to WORKSPACE (see Chapter 2.5.6 Built-in Dependencies).

image161 image161

  • Path A path relative to the target folder.

ExecuteProcessBuildTask

Executes any process on your operating system. Please note that this tasks needs a built-in dependency to WORKSPACE (see also Chapter 2.5.6 Built-in Dependencies).

To execute a shell command on windows, choose cmd as shell command, /c as first argument, and your shell command and parameters as subsequent arguments.

image162 image162

  • Directory Directory to execute the process relative to the target project.
  • Command The command (without arguments) to execute.
  • Argument The arguments of the command.

GraphvizBuiltTask

Runs the graphviz dot command on all .dot files in the target folder. Please note that this tasks needs a built-in dependency to GRAPHVIZ (see also Chapter 2.5.6 Built-in Dependencies).

Make sure that you have graphviz installed (see www.graphviz.org) and reachable in your path.

image163 image163

  • Styleheet A css stylesheet if needed.

  • Adapt Size If set to true, the generated diagram's width is set to 100%.

Eclipse Builder

Eclipse supports so called Builders to build anything. In C/C++ there is the CDT Builder to build executables and libraries from header and source files. In Java there is the Java Builder to build .class files from .java files.

In Actifsource there is the Actifsource Builder to generate code from the model (.asr files).

Make sure that the builders are arranged in the correct order. You will find the settings in Project/Properties/Builder.

image164 image164

Template Editor

Overview

As already seen in Chapter 1.1 Working with models, the Actifsource Template Editor allows you to write meta-code based on the meta-model. Writing meta-code means to write code along the structures which are given by the meta-model without knowing the specific domain model.

image165 image165

New Template

A template is either based on a type (Class, Enum) or not.

Template Type Description
Based on types Based on a type means that the Template is applied for every instance of that type. The result is one file per instance.
Build once Build once means that the Template is applied exactly once. The result is one file.

Create a template based on type

Creating a template based on a specific type (Class) is the normal case. Consider a nested Parent-Child structure with the following meta-model.

image166 image166

For every specific parent-child structure there is at least a resource of type Parent to start with. So let’s start writing meta-code based on the class Parent

To create a template based on the class Parent simply choose New/Template from the context menu of the class Parent

image167 image167

The New Template Wizard helps to configure the template settings.

image168 image168

Set the options as needed.

Option Description
Resource Path The resource path where the template is located (see Chapter 18 resource-paths) Resource Paths). This option is automatically filled in.
Package The package where the template is located. The package is derived from the location where the context menu was called.
Template Name The name of the template. The template name is automatically derived from the Base Type.
BuildConfig The build configuration where this template is referenced (see Chapter 7 Build Config).
MetaModel Make sure to choose Actifsource unless you know exactly what you do.
Base Type The base type is derived from the location where the context menu was called.

Please note that there is a short way for choosing the package. Just type the first few letters of a package followed by a dot. Using content assist (Ctrl+Space) shows the matching packages.

image169 image169

Creating a template based on a type (i.e. class Parent opens an editor with a predefined selector Build.allParent. This means that this template is executed for all resources of type Parent

image170 image170

Create a Build.once Template

To create a Build.once template simply choose New/Template from the context menu of a package. Please note that the template is created in the chosen package.

image171 image171

The New Template Wizard asks for the template name and even allows you to add a base type afterwards using the content assist (Ctrl+Space). Adding a base type leads to a template based on a type (see Chapter 8.2.1 Create a template based on type).

image172 image172

Creating a Build.once template opens an editor with a predefined selector Build.once@BuiltIn. That means that this template is executed only once.

image173 image173

Writing template code

Writing template code is nearly as easy as writing common code – thanks to the Actifsource Template Editor.

Base Context

The Actifsource Template Editor lets you write code in the context of the meta-model.

image174 image174

The orange bar on the left is the context you are in. Creating a template for the class Parent lets you work in the context of this class.

The context derived from the base type (see Chapter 8.2.1 Create a template based on type) is called base context.

File Line

First of all you have to specify a proper name. Since we want to generate a file for any instance of the class Parent, we have to specify a file name that is unique for every Parent instance.

image175 image175

The name of the generated files is derived from the specific resource instance for which code is generated. Use content assist (Ctrl+Space) to access the properties of the class which is bound to the base context by the Selector.

image176 image176

The following file name will create files named Parent.name while Parent.name is replaced by the name of the specific instance of class Parent Text elements referring to the model are called links and displayed underlined.

Please note that the file extension .hpp automatically selects the Language C++ (see Chapter 8.3.3 Language Line and Chapter 8.4 Declaring a Programming Language).

image177 image177

It is also possible to define a folder structure in the file line. The generated files will be placed in the defined folders.

image178 image178

Language Line

The language line defines the programming language for

  • Syntax Highlighting
  • Comment Style
  • String Style including escape rules

Actifsource defines the most common languages. If you are using a language which is not defined by default (see Chapter 8.4.1 Supported Programming Languages), do not hesitate to create one by your own (see Chapter 8.4 Declaring a Programming Language).

You may change the language at any time by using the content assist (Ctrl+Space) on the language line.

image179 image179

Selecting or changing a file extension in the file line (see Chapter 8.3.2 File Line) automatically selects the corresponding language.

image180 image180

Use Ctrl+Click on the language to show the underlying language model (see Chapter 8.4 Declaring a Programming Language).

image181 image181

File Tab

There are always situations where two or more files belong to each other (i.e. hpp/cpp in C++). Actifsource therefore supports file tabs.

Just press the [+] button right next to the file tabs to add a new file tab.

Info

Note that files tabs are always automatically named the same as the file extension.

image182 image182

Press the X button to delete the active file tab.

image183 image183

Press Ctrl+Tab to select next tab from within the code section.

SuperContext

Let’s assume that we want to generate a file for every Child instance.

image184 image184

For that reason we create a template with Child as base type.

image185 image185

Since Child is owned by Parent.child, Actifsource automatically provides you with a super context of type Parent

image186 image186

Please note that the base context (i.e. Child in this example) is the widest bar ( image187 image187 ).

image188 image188

Writing Code

Let’s start writing code. First we write a C++ class named Parent.name while Parent.name is replaced by the name of the specific instance of class Parent

Info

Note that the keyword class is bold and has a special color as defined in the language C++ (see Chapter 8.4 Declaring a Programming Language).

To insert a reference to the meta-model just use content assist (Ctrl+Space) at any time.

image189 image189

Underlined words are so called links which are directly linked with your model.

Info

Note that renaming resources in the meta-model automatically renames all links in the template synchronously.

image190 image190

You can always navigate to the corresponding resource in the model by using Ctrl+Click on the links as shown below or the image191 image191 tool from the toolbar.

image192 image192

Saving the above template leads to one file for every resource of type Parent in your project.

image193 image193

A build config is needed to work with resources from other projects (see Chapter 7 Build Config).

Using type names in the template code

Please note that you might insert type names directly in the template code by using the content assist (Ctrl+Space). If the desired type name is not available, press Ctrl+Space again to get all available type names.

image194 image194

The type name is inserted just as given. The advantage of using type names in the template is the automatic renaming if the name of the type is changed.

image195 image195

You can always open a resource link in the template editor.

image196 image196

  • Open Link with Default Editor Use one of the following methods to open a link in the default editor (see Chapter 2.11.2 Open with).
Action Opens Description
Ctrl+Click Default Editor Press Ctrl+Click on the link to open the resource
F3 Default Editor Press F3 on the current cursor position to open the resource
image197 image197 Default Editor Click Open Link in ResourceEditor from toolbar on the current cursor position to open the resource \

To open a function link in the function editor use the default editor. To open the function model use the resource editor (see below).

  • Open Link with Resource Editor Use one of the following methods to open a link in the resource editor (see Chapter 2.11.2 Open with).
Action Opens Description
Ctrl+Alt+Click Resource Editor Press Ctrl+Click on the link to open the Editor resource
Alt+F3 Resource Editor Press F3 on the current cursor position to open Editor the resource
image191 image191 Resource Editor Click Open Link in ResourceEditor from the toolbar on the current cursor position to open the resource

Line Context, Column Context, Protected Context

Actifsource knows three different types of contexts.

  • Line Context The line context consists of one or more lines in a file. The text in the line context is repeated for any resource reached by the selector (see chapter 8.3.10 Working with Context). To insert a line context use the Insert LineContext tool image198 image198 from the toolbar or press Alt+Insert. image199 image199
  • Column Context The column context consists of one or more columns of a line. The text in the column context is repeated for any resource reached by the selector (see Chapter 8.3.10 Working with Context). To insert a column context use the Insert ColumnContext tool image200 image200 from the toolbar or press Alt+Shift+Insert.
    image201 image201
  • Protected Context The protected context allows inserting so called protected regions into the generated files.
    image202 image202

The content of the Protected Regions is saved before regenerating and inserted in the newly generated file. Use Protected Regions to insert handwritten code into generated files.

Info

Note that Protected Regions are identified by the GUID of the resource of the current context. Use Ctrl+Click on the GUID to navigate to the corresponding resource.

image203 image203

The protected context consists of one or more lines in a file. The text in the protected context is repeated for any resource reached by the selector (see Chapter 8.3.10 Working with Context) and generated. To insert a protected context use the Insert ProtectedContext tool image204 image204 from the toolbar.

image205 image205

Info

Note that you can control the GUIDs that identify the protected regions by checking the resources in the context path. Just make sure that the resulting set of GUIDs is unique in your generated file. You might also define a name for the Protected Region.

image206 image206

Please note that changing the name of the Protected Region or the involved resources leads to new Protected Regions while the old once are moved to the end of the file.

Working with Contexts

Adding and removing a context is one of the most important operations when working with the Template Editor.

Use the Template Editor Toolbar to add, remove or navigate contexts.

image207 image207

Context Operation Icon Shortcut Description
Select TopContext image208 image208 Alt+Home Selects the top context
Select image209 image209 Alt+PgUp Selects the parent context from the actual context
Select image210 image210 Alt+PgDown Selects the child context from the actual context
Select image211 image211 Alt+End Selects the bottom context
Insert LineContext image198 image198 Alt+Insert Inserts a line context in the actual context
Insert image200 image200 Alt+Shift+Insert Inserts a column context in the actual context
Insert image204 image204 Inserts a protected context in the actual contextt
Delete Context image212 image212 Alt+Delete Delete the actual context
  • Navigate Context via Select Tools Using the Context Select Tools in the Toolbar you might change the selection of the context from parent to child and vice versa.
    image213 image213

  • Navigate Context via Breadcrumb A context can be selected by clicking on the Breadcrumb.
    image214 image214

  • Navigate Context via Context Bar A context can also be selected by clicking on the context bar.
    image215 image215

  • Add Context A new context is always added after the actually selected context. Navigate to a certain context before inserting a new context as shown above.
    Let’s assume that we want create a function identifyChild.name for every child in the parent context. For that reason we insert a new context using the Insert LineContext tool image198 image198 from the toolbar.
    image216 image216

As a second step you have to declare a selector (see Chapter 8.3.12 Selector) to define the context.

Since our base context is Parent we have to traverse the relation Parent.child to reach all children from parent.

image217 image217

Choose the relation Parent.child for the selector using content assist (Ctrl+Space).

image218 image218

Using content assist in the new context you are now able to use links on resources of type Child

image219 image219

To complete the task from above insert a function named identifyChild.name

image220 image220

Line 4 is now repeated for any resource of type Child reached by the relation Parent.child

image221 image221

  • Add Context via Quick-Assist Using the quick assist is the most efficient way to add a new context.

To create a new context with the selector Parent.child just insert the link Parent.child using context assist (Ctrl+Space). A light bulb image222?classes=inline image222?classes=inline indicates that there is a quick assist available. Click on the light bulb or press Ctrl+1 to open the quick assist.

image223 image223

You are now allowed to create a line context or a column context directly with Parent.child as the selector.

image224 image224

A new context is inserted with the desired selector. Parent.child is automatically replaced by Child which is the result of the selector. image225 image225

  • Automatic Context growth Adding new lines (pressing return) automatically lets the context grow.

image226 image226

  • Add Content between existing Contexts

Consider two contexts that follow each other (line 4 and 5 in the following example). How to insert new content between line 4 and line but in the base context?

image227 image227

Place the cursor on the end of line 4 as shown above and press cursor right. The cursor will still remain at the same position but the context selection will change to the parent context.

image228 image228

Entering a new line is done in the selected parent context and results in a new line between the existing contexts.

image229 image229

Copy/Paste

Copy (Ctrl+C) and Paste (Ctrl+V) in the Template Editor has some special features to work with links and contexts.

  • Copy/Paste with Link Links can be easily copied like text.

image230 image230

  • Copy/Paste with Context The Copy action takes care on all nested contexts in the current context. The following situation won’t copy the selected line context C on line 2 but the nested column context D

image231 image231

If you have to copy the line context C on line 2 just navigate to the base context (see Chapter 8.3.10 Working with Contexts) what makes the line context a nested context.

image232 image232

There is also a command Copy with Context in the context menu which allows to specify the position from which context are copied. The following situation shows a selection on line 2 where the copy operation allows to copy with context C or B

image233 image233

Please note that it makes no sense to copy the base context (see Chapter 8.3.1 Base Context) or even the super context (see Chapter 8.3.5 SuperContext) because they are part of the whole template.

Selector

The selector allows navigating the meta-model and is extremely powerful. Please consult Chapter 9.3.2 SelectorFunction for details.

Use the Switch to Selector tool from the tool bar or Alt+Enter to navigate from the code to the selector. Use Enter in the selector to jump back to the code.

image234 image234

  • Break Flag Consider the following situation:

image235 image235

The subsequent template iterates over Container.element and prints the name of every element.

image236 image236

Let’s assume that we write template code that shall produce different code depending whether Container.element is of type ElementA ElementB or ElementC

A straightforward solution is introducing a context with a type cast for type in the inheritance hierarchy.

image237 image237

The problem is that a resource type of ElementC is also of type ElementB and ElementA Therefore the above template prints lines 2, 3 and 4 for resources f type ElementC But the intention is that only line 2 is printed.

Use the break flag in the selector for the desired behavior. If the break flag is set all subsequent context of the same level are skipped. Users familiar with programming language C or C++ can think of the switch/case/break statement.

The following template prints line 2 for resource types of ElementC and then breaks the current iteration to continue with the next resource for Container.element

image238 image238

Info

Please note that a context with a break flag is displayed with a ground beam. image239 image239

Line Attributes

Use line attributes on a line context to control the output specific positions of a resource in a list. Place the cursor on the desired line to apply a line attribute.

image240 image240

There are five different types of line attributes which might be applied to a line context.

Context Operation Icon Shortcut Description
First image241 image241 Alt+1 The first element of the iteration
Not First image242 image242 Alt+2 All elements of the iteration except the first
Not Last image243 image243 Alt+3 All elements of the iteration except the last
Last image244 image244 Alt+4 The last element of the iteration
Empty image245 image245 Alt+5 For empty iterations

The following template prints the comment on line 7 only for the first element of the iteration over the list Parent.child Please note that line 7 is not printed if Parent.child is empty.

image246 image246

The following example prints a comment on line 8 if Parent.child is empty.

image247 image247

Column Attributes

Use column attributes on a column context to control the output specific positions of a resource in a list. Select the desired characters to apply a line attribute.

image248 image248

There are five different types of column attributes which might be applied to a column context.

Context Operation Icon Shortcut Description
First image249 image249 Alt+1 The first element of the iteration
Not First image250 image250 Alt+2 All elements of the iteration except the first
Not Last image251 image251 Alt+3 All elements of the iteration except the last
Last image252 image252 Alt+4 The last element of the iteration
Empty image253 image253 Alt+5 For empty iterations

The following example prints the comma after Param.name for all elements of the iteration except the last.

image254 image254

The next example prints void on line 7 if Parent.child is empty.

image255 image255

FunctionSpace

As shown in Chapter 9.2 Function Space the Template acts as a Functions Space. Therefore functions might be placed directly in the template (see Chapter 9 Functions for details).

image256 image256

Function calls are displayed in italic. In the subsequent example there is a call to Parent.className where className is the function.

image257 image257

To see the model of a function within a template just open the folding image258 image258 on the template.

image259 image259

If a function is placed in a function space other than the own template the function call is displayed with the name of the function space after the @ sign. Parent.className@MyFunctionSpace indicates a function call where the function className is located in the function space MyFunctionSpace

image260 image260

Extract Function

The Actifsource Template Editor allows you to extract selected expressions as functions. Please consider extracting complex expression if you use them more than once.

image261 image261

Selecting an expression which might also contain links leads to a image74 image74 light bulb on the left side which indicates that there is a Quick Assist available. Click on the light bulb or press Ctrl+1 to open the Quick Assist.

image262 image262

Context Path

The path from the outermost to the innermost context is called Context Path. Actifsource uses the Context Path to determine the parameters of a function (see Chapter 9.2.1 Function Parameters).

Consider the following meta-model:

image263 image263

The subsequent template shows nested contexts based on the above meta-model. Please note that the breadcrumb displays the context path for the actual cursor position.

image264 image264

The template shows the following context paths.

Line Context Path
ine 1 A
Line 2 A, B
Line 3 A, B, C
Line 4 A, B, C, D

Calling a function with parameters is only allowed if the context path is matching.

The following function fD C B A is based on Class D and declaring the parameters c of type C b of type B and a of type A

image265 image265

Calling fD C B A is only allowed if the context path contains at least A B C, and D in the given order.

image266 image266

Consider a function fD A which is based on Class D and declaring a parameter a of type A It is allowed to call this function on the context path A B C, and D because it contains A and D in the correct order.

image267 image267

Declaring a Programming Language

The Actifsource Template editor does syntax highlighting for keywords, comments, and strings. The actual selected language is determined by the Language Line (see Chapter 8.3.3 Language Line).

Supported Programming Languages

Currently Actifsource supports syntax highlighting for the following programming, script, markup, or domain languages.

Programming Language Description File Name Extension
Ada ada
C c, h
C# Microsoft C Sharp cs
C++ cpp, hpp
Cobol cob
Css Cascading Style Sheet css
D d
Delphi dfm
Eiffel e
Erlang erl, hrl
GraphViz www.graphviz.org dot
Groovy groovy
Haskell hs
Html Hyper Text Markup Language html, xtml
Java java
JavaScript js
Modula2 mod
Oberon pas
OmgIdl www.omg.org idl
Pascal pas
Perl pl
Php php
Python py
Ruby rb
Scala scala
Sql Structured Query Language for RDBMS sql
StructuredText see wikipedia st
Svg Scalable Vector Graphics svg
Text Plain text txt
VisualBasic Microsoft Visual Basic vb, vba
Xml Extensible Markup Language xml

TemplateLanguage Model

To create your own template language model just instantiate the class TemplateLanguage.

image268 image268

  • fileNameExtension The file name extension of the template language is used to automatically select the language line (see Chapter 8.3.3 Language Line) from the file extension in the file line (see Chapter 8.3.2 File Line).

  • keywordStyle A list of keywords including the syntax style (color, font modifier)
    image269 image269

  • stringStyle A declaration of start and end tag for strings including the syntax style (color, font modifier)
    image270 image270

  • singleLineComment A declaration of the start tag for single-line comments including the syntax style (color, font modifier)
    image271 image271

  • mutliLineComment A declaration of start and end tag for multi-line comments including the syntax style (color, font modifier)
    image272 image272

File Extension Priority Rules

You might define your own template language defining the same file name extension as a built-in language. Actifsource will handle user-defined template languages with higher priority so that you can overwrite the standard.

Functions

Table of Contents

Overview

Actifsource functions might be called from templates (see ChapterTemplate Editor), from other functions, or from selector relations (see Chapter 4.4.7 SelectorRelation). There are different supported types of functions (see Chapter 9.3 Function types).

Function Space

The function space is the resource where functions are living. We know two different types of functions spaces, both derived from AbstractFunctionSpace.

FunctionSpace is the place where you can place any function. Template is a code template where you can place functions in the scope of the template.

image256 image256

Functions are grouped by a FunctionContext. By the typeRef, the FunctionContext is bound to a Class or an Enum. Functions in the function context are applicable on instances of types referenced by typeRef.

image273 image273

Info

Note that Actifsource prohibits more than one function context with the same typeRef in the same function space.

Function Parameters

A function might define a set of parameters. If calling a function from a template, Actifsource automatically tries to match with the context path (see Chapter 8.3.17).

Function parameters are defined in the model of the specific function type (see Chapter 9.3 Function types).

image265 image265

Using function parameters in a template function (see Chapter 9.3.6 TemplateFunction) leads to the corresponding super contexts (see Chapter 8.3.5 SuperContext).

image274 image274

Using function parameters in a java function (see Chapter 9.3.3 SelectorFunction)

Selector functions allow you to navigate the model by using the selector syntax. Starting from a Class defined by FunctionContext.typeRef you may navigate via the resource properties.

Selectors might be used in Templates to select a context. But selectors might also be called from within selectors – even recursively.

  • Forward navigation Consider the following meta-model.

    image275 image275

    We like to define a selector function named getSubChild on Parent which returns all sub-children in all children of the parent. The return type when navigating along a property is given by the range of the property, i.e, in our example the expected return type is a list of elements of type SubChild To navigate from Parent via child to subChild just assemble a selector Parent.child.subChild Make sure to use content assist (Ctrl+Space) when writing selector functions.

image276 image276

This is what a selector function could look like.

image277 image277

  • Backward navigation Consider the following meta-model.

image275 image275

To get the Parent instance for a SubChild instance we have to navigate backwards via the subChild and child relation. The selector allows backward navigation via the minus relation.

image278 image278

  • List operators Actifsource provides you with the following operators which are defined on lists (where the lists are given by Selector expressions):\
Operator Description
A union B The result is the concatenation of the two lists A and B. For example, [a1,a2] union [a3,a1] is equal to [a1,a2,a3,a1].
A intersect B Only elements found in A and in B where duplicates are preserved and the resulting order is given by A. For example, [a1,a1,a2,a2] intersect [a2,a1,a1] is equal to [a1,a1,a2].
A except B For all elements b in B, the first occurrence of b in A is removed from A. For example, [a2,a1,a3,a2,a1] except [a1,a2,a1] is equal to [a3,a2]
A else B All elements in A if a is empty, otherwise all elements in B. For example, [a1, a2] else [b1,b2] is equal to [a1,a2] and [] else [b1,b2] is equal to [b1,b2].
A then B All element in B if A is not empty else empty list (i.e (A then B else C)).
A excludefilterA.c All elements from the set A with the exception of the elements for which A.c is evaluated to empty or boolean true.
A includefilterA.c where the expression A.c must be evaluated as not empty or Boolean true.
A getindexi Selects the element at position i ($i \in \mathbb{Z}_{0}^{+}$) from the list of elements of A. For example [a2,a1,a3,a2,a1] getindex 2 selects a3.
Info

Note that you can use brackets to control precedence (i.e. (A.x union A.y) intersect A.z). The result type of the union, intersect and else operator is the most concrete supertype of the type of the two operands (e.g. if A is of type NamedResource and B is of type Resource, then A intersect B A union B and A else B are all of type Resource). After brackets you can continue the selector (i.e (A.x union A.y).typeOf).

  • Down Cast Consider the following meta-model.
    image279 image279

If you only like to get Leaf components from the Client, just use the type cast operator (colon).

image280 image280

  • Up Cast It is always possible to use an upcast to a base class (i.e. Resource or NamedResource) if needed.

  • Self Cast If your selector has to return the typeRef instance itself, use the self-cast. Consider the following selector function for Component returning the component instance itself.

image281 image281

  • Recursive navigation The diagram below shows a composite pattern as presented in the book Design Patterns from Erich Gamma et al. The composite pattern allows you to recursively instantiate Composite instances, which might aggregate other components of type Leaf or again – of type Composite.

image282 image282

There is an easy way to find the Client of this recursive model using selectors. First, we collect all components including the own component and all parent components.

For that reason we write a selector function for Component which returns the component itself and also all parent components which are reachable by going backwards via the component relation.

image283 image283

To get the Client which is parent of all component just collect all component first by using the above selector functions. From all this components in the collected set there is only one instance aggregated by Client. Let’s write a selector function for that.

Please take extra care because there are two relations named component. One is Composite.component the other one is Client.component Make sure to use Composite.component in allComponent and Client.component in getClient

image284 image284

  • Calling selectors with parameters

[TBD]

JavaFunction

leads to the corresponding java function arguments.

image285 image285

Polymorphic calls

Function calls are polymorphic if a function has the same name, the same parameters and a typeRef to a sub class.

image286 image286

In the following example, the function identify is defined for MyClass and MySubClass. There will be a polymorphic call to MyClass.identify dependent on the type of the instance.

image287 image287

Non-Polymorphic calls

There are situations where polymorphic calls are not desired. You have to disable polymorphic calls on every caller. Use the context menu Change to non-virtual call on the function.

image288 image288

A small arrow indicates the non-polymorphic call.

image289 image289

Extends

Polymorphic calls are supported in the same function space by default. Extending another function space enables polymorphic calls over functions spaces.

image290 image290

Function types

Actifsource supports different types of functions.

image291 image291

Abstract Function

Abstract functions shall only be defined on types with an abstract modifier (see Chapter 4.6.1 ch.actifsource.core.Class).

For an abstract function, there must be non-abstract function for any non-abstract subclass in the same function space or in a function space that extends it.

image292 image292

SelectorFunction

Selector functions allow you to navigate the model by using the selector syntax. Starting from a Class defined by FunctionContext.typeRef you may navigate via the resource properties.

Selectors might be used in Templates to select a context. But selectors might also be called from within selectors – even recursively.

  • Forward navigation Consider the following meta-model.
    image275 image275

We like to define a selector function named getSubChild on Parent which returns all sub-children in all children of the parent. The return type when navigating along a property is given by the range of the property, i.e, in our example the expected return type is a list of elements of type SubChild

To navigate from Parent via child to subChild just assemble a selector Parent.child.subChild Make sure to use content assist (Ctrl+Space) when writing selector functions.

image276 image276

This is what a selector function could look like.

image277 image277

  • Backward navigation Consider the following meta-model.

image275 image275

To get the Parent instance for a SubChild instance we have to navigate backwards via the subChild and child relation. The selector allows backward navigation via the minus relation.

image278 image278

  • List operators Actifsource provides you with the following operators which are defined on lists (where the lists are given by Selector expressions):
Operator Description
A union B The result is the concatenation of the two lists A and B. For example, [a1,a2] union [a3,a1] is equal to [a1,a2,a3,a1].
A intersect B Only elements found in A and in B where duplicates are preserved and the resulting order is given by A. For example, [a1,a1,a2,a2] intersect [a2,a1,a1] is equal to [a1,a1,a2].
A except B For all elements b in B, the first occurrence of b in A is removed from A. For example, [a2,a1,a3,a2,a1] except [a1,a2,a1] is equal to [a3,a2]
A else B All elements in A if a is not empty, otherwise all elements in B. For example, [a1, a2] else [b1,b2] is equal to [a1,a2] and [] else [b1,b2] is equal to [b1,b2].
A then B All element in B if A is not empty else empty list (i.e (A then B else C)).
Info

Note that you can use brackets to control precedence (i.e. (A.x union A.y) intersect A.z). The result type of the union, intersect and else operator is the most concrete supertype of the type of the two operands (e.g. if A is of type NamedResource and B is of type Resource, then A intersect B A union B and A else B are all of type Resource).

  • Down Cast Consider the following meta-model.

image279 image279

If you only like to get Leaf components from the Client, just use the type cast operator (colon).

image280 image280

  • Up Cast It is always possible to use an upcast to a base class (i.e. Resource or NamedResource) if needed.

  • Self Cast If your selector has to return the typeRef instance itself, use the self-cast. Consider the following selector function for Component returning the component instance itself.

image281 image281

  • Recursive navigation The diagram below shows a composite pattern as presented in the book Design Patterns from Erich Gamma et al. The composite pattern allows you to recursively instantiate Composite instances, which might aggregate other components of type Leaf or again – of type Composite.

image282 image282

There is an easy way to find the Client of this recursive model using selectors. First, we collect all components including the own component and all parent components.

For that reason we write a selector function for Component which returns the component itself and also all parent components which are reachable by going backwards via the component relation. $

image283 image283

To get the Client which is parent of all component just collect all component first by using the above selector functions. From all this components in the collected set there is only one instance aggregate by Client. Let’s write a selector function for that.

Please take extra care because there are two relations named component. One is Composite.component the other one is Client.component Make sure to use Composite.component in allComponent and Client.component in getClient

image284 image284

  • Calling selectors with parameters

[TBD]

JavaFunction

Actifsource supports user-implemented Java functions that make use of the very powerful Javamodel to access the Actifsource models from Java code (see also Section 9.5).

image293 image293

When you declare a Java function, Actifsource automatically generates a function skeleton in a file with the same name as your function space found in the folder src-gen.

image294 image294

You should only modify generated files within protected regions (see Chapter 2.12.5 Protected Regions). Take extra care that import statements are placed within the protected regions – especially if inserted automatically by the Java content assist.

image295 image295

As function arguments, an instance of type FunctionContext.typeRef and all parameters are passed. Use the Java content assist (Ctrl+Space) to display available functions. To access properties choose myClass.selectMyProperty(). For more information on how to access the Javamodel see Chapter 9.5.

  • Return Types
    image296 image296

A Java function has a return type which is either a Type or a TypeReference.

A Type is either a SimpleType or a ListType. A SimpleType can, in particular, be a ClassType, which references any Class, or a LiteralType, which references any Literal. For a LiteralType the return type of the generated Java function is the Java class given by the return value of the method getValueType() of the ILiteralAspect (e.g. in the example above the LiteralAspect of StringLiterals (ch.actifsource.core.model.aspects.impl.String.StringLiteralAspect) defines that java.lang.String represents StringLiterals and, therefore, the the return type of identify is java.lang.String). A ListType references either a Class or a Literal (more precisely, it actually references an AbstractType). The return type of the generated Java function is then a java.util.List<Class>, where Class is the Java class that corresponds to the Literal or the Class. Note that in the latter case the Java class is the wrapper Java class that corresponds to the Actifsource Class and is provided by the Javamodel (see also Chapter 2 and Section 9.5).

A TypeReference is either a GenericContextType or a GenericContextListType. In the first case, the return type of the generated Java function is <T extends C T where C is the Java class corresponding to the type of the element the function is called on (the this-instance). In the second case, the return type of the generated Java function is a <T extends C> java.util.List<T> where T is defined as before (see examples below).

Info

Note that function with a return type of GenericContextType or a GenericContextListType can be applied to elements of any sub-type of the type given by typeRef of the FunctionContext, i.e., the this-parameter of the generated Java function is <T extends Class> T where Class is the Java wrapper class corresponding to the typeRef of the FunctionContext.

image297 image297

image298 image298

image299 image299

image300 image300

image301 image301

JavaListFunction

Java list functions can be applied to a list of elements defined by a Selector expression, e.g. in the Selector expression Parent.child.myFunction@ChildFunctionSpace the function myFunction is called on the list of all Children reachable from Parent via the relation child (see example in Section 9.3.2). The this-parameter of the generated Java function is then of type java.util.List<\> where C is the Java class corresponding to the typeRef of the FunctionContext (respectively java.util.List<T extends C> if the returnType of the Java list function is GenericContext(List)Type). Consider the following example that is based on the meta-model from Section 9.3.5:

image302 image302

image303 image303

The return types of JavaListFunctions are determined in the same way as for JavaFunctions (see Section 9.3.3). A list of built-in (Java) list functions is presented in Section Fehler! Verweisquelle konnte nicht gefunden werden..

Consider an extended meta-model where Parent can be referenced by a ParentContainer via a relation parent:

image304 image304

In this case, the selector ParentContainer.parent.child.myFunction@MyFunctionSpace constructs for each Parent the list of Children reachable from this Parent and then applies the function myFunction to each of these lists. If the function should be applied to the list of Children reachable indirectly via parent we can write a (Selector)Function that returns a list of all these Children e.g. ParentContainer.getAllChildren@MyFunctionSpace where getAllChildren is a SelectorFunction with the selector ParentContainer.parent.child In the selector ParentContainer.getAllChildren@MyFunctionSpace.myFunction@MyFunctionSpace the function myFunction is only called once on the list of all Children reachable from ParentContainer.

JavaAspectFunction

[TBD]

TemplateFunction

A template function behaves in the same way as a template, but there are no files generated from a template function. Just think of a template function as a sub template which can be expanded in a template or in another template function (also recursively).

Consider the following meta-model:

image305 image305

Let us now write a template function for a component which writes the name and type of the component and, if the given component is a composite, also does the same recursively for all subcomponents.

First of all we have to define the template function in the model.

image306 image306

To open the template function with the template editor, just double click in the Project Explorer. Use the Link with Editor tool (see Chapter 2.10.1 Link with Editor) to easily locate the template function in the project explorer.

image307 image307

In line 1 we write out the component name and its type name. In line 2 we iterate over all aggregated components, but only if the component is of type Composite (type cast). In this context we call the template function asText recursively for all aggregated component.

Info

Note the indention of two spaces on line 2. Actifsource takes care of the indentions so that the whole content of the template function is indented.

image308 image308

We can now call our template function from a template. If there is a call to a function from another function space, the function space is explicitly stated using the notation myFunction@MyFunctionSpace.

image309 image309

Next, we create an instance of type Client containing composites and leaves. The output from the above template might look as follows.

Info

Note that the indention is applied recursively.

image310 image310

TemplateLineFunction

The template line function behaves like a template but without the possibility to set contexts (see Chapter 8.3.9 Line Context, Column Context, Protected Context). The template line allows you to create simple single line texts as for name aspects (see Chapter 4.6.1 ch.actifsource.core.Class).

Consider a resource Person with two string literals firstName and LastName

image311 image311

Write a template function for person, which prints out the person's last name and first name.

image312 image312

Simply use the template line function as name aspect in the class Person.

image313 image313

Please not that it is also possible that the selector of the name aspect can be used directly as template line.

image314 image314

Info

Note that Person is only a Resource but not a NamedResource. The attributes firstName and lastName are therefore just normal properties.

image315 image315

Defining the name aspect as seen above synthesizes the name.

image316 image316

Built-in functions

Actifsource provides lots of useful built-in functions.

Built-in functions on Any

Actifsource provides the following built-in functions on Any.

Function Return type Description
guid Literal Gets the unique identifier of any Resource or Literal. (For Resources it is a GUID, for Literals it is the Literal itself.)

Built-in functions on Any List

Actifsource provides the following built-in functions on List of Any.

Function Return type Description
count IntegerLiteral Counts the number of elements in the list
isEmpty BooleanLiteral Returns true if and only if the list is empty.
isSet BooleanLiteral Returns true if and only if the list contains no duplicates.
first T Returns the first element in the list.
last T Returns the last element in the list.
count IntegerLiteral Counts the number of elements in the list.
reverse List of T Reverses the elements in the list.
distinct List of T Remove duplicates from a list, first to last.

Built-in functions on Resource

Actifsource provides the following built-in functions on Resource.

Function Return type Description
package String Returns the package of the resource as string.
guid String Returns the GUID of the resource as string.
simpleName String Returns the Resource’s name as defined by its NameAspect. If the resource extends NamedResource, the NameAspect returns the value of the name attribute. If no NameAspect is defined, the GUID of the resource is returned.

Built-in functions on List of Resource

Actifsource provides the following built-in functions on List of Resource.

Function Return type Description
sortByGuid List of T Sorts the list of resources by their GUIDs.
sortBySimpleName List of T Sorts the list of resources by their names.

Built-in functions on Literal

Actifsource provides the following built-in functions on Literal.

Function Return type Description
guid T Gets the identifier of the Literal value.

Built-in functions on IntegerLiteral

Actifsource provides the following built-in functions on IntegerLiteral.

Function Return type Description
increment Integer Increments an integer number.
decrement Integer Decrements an integer number.
notZero Integer Returns the number unless it is zero.

Built-in functions on IntegerLiteralList

Actifsource provides the following built-in functions on List of IntegerLiteral.

Function Return type Description
sum Integer Calculates the sum of a list of integer numbers.
minimum Integer Returns the minimum integer in a list.
maximum Integer Returns the maximum integer in a list.

Built-in functions on BooleanLiteral

Actifsource provides the following built-in functions on BooleanLiteral.

Function Return type Description
isFalse Boolean Returns true if the Boolean value is false.

Built-in functions on List of Character

Actifsource provides the following built-in functions on List of Character.

Function Return type Description
string Boolean Builds a string from characters.

Built-in functions on List of Letter

Actifsource provides the following built-in functions on List of Letter.

Function Return type Description
string Word Builds a word from letters.

Built-in functions on TextLiteral

Actifsource provides the following built-in functions on TextLiteral.

Function Return type Description
suppressIndent Text Sets the current intent mode to ‘suppress indent’: All lines after the first line start at the very beginning of the line. If applied in a template function, the setting of the outer template is not affected. The return value is the text itself.
indent Text Sets the indent mode to ‘indent’ (=default). All lines will start at the same position as the first line. (The preceding characters in the first line are copied, non-whitespace characters replaced by whitespaces.) If applied in a template function, the setting of the outer template is not affected. The return value is the text itself.
prefix Text Sets the indent mode to ‘prefix’. All lines will repeat the preceding characters in of the first line. If applied in a template function, the setting of the outer template is not affected. The return value is the text itself.
splitLines List<String> Splits text at line breaks into a list of strings.
split80 List<String> Splits text into a list of strings of maximum 80 characters. Words are considered atomic, if possible.
split100 List<String> Splits text into a list of strings of maximum 100 characters. Words are considered atomic, if possible.
escapedString String Escapes the text such that it can be embedded into C, C++ or Java source code. Escaping for C/C++ only works for ASCII characters.
notEmpty Text Returns the text unless it is empty.

Built-in functions on StringLiteral

Actifsource provides the following built-in functions on StringLiteral.

Function Return type Description
character List of Character Gets the characters in the string.
length Integer Gets the number of characters in the string.
toFirstUpper String Gets the same string with capital first letter.
toFirstLower String Gets the same string with small first letter.
toAllUpper String Gets the string in all capital letters.
toAllLower String Gets the string in all small letters.
camelcapToUnderscore String Inserts an underscore before every uppercase letter unless it is the first letter in the string.
whitespaceToCamelcap String Replaces letters behind one or many whitespace characters by their uppercase counterparts, replacing those whitespace
characters.
whitespaceToUnderscore String Replaces all whitespace characters by underscore characters.
split80 List of String Splits the string into a list of strings of maximally 80 characters.
split100 List of String Splits the string into a list of strings of maximally 100 characters.
packageToDirectory String Replaces '.' by '/'.
isNotEmpty Boolean Returns true if and only if the string is not an empty string.
escapedString String Escapes the string such that it can be embedded into C, C++ or Java source code. Escaping for C/C++ only works for ASCII characters.
part List of Literal Parses the string into words, natural numbers and special characters, removing whitespaces.

Built-in functions on Word

Actifsource provides the following built-in functions on Build.

Function Return type Description
character Letter Gets the letters in the word.

Built-in functions on Guid

Actifsource provides the following built-in functions on Build.

Function Return type Description
timestamp Long Returns the GUID's timestamp in nanoseconds starting from Oct 15, 1582.
time Time Returns the GUID's time.
identify Resource Returns the Resource identified by the GUID.

Built-in functions on Build

Actifsource provides the following built-in functions on Build.

Function Return type Description
once Build Used in the selector of the template. Build.once means a template is not based on a resource but only built once.

Built-in functions on LinkSelector

Actifsource provides the following built-in functions on LinkSelector.

Function Return type Description
selectorText String Converts a selector to simple text string.
selectorResultType AbstractType Calculates a selectors result type.

Built-in functions on File

Actifsource provides the following built-in functions on File.

Function Return type Description
contents Text Returns a file's contents.

Accessing the model from within Java function

It is possible to access the model, other functions (see chapter 9.3 Function types), or even built-in functions (see chapter Fehler! Verweisquelle konnte nicht gefunden werden. Fehler! Verweisquelle konnte nicht gefunden werden.) from within Java functions.

Consider the following meta-model for the subsequent examples:

image317 image317

Model forward access

Let’s write a Java Function for Parent which returns only instances of type Child with names beginning with “A”.

Start by declaring a Java Function named filterChild as seen in Chapter 9.3.3.

image318 image318

For the model forward access use the selectProperty() function on the given resource where property is the property to select.

The subsequent filter function iterates over the relation Parent.child in the for-Statement via parent.selectChild(). Then we check if Child.name starts with “A” via child.selectName(). If the condition is fulfilled we add the filtered child to the child list. At the end we return the child list with the filtered children.

image319 image319

You might use the filter function in the selector of a template or in any other function. The following template only prints children with names starting with “A”.

image320 image320

Model backward access

Using the selector syntax accessing the model backwards is quite easy (see chapter 9.3.2 SelectorFunction) by the minus sign. Accessing the model backwards is also possible in the Java code.

For the model backward access use the static function selectToMeProperty() on the class which defines the relation.

Since we want to access the relation Parent.child backwards we have to choose the static method Parent.selectToMeChild() providing the actual child as parameter. As a result we get the parent of the given child.

image321 image321

Function access

Use the extension mechanism to access any of your functions from within Java Code.

Info

Note that the extension mechanism also supports polymorphic calls (see chapter Fehler! Verweisquelle konnte nicht gefunden werden. Fehler! Verweisquelle konnte nicht gefunden werden.).

Let’s assume that we have a function filterChild as shown in chapter 9.5.1 Model forward access. Let’s write a Java function filterChildReverse which returns a reverse list of the filtered children based on filterChild.

For the function access use the extension() function on the given resource with FunctionSpace.ITypeRefFunctions.class as parameter. FunctionSpace is the function space where your function is defined. TypeRef is FunctionContext.typeRef. The static property .class is given from Java and represents a class as an object.

image322 image322

Built-in function access

Use the extension mechanism to access built-in functions on resources (see chapter 9.4.1 Built-in functions on Any

Actifsource provides the following built-in functions on Any.

Function Return type Description
guid Literal Gets the unique identifier of any Resource or Literal. (For Resources it is a GUID, for Literals it is the Literal itself.)

Built-in functions on Any List

Actifsource provides the following built-in functions on List of Any.

Function Return type Description
count IntegerLiteral Counts the number of elements in the list.
isEmpty BooleanLiteral Returns true if and only if the list is empty.
isSet BooleanLiteral Returns true if and only if the list contains no duplicates.
first T Returns the first element in the list.
last T Returns the last element in the list.
count IntegerLiteral Counts the number of elements in the list.
reverse List of T Reverses the elements in the list.
distinct List of T Remove duplicates from a list, first to last.

Built-in functions on Resource) from within Java Code. Accessing built-in functions is done the same way as seen in the above chapter 9.5.3 Function access.

To write a function which returns the package and the simpleName of a child we can reuse the built-in functions package() and simpleName() For the built-in function access use the extension() function on the given resource with BuiltinResourceFunctions.class as parameter.

image323 image323

Info

Note that you cannot access built-in functions for literals via the extension mechanism.

Code Snippets

Overview

Actifsource supports a special editor, the so-called Code Snippet editor, which allows the user to insert Actifsource resources as variables or functions into snippets of source code. Such a snippet of code is essentially a list of statements written in C-, where C- is a subset of the programming language ANSI C. A more precise definition of C- will be given below. Actifsource then provides the possibility to generate code in an arbitrary target language from these code snippets. This is achieved by parsing the input code according to the grammar of C- and applying either built-in or user-provided templates to the resulting parse tree. This parse tree is actually a model composed of temporary (i.e. non-persistent) resources. The following example shows a code snippet here the underlined identifiers are resources used as variables and functions:

image324 image324

Defining Code Snippet Relations

First, we will show how to add a code snippet relation to a class and define all the necessary properties of this relation. Such a relation enables the code snippet editor on instances of this class and allows a user to add code written in the chosen input language to the resource. Most of the examples and screenshots in the following are taken from the Code Snippet tutorial available at http://www.actifsource.com/tutorials/index.html. This tutorial is based on the following meta-model for statemachines and shows how to add code snippets for conditions on transitions and for actions taken when a condition is executed.

image325 image325

To add code snippets to resources of type MyClass, you have to edit MyClass in the resource editor, add a new property and choose the type StructuredCodeSnippetRelation for the relation in the Type Selection dialog:

image326 image326

In the resulting property, you have to create the following statements: subjectObjectCardinality, objectCardinality and name as for Own- or Association (see Section 4.3).

Additionally, we define the CodeSnippetRelationAspect as shown below with the class

ch.actifsource.codesnippet.metamodel.aspect.impl.StructuredCodeSnippetRelationAspect.

image327 image327

Language

Next, we choose an input language for the code snippet.

image328 image328

The input language is used to check the input code syntactically and to highlight keywords of the language. Furthermore, the input language defines which parser will be applied to the input code when generating output code from the code snippet. See Section 10.3 for a description of the available input languages.

Tokens

Finally, we need to define which resources will be available as functions and variables in the code snippet editor. This is done by creating one or more token statements referring to a RelationTokenProvider. The RelationTokenProvider allows the user to define a selector (cf. Section 8.3.12) which defines a list of resources. Additionally, it allows you to choose a tokenType which is either

  • ch.actifsource.codesnippet.metamodel.TokenType.Variable for variables or
  • ch.actifsource.codesnippet.metamodel.TokenType.Function for functions.

image329 image329

For variables you can define sub-tokens. The definition of sub-tokens instructs the Content Assist to propose all resources defined by the selector of the sub-token when you insert a '.' after a token. This means that sub-tokens can be used to insert resources as identifiers of fields in structs where the token corresponds to the struct and the sub-token to the field (for details see Section 0 below).

Input Languages

At the moment, the following languages are available: C-, CMinusCondition and Text.

C-

The language C- is a (proper) subset of the language ANSI C. It has the following restrictions:

  1. C- supports no declarations (of variables, functions or types)

  2. C- does not support the use of pointers and addresses

  3. C- does not support type casts

  4. C- does not support conditional statements (Expression ? Expression : Expression). However, they can easily be replaced by equivalent if-statements.

  5. The comma operators is not supported, i.e., expressions such as

    • X = 2, z = 42
    • Foo(x,(y=2,y)) are not valid.
  6. Postfix and prefix increment and decrement operators (++,--) are not supported.

C- supports access to fields of structs. As identifiers for fields either variables or arbitrary identifiers are valid. The Content Assist provides proposals for fields of structs if the variable definitions are created accordingly (see Section 10.4.1 ).

C- knows the following list of keywords: break, else, switch, return, continue, for, default, do, if, while, until, case.

Furthermore, the language knows the following operators:

  • Infix-Operators { ||,  &&|^&==!=<><=, >=<<>>, +-*,  /, %}
  • Prefix-Operators { !, ~, +, -}
  • Assignment-Operators {=, *=, /= , %=, +=, -= , <<= , >>= , &=, ^= , |=}

CminusCondition

A code snippet with CMinusCondition allows the user to input a conditional expression as in ANSI C (e.g. a relational or equality expression) while the same restrictions apply as for C- (details see Section 10.3.1). Such an expression can then be used for example as the condition in an if-statement.

Text

Text allows the user to insert arbitrary text with resources added as either variables or functions. This language should only be used if C- is too restrictive and validation of the input code is not required. The input code is syntactically not validated[^1] and the resulting parse tree is very simple:

image330 image330

Code Snippet Editor

The code snippet editor is available in the resource editor for any property of type StructuredCodeSnippetRelation. The editor supports multi-line input. It highlights keywords and comments according to the language property of the StructureCodeSnippetRelation. You can inspect the definition of the input language by CTRL+Left-Click on the chosen language:

image331 image331

This opens the chosen language in the resource editor and allows you to browse the properties such as keywords and style of comments of the language:

image332 image332

Content Assist

By using CTRL+Space in the code snippet editor you can as usual call the Content Assist. The Content Assist will show you all available resources to insert as functions and variables. The set of available resources is defined by the property token on the corresponding StructuredCodeSnippetRelation (see Section10.2). Inserted resources are underlined with blue color.

  • Structures The StructuredCodeSnippetRelation supports the definition of complex and nested data types such as structs by defining a set of subtokens for a token. After inserting an instance of a token into the code snippet editor followed by a '.' (struct field access in C-), the Content Assist will propose the list of all resources defined by the selectors of its sub-tokens.

Consider for example the following meta-model:

image333 image333

Furthermore, we consider a StructuredCodeSnippetRelation on class A with the following definition of tokens:

image334 image334

We can now create a resource a1 of type A and insert code into the code snippet editor. When calling the Content Assist after inserting b1 it proposes the list c1, c2 (available through the Selector B.c) and d1 (available through the Selector B.d). See first screenshot below.

Info

Note that it is also syntactically correct to insert arbitrary strings as identifiers for fields of structs. After inserting one or more such identifiers followed by a '.', the Content Assist will again propose the list of root elements (tokens) independently of possible resources before the string (see second screenshot below).

It is not possible to define structures recursively. Thus, you have to explicitly define the whole structure to the desired (finite) depth if it is self-referential.

image335 image335

image336 image336

Validation and Errors

The syntax of the input code in the code snippet editor is continuously validated. Syntax errors are shown by underlining the errors in the code and adding an error description to the Model Inconsistencies view:

image337 image337

Code Generation

In this section, we will show how to generate code in an arbitrary target language from code snippets. As explained in the introduction of this chapter, the input code of a code snippet is parsed by a parser that depends on the chosen input language (e.g. C- or Text). From the resulting parse tree, Actifsource generates a model that is composed of temporary resources. The meta-model for parse trees of the language C- is available at http://www.actifsource.com/manuals/index.html. The parse tree for unvalidated input (Text) can be found in Section 10.3.3.

To generate output files from these temporary models, we can apply code templates or template functions to these temporary resources, i.e., the temporary resources behave in exactly the same way as persistent resources except that they are not shown in the resource browser (Project Explorer) and are deleted when the session ends (e.g. the project or the workspace is closed). To use the content of code snippets in templates, you can either use the built-in TemplateFunctions (see Section 10.5.1) or write your own templates or template functions by modifying the built-in templates or writing them from scratch. The behavior of the built-in template functions can be customized by overwriting the way names of variables and functions are created (see Section Overwrite Variable and Function Names (Name Provider) below).

Built-in Template Functions

Actifsource provides the following built-in template functions which are defined on resources of type ch.actifsource.codesnippet.metamodel.element.CodeSnippet:

  • codeSnippetToST: generates Structured Text from a CodeSnippet with input language CMinus or CMinusCondition.
  • codeSnippetToC: generates C code from a CodeSnippet with input language CMinus or CMinusCondition.
  • codeSnippetToText: generates code from a CodeSnippet with input language Text (unvalidated code).
  • codeSnippetToFormattedC: generates formatted C code (HTML) from a CodeSnippet with input language CMinus or CMinusCondition (the actual code is the p)
  • codeSnippetToVHDL: generates VHDL code from a generates C code from a CodeSnippet with input language CMinus or CMinusCondition

For all the above template functions, the names of variables and functions in the output code are generated by calling the function simpleName@BuiltIn on the corresponding resource.

Info

Note that the above template functions which are written for input languages CMinus and CMinusCondition can also be applied to Text. The output is the same as when calling the function codeSnippetToText in this case.

Overwrite Variable and Function Names (Name Provider)

Generating the names of variables and functions by calling simpleName@BuiltIn, is in practice not always sufficient to generate code that meets all the requirements (the requirements on the naming could depend on naming conventions of the target language or names of variables could depend on the context in which the corresponding resource is used). For these cases, Actifsource provides more flexible template functions which takes a Literal of type ch.actifsource.codesnippet.metamodel.parsetree.template.NameProvider as an additional parameter:

  • codeSnippetToSTwithNameProvider

  • codeSnippetToCwithNameProvider

  • codeSnippetToText

  • codeSnippetToFormattedC

  • codeSnippetToVHDL

Apart from the generation of function and variable names, these templates have exactly the same behavior as the corresponding template functions from the section above.

The additional parameter to this functions can be used to store additional context information necessary to generate the names and to overwrite the functions used to generate the names, namely variableName@TokenToName and functionName@TokenToName. These two functions take a parameter of type Resource (the resource corresponding to the variable resp. function) and generate the name by calling NameProvider.variableName@TokenToName resp. NameProvider.functionName@TokenToName:

image338 image338

image339 image339

The Code Snippet tutorial available at http://www.actifsource.com/tutorials/index.html show how to implement a NameProvider by guiding you step-by-step through an example.

Implement a custom NameProvider

In general, one can implement and use a NameProvider as follows:

  1. Write a LiteralAspect (e.g. MyNameProviderLiteralAspect) in Java which implements ch.actifsource.core.model.aspects.impl.IGenericLiteralAspect<MyNameProviderLiteralAspect>. image340 image340

  2. Create your own resource of type Literal (e.g. MyNameProvider) which extends ch.actifsource.codesnippet.metamodel.parsetree.template.NameProvider: image341 image341

  3. Create a Java interface (e.g. IMyNameProvider) which provides the members needed to manage and store the context information needed by the NameProvider. image342 image342

  4. Create a FunctionSpace (e.g. MyNameFunctions) which extends TokenToName with a FunctionContext for the newly created Literal type (e.g. MyNameProvider). Create the two functions variableName and functionName with exactly the same signature as corresponding functions in the TokenToName.

    image343 image343

    image344 image344

  5. Write a JavaFunctions (e.g. createMyNameProvider) that generates an instance of the newly created Java interface (e.g. IMyNameProvider).

    image345 image345

  6. In the template where the function to<Language>withNameProvider is used, call the newly created JavaFunction (createMyNameProvider) and call to<Language>withNameProvider with the output of the JavaFunction.

image346 image346

Info

Note that the TemplateFunctions presented in Section 10.5.1 generate the names by internally calling the name functions variableName and functionName on ch.actifsource.codesnippet.metamodel.parsetree.template.NameProvider (the default NameProvider). Thus, overwriting these functions in a FunctionSpace that extends TokenToName for the type NameProvider (see example below) also changes the behavior of this TemplateFunctions without NameProvider (e.g. toC@CodeSnippetToCode). This can, in particular, change the behavior of already existing templates and template functions. Therefore, this approach should normally be avoided and a customized NameProvider implemented instead.

image346 image346

Display Code Snippets in Diagrams

Since the parse trees created from the input code of a code snippet are temporary resources, they are only visible for the code generator. To use the content of code snippets in diagrams, Actifsource provides template functions which allow you to display the code in diagrams:

  • displayCodeSnippet
  • displayCodeSnippetSingleLine

These TemplateFunctions show the unprocessed code as it is entered by the user in the code snippet editor. Both functions are defined on resources of type ch.actifsource.codesnippet.metamodel.element.CodeSnippet. An example application of these functions can be found in the Installing Actifsource](/tutorials/\20_enterprise/60_code-snippet) .

Java API

Select-Fassade

Select Functions for Property

Function Return type Description
rangeOrNull Class Returns a Property’s range.
→ownerOrNull Class Returns a Property’s domain.
isComposition boolean Check if a Property is an Composition.
isDecoratingRelation boolean Check if a Property is a DecoratingRelation.
isSubRelation boolean Checks if a Relation extends another Relation.
isComposition boolean Checks if a Relation is a Composition.
superRelations Set of Relation Returns the Relations a Relation extends.
subRelations Set of Relations Returns the that extend a Relation given Relation.
rootProperty Relation Returns the first Properties of the Set of Properties a Property extends, including itself.
rootRelation Relation Returns the first Relations of the Set of Relations a Relation extends, including itself.
possibleDecoratingTypes Map ? ?

Select Functions for Statement

Function Return type Description
existsStatement boolean ?
findNext Property Set Returns the successor Statement of a given Statement.
nameOf Attribute Set Returns the composed simpleName in the form (Subject, Predicate, Object).
statementPath List of Statement ?
decoratedNode Resource Returns the Resource that is decorated via this decorating Statement.

Select Functions for Class

Function Return type Description
instances Set of Resource Returns the direct or indirect instances of a Class.
directInstances Set of Resource Returns the direct instances of a Class.
instancesWithPackage Set of Resource Returns the direct or indirect instances of a Class in all Packages.
instancesWithMainPackage Set of Resource Returns the direct or indirect instances of a Class with their main Package.
isTypeOfFilter Filter on Resource Returns a Filter which includes Resources of a given Class.
resourceBySimpleNameOrNull Resource with Package Returns the Instance having a given simple Name.
resourcesBySimpleName Set of Resource with Package Returns the Instances having a given simple Name.
resourceByFullNameOrNull Resource with Package Returns the Instance having a given simple Name.
resourcesByFullName Set of Resource with Package Returns the Instances having a given simple Name.
allowedPropertiesOfType Set of Property Returns the (inherited or defined) Properties of a Class.
allowedPropertiesOfTypeForRead Set of Property Returns the (inherited or defined) Properties of a Class,including the overridden Properties.
allowedAttributesOfType Set of Attribute Returns the (inherited or defined) Attributes of a Class.
allowedAttributesOfTypeForRead Set of Attribute Returns the (inherited or defined) Attributes of a Class, including the overridden Attributes.
allowedRelationsOfType Set of Attribute Returns the (inherited or defined) Relations of a Class.
allowedRelationsOfTypeForRead Set of Attribute Returns the (inherited or defined) Relations of a Class, including overridden Relations.
isAbstractClass boolean Checks if a Class is abstract.
isFinalClass boolean Checks if a Class is final.
isSubclass Set of Type Checks if a Class extends another Class.
subclasses Set of Resource with Package Returns the Sub-Classes of a given Class.
superclasses Set of Resource with Package Returns the Super-Classes of a given Class.
matchingInstances Set of Type ?
isMatchingObjectFilter Filter on Resource ?
matchingSuperTypes Set of Type ?
matchingSubTypes Set of Type ?
isMatchingSuperType boolean ?
rangeToType Set of Type ?

Select Functions for Resource

Function Return type Description
exists boolean ?
packages Relation Set ?
mainPackage Relation Set ?
asPackagedResource Resource with Package Decorate a Resource by its main Package.
asPackagedResource Set of Resource with Package Decorate a Set of Resources by their main Packages. ?
namespace string Returns the name of the Packages and owning Resources, concatenated with dot.
simpleName string Returns the Name of a Resource defined by the NameAspect, or else the GUID.
hasName boolean Checks if a Resource has a Name, that is it has a NameAspect defined.
hasModifiableName boolean ERROR
fullName boolean Returns the Name, predeeded by Package Names and Name of the owner Resources.
isOwned boolean Checks if a Resource is directly or indirectly owned by another Resource, or it is the same Resource.
isRootResource boolean Checks if a Resource is not owned by any other Resource.
isAllowedPredicate boolean ?
rootResource Resource Returns the owner Resource that directly resides in a Package.
rootStatements Statement ?
directlyOwnedResources Set of Resource ?
ownStatementOrNull Statement Returns the Statement stating that a given Resource is owned by another Resource.
decoratedNode Resource Returns the Resource being decorated by this Decorator.
shallowType Type Returns the direct Type of a Resource.
isTypeOf boolean Check if a Resource is instance of a given Class.
toMeRelationsForType Relation ?
toMeTypes Set of Type ?
isMatching boolean ?
matchingTypes Set of Type ?
allowedProperties Property Set Returns the (inherited or defined) Properties of a Resource’s Class.
allowedPropertiesForRead Property Set Returns the (inherited or defined) Properties of a Resource’s Class,including overridden Properties.
allowedAttributes Attribute Set Returns the (inherited or defined) Attributes of a Resource’s Class.
allowedAttributesForRead Attribute Set Returns the (inherited or defined) Attributes of a Resource’s Class, including overridden Attributes.
allowedRelations Relation Set Returns the (inherited or defined) Relations of a Resource’s Class.
allowedRelationsForRead Relation Set Returns the (inherited or defined) Relations of a Resource’s Class, including overridden Relations.
allowedToMeRelations Relation Set Returns the Relations having a Resource’s Class as range.

Select Functions for Extendable

Function Return type Description
isAbstractExtendable boolean Checks if an Extendable is abstract.
isFinalExtendable boolean Checks if an Extendable is final.
extensions Set of Extendable Returns the extending Resources.
extendedResource Set of Extendable Returns the extended Resources.
isExtension boolean Check if a Resource extends another Resource.

Select Functions for (Resource, Property)

Function Return type Description
attributeStatementOrNull Statement ?
allowedPropertiesForRead Property Set Returns the (inherited or defined) Properties of a Resource’s Class, including overridden Properties.
allowedAttributes Attribute Set Returns the (inherited or defined) Attributes of a Resource’s Class.
allowedAttributesForRead Attribute Set Returns the (inherited or defined) Attributes of a Resource’s Class, including overridden Attributes.
allowedRelations Relation Set Returns the (inherited or defined) Relations of a Resource’s Class.
allowedRelationsForRead Relation Set Returns the (inherited or defined) Relations of a Resource’s Class, including overridden Relations.
allowedToMeRelations Relation Set Returns the Relations having a Resource’s Class as range.
objectsForAttribute List of Any Returns the Objects as result of the Evaluation of a given Attribute on a given Resource
objectForAttribute List of Any Returns the first Objects as result of the Evaluation of a given Attribute on a given Resource, or else a default.
objectForAttributeOrNull List of Any Returns the first Objects as result of the Evaluation of a given Attribute on a given Resource.
statementForAttributeOrNull List of Statements Returns the first Statement on a given Resource for a given Attribute.
objectForPropertyOrNull List of Objects Returns the first Objects as result of the Evaluation of a given Property on a given Resource.
objectMaxCard int Returns the maximum allowed count of Statement of a given Relation for a Resource in the Relation’s range.
objectMinCard int Returns the minimum allowed count of Statement of a given Relation for a Resource in the Relation’s range.
attributeMinCard int Returns the minimum allowed count of Statement of a given Attribute for a Resource in the Attribute’s domain.
attributeMaxCard int Returns the minimum allowed count of Statement of a given Attribute for a Resource in the Attribute’s domain.
subjectMinCard int Returns the minimum allowed count of Statement of a given Relation for a Resource in the Property’s domain.
subjectMaxCard int Returns the minimum allowed count of Statement of a given Relation for a Resource in the Property’s domain.
objectForAttributeOrNull List of Literal Returns the first Objects as result of the Evaluation of a given Attribute on a given Resource.
valueForAttributeOrNull string Returns the string value of the first Object as result of the Evaluation of a given Attribute on a given Resource.
valueForBooleanAttribute boolean Returns the string value of the first Object as result of the Evaluation of a given Attribute on a given Resource, or a default value.
objectForRelationOrNull List of Resource Returns the first Objects as result of the Evaluation of a given Relation on a given Resource.
objectsForRelation List of Resource Returns the Objects as result of the Evaluation of a given Relation on a given Resource.
objectsForRelationOfType List of Resource Returns the Objects as result of the Evaluation of a given Relation on a given Resource, having a given Type.
ownerOrNull Resource Returns a Resource’s owner Resource.
relationStatementOrNull Statement ?
statementOrNull Statement Returns the Statement with given Subject, Predicate and Object.
statement Set of Statement Returns the Statements with given Subject.
statementsForAttribute Set of Statement Returns the Statements with Subject and Predicate given by Resource and Attribute.
statementsForRelation Set of Statement Returns the Statements with Subject and Predicate given by Resource and Relation.
statementForRelationOrNull Set of Statement Returns the first Statement with Subject and Predicate given by Resource and Relation.
subjectForRelationOrNull Set of Object Returns the first Subject with Statement and Predicate given by Resource and Relation.
subjectsForRelation Set of Statement Returns the Subjects with Object and Predicate given by Resource and Relation.
toMeStatementForRelationOrNull Set of Statement Returns the first Statement with Object and Predicate given by Resource and Relation.
toMeStatementsForAttribute Set of Statement Returns the Statements with Object and Predicate given by Resource and Attribute.
toMeStatementsForRelation Set of Statement Returns the Statements with Object and Predicate given by Resource and Relation.
toMeStatements Set of Statement Returns the first Statement with given Object.
treeSelectObjects Set of Object Calculates the closure for given Resource and Relation. ??
topoSelectObjects Set of Object ?
treeSelectSubjects Set of Object ?
decoratableNodes Set of Resource ?

Select Functions for Package

Function Return type Description
allReferencedPackages Package ?
allStatements Set of Statement Returns all the Statements in a Package.
allRequiredScopes Set of Statement ?
allAvailableRequiredScopes Set of Resource Scope ?
resourceByNameOrNull Resource Returns the Resource in the Package having a given simple Name.

Select Functions for Resource Scope

Function Return type Description
getScope Resource Scope Returns the Scope.
isRequired Set of Resource Scope ?
allResourcesInScope Unordered Set of Resource Returns all Resources reachable from a given Resource Scope.
allReferencedResourcesInScope Unordered Set of Resource ?
classByName Java class Loads a Java class of given name.
classByNameOrNull Java class Loads a Java class of given name.
packagesInScope Set of Package ?
unreferencedResource Set of Resource with Package ?
types Set of Class Returns the direct and indirect Types of a Resource.

Additional Select Functions

Function Return type Description
getScope Resource Scope Returns the Scope.
getRequiredScopes Set of Resource Scope ?
allRequiredScopes Set of Resource Scope ?
allAvailableRequiredScopes Set of Resource Scope ?
isRequired Set of Resource Scope ?
allResources Unordered Set of Resource Returns all Resources in Scope.
allResourcesInPackage Unordered Set of Resource Unordered Set of Resource
allResourcesInPackage2 Unordered Set of Resource with Package Returns all Resources in a Package.
allResourcesInPackages2 Unordered Set of Resource with Package Returns all Resources in a List of Packages.
allRootResourcesInPackage Unordered Set of Resource Returns all Resources residing directly in a Package.
allStatements Set of Statement Returns all Statements.
resourceBySimpleNameOrNull Resource with Package Returns the Resource having a given simple Name.
resourcesBySimpleName Set of Resource with Package Returns the Resource having a given simple Name.
resourceByFullNameOrNull Resource with Package Returns the Resource having a given full Name.
resourcesByFullName Set of Resource with Package Returns the Resource having a given full Name.
packagesByName Set of Package Returns the Packages having a given Name.
subPackagesByName Set of Package Returns the Packages having a given Name, including the Sub-Packages.
packagesByExpressions Iterable of Package ?
allPackages Iterable of Package ?

Update-Fassade

Context Sensitive Help

Overview

In this section we will show how to set up the context sensitive help system. The Actifsource context sensitive help is integrated into the Eclipse Platform help system.

As a very simple example, let us define a help system for the following meta-model. This example allows to show help information about the Class A, B and BaseAB, and the respective instances A1 and B1.

First, we create the help file “ClassDocument.html” which contains all the help information and which defines the link targets for the context sensitive help.

image348 image348

image349 image349

Table of Contents

The table of contents (toc) contains a collection of topics for display inside the Eclipse help system. The topics here unlike in the context sensitive help are not bound to a context. For the detailed information on the supported features (Topics, Link and Anchor), see the Eclipse documentation

Now we create a HelpSystem resource in Actifsource: “ExampleHelpSystem”. Let us add a table of contents which has its contents statically defined as xml file: “StaticTableOfContents”. It has two properties:

  • primary: If true: The table of contents is displayed as a book within the Eclipse help.
  • file: The location of the toc xml file.

image350 image350

For editing the toc xml file, you can use the Eclipse specific editor, or edit it directly in an xml editor.

The toc xml file consist of a root xml element “toc” having an attribute “label” and containing nested “topic” elements. A “topic” element has the two xml attributes:

  • label: The label to display for the topic.
  • href: The location of the html File. The link providing anchors.

Now we create a toc file (TableOfContentsFile.xml) with the following topics and nested topics.

image351 image351

image352 image352

To open the Eclipse help system choose Help -> Help Contents. Select the ‘Actifsource Help Sample’ and expand the topics and you will see the following.

image353 image353

Help Context

Context sensitive help is a mechanism for linking a Resource to a specific help topic. For the detailed information on the supported features (Context, Topics and Commands), see the Eclipse documentation.

image354 image354

The information, which defines the different contexts and how they are linked to a topic, is stored in a help context xml file. When triggering the context sensitive help, the defined contexts are matched against the currently selected resource in the following order (most specific to least specific):

  • Matching of the instance by its GUID (instance match)
  • Matching of a resource by the GUID of its class (direct class match), and it super-classes (indirect class match).

You can edit the help context xml file directly or you using the Eclipse specific editor. A context xml entry has the two attributes:

  • id: The GUID of the Resource to associate the help.
  • merge: If true, also the topics of less specific contexts than this context are shown. If false, the topics of less specific context matches are omitted.

A topic entry in the xml file has the attributes:

  • label: The label displayed for the topic.
  • href: The location of the html file. The link providing anchors.

Now we create a help context file (HelpContextfile.xml) with the following contexts and topics.

image355 image355

image356 image356

The content sensitive help can be opened by selecting a Resource via any Actifsource editor and pressing ‘F1’.

All related topics started from the selected Resource (A1) via his types (from specific to generic type) are merged together. If only a single context matches the currently selected resource (setting the “merge” flag to false), then the html content is immediately shown inside the Eclipse help view.

image357 image357

Generic Export Wizard

Overview

In this section we will show how to export any build config to the file system. As a very simple example, let us define a generic template wizard to export the build config ‘TestBuildConfig’.

image372 image372

Generic Template Wizard

Property Description
name Defines the export wizard name.
version Defines the version from the export wizard.
publisher Defines the publisher from the export wizard.
description Defines the description inside the eclipse info page. Html tags are allowed.
info Defines the info inside the export wizard.
buildConfig Defines the build config to export.

You can start the export sequence via the context menu in the project explorer.

image373 image373

Select the generic export wizard to continue the export.

image374 image374

Select the Test-Generic-Template-Wizard to continue the export.

image375 image375

Preselecting a project scope and output folder inside the workspace or file system to complete the exporting sequence.

image376 image376

After importing any errors and infos are shown in the info-Page.

image377 image377

Code Generator

Overview

Click on GUID

Eclipse Builder

Working with GCC

VsCode

Manual Actifsource VsCode Extension coming soon.

Subsections of Tutorials

Workbench Community

Installing Actifsource

Learn how to install the Actifsource Plugin for Eclipse and how to activate your license. more…

Simple Service

Learn to design a generic domain, write code templates and generate code. more…

Complex Service

Develop complex templates with template interdependencies. Use Java Functions from within templates. more…

State Machine

Develop a fully typed state machine model. Learn about decorating relations and range restrictions to ease the use of the specific domain model. more…

Language

Enabling syntax highlighting for any programming language more…

Literal Aspect

Writing Java validation aspects for user defined literal types. more…

Refactoring

Writing an aspect for refactoring model instances based on meta model changes. more…

Built-in Models

Learn how to create an eclipse plugin containing an Actifsource builtin model. more…

JavaListFunction

Learn about JavaListFunctions. Create your own JavaListFunction to sort resources. more…

Subsections of Workbench Community

Installing Actifsource

logo-large

Tutorial Actifsource Tutorial – Installing Actifsource
Required Time - 10 Minutes
Prerequisites - Download and install Java
- Download and install Eclipse
Goal - Installing actifsource as a Eclipse Plugin
Topics covered - Install the actifsource Plugin
- Switch to the actifsource Perspective
Notation $\hookrightarrow$ To do
$\hookrightarrow$ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

Part I Preparation

  • Download Java from www.oracle.com.We recommend installing at least version 17. Alternatively, you can use OpenJDK.You can also skip this step if you optionally download the JRE via the Eclipse installer
  • Install Java on your desktop computer
  • Start by downloading Eclipse Installer from www.eclipse.org/downloads
  • Now go to File Explorer and click on Downloads after that click on the eclipse-inst-jre-win64.exe file for installing Eclipse IDE.
  • Select the installation version “Eclipse IDE for Eclipse Committers”

Part II Install the Actifsource Plugin

  • Actifsource is realized as an Eclipse Plugin

  • For more information about eclipse see also wikipedia (Eclipse (software))

    Install New Software Install New Software

  • From the menu Help select Install New Software...

    Install New Software.svg Install New Software.svg

  • Click Add...

  • Enter Name: actifsource

  • Enter Location: https://www.actifsource.com/updates or the given update site

  • Click OK

Install New Software Install New Software

  • Select actifsource
  • Click Next

Install New Software Install New Software

  • Click Next

Install New Software Install New Software

  • Carefully read the license agreement
  • If you agree, select I accept the terms of the license agreement
  • Click Finish

Install New Software Install New Software

  • Click Yes to restart Eclipse

Part III Switch to the Actifsource Perspective

Actifsource Perspective Actifsource Perspective

  • Click on the Open Perspective tool in the Eclipse toolbar
  • Click Other...

Actifsource Perspective Actifsource Perspective

  • Select the actifsource perspective
  • Click OK

actifsource-point-large

Simple Service

logo-large

Tutorial Actifsource Tutorial – Simple Service
Required Time • 70 Minutes
Prerequisites • Actifsource Tutorial – Installing Actifsource
Goal • Developing a generic domain model for a simple service infrastructure
• Instantiating specific domain objects according to the generic domain
• Writing code templates according to the generic domain
• Generate code for every specific domain object
Topics covered • Creating a new actifsource project
• Working with Diagram/Resource and Template Editor
• Generating Code
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. Other names appearing on the site may be trademarks of their respective owners.
Compatibility Created with actifsource Version 5.8.5

Overview

  • Create a new actifsource Project
  • Structure your models using Packages
  • Create Domain Classes in a Generic Domain Model for a Simple Service Infrastructure consisting of Services, Service-Calls, Arguments and Types:

overview-1 overview-1

  • Create a Specific Domain Model using your own domain-specific type system
  • Use Content Assist to create new domain-specific types or insert existing domain-objects

overview-2 overview-2


Part I: Create a new actifsource Project

  • Enable the actifsource perspective
  • Create and setup a new actifsource project “SimpleService”
  • Familiarize yourself with the basic structure of an actifsource project

Create a new actifsource Project

part1-1 part1-1

↪ Install Actifsource as a plugin from www.actifsource.com/
↪ Open the actifsource Perspective

part1-2 part1-2

↪ In the Open Perspective dialog click on Actifsource
↪ Click OK to confirm.

part1-3 part1-3

ⓘ Make sure the actifsource Perspective is activated


Create and Setup a new actifsource Project “SimpleService”

part1-4 part1-4

↪ Create a new actifsource Project

part1-5 part1-5

↪ Choose the project’s name com.actifsource.simpleservice
↪ Click Next

part1-6 part1-6

Info
  • In Actifsource, artifacts are called Resources
  • Resources are placed in folders and files
  • The default resource folder is called asrc

part1-7 part1-7

↪ Switch to the tab Target Folders
↪ Click Add Target Folder…

Info
  • Note: Generated Code is placed in target folders
  • Change project settings anytime using the project properties: Project/Properties/actifsource

part1-8 part1-8

part1-9 part1-9

↪ Add a target folder named src

part1-10 part1-10

Click Finish

part1-11 part1-11

Info
  • We have created a new actifsource Project named com.actifsource.simpleservice
  • Resource Folder asrc is where we place all actifsource Resources
  • Target Folder src is where the generated code is placed

Part II: Create a Generic Domain Model

  • Setup an appropriate package structure
  • Create a new diagram to model the generic domain model using generic classes and relations

Setup an Appropriate Package Structure

part2-1 part2-1

Info
  • In actifsource, Resources are organized within Packages

↪ Create a new Package in the resource folder asrc

part2-2 part2-2

↪ Name your package com.actifsource.simpleservice.generic as shown above
↪ Click Finish

Create a new Diagram to Model the Generic Domain Model

part2-3 part2-3

↪ Change the style for Package Presentation as you like

part2-4 part2-4

↪ Start with a Class Diagram of your generic domain model
↪ Create a new Class Diagram in the Package generic

part2-4 part2-4

↪ Name your Diagram ServiceDesign
↪ Click Finish


Add Generic Classes

part2-6 part2-6

Info
  • The Diagram ServiceDesign is opened in the Diagram Editor

↪ Insert the following Classes using the New Class Tool from the Palette: Service, Call, Parameter and Type


Add Generic Relations

part2-7 part2-7

↪ Specify the Relations between your Classes using the Relation Tool from the Palette on the right
↪ First, link Service and Call by clicking on Service and then on Call in the diagram


Composition Relations

part2-8 part2-8

Info
  • Actifsource distinguishes basically Composition, Aggregation and Association, all other relation types based upon them.
  • Composition and Aggregation resources live within the context of their owner
  • Association resources have their own lifetime and are referenced only
  • A Call is owned by Service because no Call must exist without its Service
  • Default name call is fine here

↪ Select the Composition

part2-9 part2-9

↪ Insert another Composition between Call and Parameter


Association Relations

part2-10 part2-10

Info
  • Type is used by Parameter because types have their own lifetime independent from referencing parameters

↪ Insert a Association between Parameter and Type

part2-11 part2-11

part2-12 part2-12

Info
  • Call should support a return type

↪ Insert a Association between Call and Type

part2-11 part2-11

part2-13 part2-13

↪ Name the relation returnType
↪ Choose SubjectCardinality 1..1 since we always want a return type in this example
↪ Click Ok


Adjust Cardinalities

part2-14 part2-14

Info
  • You can open the actifsource Resource Editor on any Actifsource resource by left-clicking on the desired resource while holding down the Ctrl-Key (Ctrl+ Left-Click)
  • Use the Cmd-Key on Apple computers

↪ Adjust the subjectCardinality of the call Relation

part2-15 part2-15

↪ Change the subjectCardinality from Cardinality0_N to Cardinality1_N
↪ Use Content Assist (Ctrl+Space) and select the desired Cardinality

part2-16 part2-16

↪ Make sure to change all marked cardinalities as shown above
↪ Choose subjectCardinality Cardinality1_1 for the relations type and returnType


Part III: Create a Specific Domain Model

  • Create a package to store specific classes
  • Create specific domain objects based on the generic domain model

Create a Package to Store Specific Domain Objects

part3-1 part3-1

↪ Create a new Package specific in simpleservice

Create Specific Domain Objects

part3-2 part3-2

↪ Select the Package specific
↪ Use the New Resource Tool to create a Resource of type Service

part3-3 part3-3

↪ Name the Service Patient
↪ Click Finish

Info
  • Being Subclass of NamedResource provides Patient with an Attribute name

part3-4 part3-4

Info
  • The Resource Patient of type Service has been created
  • The validator constantly checks all resources against the model
  • Since we decided a Service must have 1..N Call resources by selecting the subjectCardinality Cardinality1_N, the validator detects the incorrect subject cardinality and flags an error

part3-5 part3-5

↪ Use the context menu on the Relation call to explore your options
↪ Press Enter to create a Resource of type Call for the Patient Service

part3-6 part3-6

Info
  • The validator tells you that the created Call is missing a name and the returnType

part3-7 part3-7

↪ Enter the name Create by pressing enter on name or use the context menu
↪ Enter a new Parameter by pressing enter on parameter or use the context menu
↪ Enter the name LastName of the created Parameter

Info
  • Type and returnType are still missing

part3-18 part3-18

Info
  • So far there is no Resource of type Type
  • Type of Parameter LastName shall be String

↪ Activate Content Assist (Ctrl+Space) to insert a Resource of type Type
↪ Create a new Type String using Content Assist (Ctrl+Space)

part3-8 part3-8

↪ Name the new Type String
↪ Switch back to the Service Patient by clicking the Patient Tab or by pressing Alt+Left to navigate to the last edit location

part3-9 part3-9

Info
  • The created Type String is inserted automatically

part3-10 part3-10

↪ Select parameter
↪ Insert a new Parameter using Insert After (Ctrl+Enter) or Insert Before (Alt+Shift+Enter)

Info
  • You may rearrange the resources as you see fit using Move Up (Alt+Up) or Move Down (Alt+Down)

part3-11 part3-11

↪ Name the Parameter FirstName
↪ Insert the already created Type String using Content Assist (Ctrl+Space)

part3-12 part3-12

↪ For returnType create a new Type int using Content Assist (Ctrl+Space)

Info
  • The validator reports no more Model Inconsistencies

part3-13 part3-13

↪ Select call
↪ Insert a new Call using Insert After (Ctrl+Enter) or Insert Before (Alt+Shift+Enter)

Info
  • You may rearrange the resources using Move Up (Alt+Up) or Move Down (Alt+Down)

part3-14 part3-14

↪ Edit the Call Delete as shown above
↪ Insert Parameter Id of Type int
↪ Insert returnType boolean

part3-15 part3-15

Info
  • New resources are created in the same Package as they are referenced

↪ Create a new Package types in generic
↪ Move the Types boolean, int and String into the Package types using drag & drop

part3-16 part3-16

↪ Activate Link with Editor alt >< alt >< to link the Project Explorer with the editor

Info
  • Notice that types can still be located by Ctrl+Mouse-Left-Click on any type in the Resource Editor

Part IV: Use Code Templates to Generate Specific Code

  • Create a generator template
  • Enable Java functions for templates
  • Write generic code based on the generic domain model and generate code on the fly

Create a Generator Template

part4-1 part4-1

Info
  • Code Templates are also Resources in Actifsource
  • Like any Resource, a Template is located in a Package

↪ Create a new Package template in simpleservice

part4-2 part4-2

Info
  • Let’s write template code for any Service

↪ Select the Resource Service
↪ Choose New Template from the context menu

part4-3 part4-3

↪ Choose the Package template using Content Assist (Ctrl+Space)

Info
  • You might use just the first letters to select your packages

part4-4 part4-4

↪ Name the template ServiceImpl
↪ Click Finish


Write Generic Code Based on the Generic Domain Model

part4-5 part4-5

Info
  • Note: The Actifsource Template Editor is a text editor
  • Writing a template for Service means that any specific information on services comes from the specific domain model
  • The generic filename must contain a Variable to be unique for any specific Service

part4-6 part4-6

↪ Place the cursor on the Filename Line
↪ Use Content Assist (Ctrl+Space) to insert a Variable
↪ Choose the Resource Service

part4-7 part4-7

↪ Press ‘. ’ (dot) after Service
Content Assist opens automatically.
↪ Press Ctrl+Space to reopen Content Assist manually
↪ Select the Attribut name for Service

part4-8 part4-8

↪ Add the postfix Impl to the file name
↪ Add the language extension .java to the file name
↪ Save the file → a new file in your Target Folder src is created

Info
  • Note that syntax highlighting is automatically activated based on the file extension

part4-9 part4-9

Info
  • The orange bar on the left hand side is called main context
  • All text in the main context is generated for every specific Resource of type Service

↪ Write a Java Class as shown above. Make sure the class name contains the Variable Service.name
↪ Use Content Assist (Ctrl+Space) to insert the Variable
↪ Or use Copy/Paste (Ctrl+C/Ctrl+V) to copy the class name from file name
↪ Save the file (Ctrl+S) → Generated code can be found in the target folder src

part4-10 part4-10

Info
  • Let’s create a function for every Call in the Service

↪ Place the cursor in the class body
↪ Use the tool Insert Line Context (Alt+Insert) from the tool bar

part4-11 part4-11

Info
  • A new Line Context has been created
  • All text in the Sub Context shall be generated for every Resource of type Call in this Service

↪ Attach the Sub Context to the Parent Context using the Selector
↪ The given Selector must therefore navigate from Service to Call using Service.call
↪ Use Content Assist (Ctrl+Space) to specify the Selector
↪ Press Enter in the Selector to return to code

part4-12 part4-12

↪ Write a function in the Call Context as shown above

Info
  • The context grows as used
  • Save the file (Ctrl+S). The generated file should contain a class and its methods. Tip: Add another Service/Call.

part4-13 part4-13

Info
  • Let’s create a Java parameter for every Parameter in the Call

↪ Place cursor between the brackets
↪ Use the tool Insert Column Context (Alt+Shift+Insert) from the tool bar

part4-14 part4-14

↪ Write a parameter list in the Parameter Context as shown above
↪ Don’t forget the ‘, ’ (Comma) at the end
↪ Save the file (Ctrl+S). The generated file should contain a Java class , its methods and parameters

Info
  • Note that all text in the Parameter Context shall be generated
  • For that reason, there is a superfluous comma at the end of the last Parameter

part4-15 part4-15

Info
  • Single characters, but even lines, can be marked with Attributes
  • First (Alt+1) → Applied for the first iteration of the Context
  • Not First (Alt+2) → Applied for any iterations of the Context but the first
  • Not Last (Alt+3) → Applied for any iterations of the Context but the last
  • Last (Alt+4) → Applied for the last iteration of the Context
  • Empty (Alt+5) → Applied if Context is never iterated

part4-16 part4-16

Info
  • The comma has to be written after each Parameter except after the last one

↪ Select both the comma and the following space
↪ Choose Not Last (Alt+3) from the tool bar
↪ Save the file (Ctrl+S). The generated file should contain a class , its methods and parameters

Info
  • No superfluous comma is generated this time

part4-17 part4-17

Info
  • Let’s write specific code for the generated functions

↪ Place cursor in the function body
↪ Insert a Protected Context in the function body with the tool shown above

part4-18 part4-18

↪ Write any text in the Protected Context, e.g. a TODO comment

Info

Note that Call is translated in Call. Tip: Rename Call to ServiceCall to find out why this makes sense

↪ Write specific code within the Protected Regions of the generated files
Info

You must not delete the Tags Begin Protected Region and End Protected Region

Tip

Alter the template code. Save the template. See what happens with the Protected Regions


actifsource-point-large

Complex Service

logo-large

Tutorial Actifsource Tutorial – Complex Service
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Use Java Functions to reuse text fragments in your templates and capture complex expressions to keep your templates clean and easy to read

- Use Function Spaces to keep Java Functions organized
Topics covered - - Extracting Java Functions from template code
- Editing Java Functions
- Advanced Template Editor Context Operations
- Functions Spaces and Template Functions
- Built-in Java Functions
- Place generated code in specific folders
- Copy with Context
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial – Simple Service

  • Learn how to extract Java Functions from template code to cope with complex situations
    image2 image2

  • Edit Java Functions

  • Learn about advanced Context Operations in the Template Editor

  • Learn about Function Spaces and how to place functions

  • Use built-in functions
    image3 image3

  • Generate code for specific folders

  • Copy template code with its Context

Part I: Preparation

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial – Simple Service

    • Setup the Target Folder src

    • Create a Generic Domain Model

    • Create a Specific Domain Model

    • Create a Code Template

  • Use the following package structure

image4 image4

Create a Generic Domain Model

image5 image5

  • Create a Generic Domain Model in the DiagramEditor named ServiceDesign in the Package generic

  • The Design shall contain the following Domain Classes

    • Service, Call, Parameter, Type
  • Insert a Composition between

    • Service and Call

    • Call and Parameter

  • Insert a Association between

    • Call and Type

    • Parameter and Type

  • Adjust the Cardinalities as shown above

Warning: The layout for the relations transition and targetState might differ in your editor

Create a Specific Domain Model

image6 image6

  • Create a Service named Patient in the Package specific

  • Add the Calls Create and Delete

  • Add the Parameter LastName, FirstName and Id as shown above

  • Add the returnTypes as shown above

image7 image7

  • Create a Code Template named ServiceImpl in the Package template

  • Write code as shown above

  • The function shall be placed in the Context Call Selector is Service.call

  • The function parameters shall be placed in the Context Parameter; Selector is Call.parameter

  • Save the Code Template

image8 image8

  • You’ll find the generated code PatientImpl.java in the Target Folder src

Part II: Java Functions

  • Use Java Functions to

    • extract recurring text fragments from your templates

    • capture complex expressions to keep your templates clean and easy to read

  • Use Java Classes generated from your Generic Domain Model to write and maintain complex Java Functions

Extract Function

image9 image9

  • We should extract identical terms to honor the DRY principle (Don’t Repeat Yourself)
Info

Note that the term Service.name_Impl is used twice

image10 image10

  • In your template select the text you want to extract into a function
  • The light bulb at the left hand indicates Quick Assist is available

image2 image2

  • Activate QuickAssist by clicking the light bulb or by pressing Ctrl+1
  • Click Extract JavaFunction

image11 image11

  • Name the function className
  • Click Finish

Using Function

image12 image12

  • The new function className returns the extracted fragment from your template
  • The static function className is added to the static Java class ServiceImpl.ServiceFunctions in class ServiceImpl; this class is automatically generated by actifsource
  • The term Service.name_Impl has been replaced by the function Service.className
  • Java Functions are shown in italics in the actifsource Template Editor

image13 image13

  • Let’s replace the second occurrence of the term Service.name_Impl
  • Use Content Assist (Ctrl+Space) on Service to insert the function className for your class name

image14 image14

  • Open the underlying Function Model (Ctrl+Alt+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image15 image15

Editing Functions

image16 image16

  • Change function declaration here if needed
  • Please notice that the Function declaration was placed in the template

image17 image17

image14 image14

  • Open the underlying Java Function (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image19 image19

  • The class ServiceImpl is opened in the Java Editor showing your function className

image20 image20

Info

Note that actifsource generates a select method for each property of the corresponding class in the Generic Domain Model. You may use these methods to traverse your Generic Domain Model using the respective selectPROPERTY() methods in your Java Functions

image21 image21

  • Make sure to place additional imports within the corresponding Protected Regions
  • Please note that all code outside Protected Regions will be overwritten if the respective source file is re-generated.

Part III Function Spaces

  • Function Declarations are managed as actifsource Resources
  • All Function Declarations are placed in Functions Spaces
  • Templates are Functions Spaces by default
  • Functions Spaces can exist without Templates
  • Function Spaces are Resources and can therefore be placed in Packages

Advanced Context Operations

image22 image22

  • Let’s add a new line after the Call Context in the Service Context
  • Place cursor on the last position of the Call Context
Info

Note that the corresponding Context Bar is highlighted

image23 image23

  • Press Cursor-Right
  • While the cursor stays at its position, the Service Context is now highlighted
  • Alternatively, you can use the context navigation from the actifsource Template Editor toolbar image24 image24

image25 image25

  • Press Enter
  • A new line has been added in the Parent Context

Add Context via Quick Assist

image26 image26

  • Let’s look at a quick and easy way to insert a new Context
  • Insert the Variable Service.call using Content Assist (Ctrl+Space)

image27 image27

  • The light bulb at the left hand indicates Quick Assist is available
  • Activate QuickAssist by clicking the light bulb or pressing Ctrl+1

image28 image28

  • Click on Create Line Context

image29 image29

  • The Variable Service.call has been replaced by Call
Info

Note that a new Call Context (Selector: Service.call) has been added

Built-In Functions

image3 image3

  • Let’s use Built-In Functions on Attributes
  • Press '.' (dot) and Content Assist (Ctrl+Space) after name to see all available Built-In Functions

image30 image30

  • Complete the member variable declaration as shown above

Extract Function in Function Space

image31 image31

  • Call.name_Impl shall be the name of a new Template
  • Select the term Call.name_Impl
  • Activate QuickAssist by clicking on the light bulb or pressing Ctrl+1
  • Click Extract TemplateFunction
  • Template Functions behave like templates and are easier to handle than Java functions

image32 image32

  • Name the function className
  • Click New Template to create a new template which acts as Function Space for the new function className
Info

Note that the default Function Space for this new function is the Template ServiceImpl

image33 image33

  • Check the Package
  • Name the Template CallImpl
  • Press Finish

image34 image34

  • Press Finish
Info

Note that the Function Space has been changed from ServiceImpl to CallImpl

image35 image35

  • The Term Call.name_Impl has been replaced by Call.className@CallImpl
  • className@CallImpl indicates that the Function className belongs to the Function Space CallImpl

image36 image36

  • A new Template named CallImpl has been created in the Package template
  • Use the Function className in the file line of your template
Info

Note that className is the Function which we extracted in the template ServiceImpl before

image37 image37

  • Write a simple class as shown above
  • Write a method execute with returnType and Parameter
  • Please notice that you might copy the whole parameter expression from the ServiceImpl Template
  • Place a Protected Context in the function body

Templates and Folders

image38 image38

  • Open the underlying Template Function for className (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image39 image39

  • The function className is handled as a Template Function (partial template)
  • Template Functions are easy to handle
  • A TemplateFunction may call itself to follow recursive meta model designs (Composite Pattern)

image40 image40

  • Generated artifacts are placed in the Target Folder of your project

  • You may want to place generated artifacts in specific sub folders

  • Add Service.name/ as folder information in the file line of the Template ServiceImpl as shown above

image41 image41

  • We want all Call implementations to be generated in the same folder as their corresponding Service
  • Add Service.name as the folder name in the file line of the Template CallImpl as shown above
  • Save the Templates CallImpl and ServiceImpl
  • Protected Regions of the generated files are preserved image42 image42
Info
  • Note that files generated from this template are moved to the new location automatically

Copy with Context

image43 image43

  • Extract a TemplateLineFunction memberName for the member variable name

image44 image44

  • Also use the function memberName in the function body as shown above

image45 image45

  • Open the underlying TemplateLineFunction for memberName (Ctrl+Left-Click)
  • Alternatively, you can use the Tool Open Link in JavaEditor from the actifsource Template Editor toolbar image18 image18

image46 image46

  • The function className is handled as a TemplateLineFunction
  • Template Line Functions are the easiest way to reuse information
  • Template Line Functions do not allow context

image47 image47

  • We want to copy Parameter.name including the Parameter Context and the separating comma from the functions parameter list
  • Select the Term Parameter.name
  • From the Context Menu, select Copy with Context
  • From the Subcontext Menu, select Parameter
Info

Note also the shortcuts Alt+PageUp to select the parent context, and Ctrl+C to copy a context

image48 image48

  • Place your cursor between the brackets
  • Select Paste from the Context Menu (Ctrl+V)

image49 image49

  • The text and its corresponding context are inserted

actifsource-point-large

State Machine

logo-large

Tutorial Actifsource Tutorial – State Machine
Required Time - 40 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – Complex Service
Goal - Developing an easy to use state machine model
- Show possible events in every transition
- Restrict transition target to state instances of the own state machine
Topics covered - Decorating Relation Aspect
- Range Restriction Aspect
- Selector (forward and reverse selection)
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

image2 image2

  • Create a simple state machine

image3 image3

  • Show possible events in every transition

image4 image4

  • Restrict transition target to state instances of the own state machine

image5 image5

  • Write a code template to generate code for a statemachine

Part I Preparation

  • Prepare a new actifsource Project named ch.actifsource.tutorial.statemachine as seen in the Actifsource Tutorial Simple Service
  • Use the following package structure

image6 image6

Part II Create a State Machine

  • Create a simple state machine
  • Instantiate the state machine and see its deficits

Create a Generic State Machine Model

image7 image7

  • Create a Generic Domain Model named Design in the Package generic using the DiagramEditor
  • The Design shall contain the following Domain Classes
    • Statemachine Event State Transition

image8 image8

  • Insert a Composition between

    • Statemachine and Event
    • Statemachine and State
    • State and Transition
  • Insert a Association between

    • Transition and State
  • Adjust the Cardinalities as shown above

  • Warning: The layout for the relations transition and targetState might differ in your editor

Create a Specific State Machine

image9 image9

image10 image10

  • Create a Statemachine named Statemachine1 in the Package specific

image11 image11

  • Add the Events start and stop
  • Add the States Initialized Started and Stopped as shown above

Part III Decorating Relation Aspect

  • Learn how to decorate a relation with a list of resources in order to prevent the mixing of instances from different Statemachines

Add a Decorating Relation Aspect

image12 image12

  • In State open the Composition transition
  • Press Enter on aspect[DecoratingRelationAspect]

image13 image13

  • Select ResourceSelectorAspectImplementation
  • Click OK
Info

Note that you can choose between a JavaAspectImplementation and a SelectorAspectImplementation

  • Selecting the JavaAspectImplementation allows you to write Java Code for complex operations
  • Selecting the ResourceSelectorAspectImplementation allows you to use the easy Selector syntax

image14 image14

  • Let's look at a possible Transition for every Event
  • The Composition transition is found in State
  • We have to navigate from State to Event
    • Navigate backwards from State via state to Statemachine
    • Navigate forward from Statemachine via event to Event

image15 image15

  • Enter the Selector State.-state.event using Content Assist (Ctrl+Space)
Info

Note that State.–state navigates backwards from State to Statemachine

image16 image16

  • Implementing a DecoratingRelationAspect asks for a subclass of Decorator

  • Decorator has a useRelation target which is used to store the specific decorating Resource

    • Shown as: decoratingRelation[target]
  • Open Quick Assist by clicking the light bulb or press Ctrl+1

image17 image17

  • Use Quick Assist to let Transition extend Decorator

image18 image18

  • Open Transition
  • By default a Class extends NamedResource
  • The Quick Assist Action changed the extends statement from NamedResource to Decorator

image19 image19

  • Quick Assist has done the following
    • Added extend Decorator
    • Added Association event

image20 image20

  • The range of Decorator.target is Resource and therefore untyped in the context of your domain
  • The new Association target extends Decorator.target but with Event as its range
  • When writing template code, you are able to access Transition.event typed as Event

image21 image21

Info

Note that the Association target has been added in the Design Diagram automatically

Use the Decorating Relation Aspect

image22 image22

  • Open the specific Statemachine Statemachine1
  • Add new Events and observe the decoratingRelation transition
Info

Note there is a decoratingRelation transition for every Event

image23 image23

  • In the State Initialized create a new Transition for transition[start]
  • Select Started as targetState
Info

Note that the relation target has been completed automatically with the specific decorating Event start

image24 image24

  • Configure the State instances Started and Stopped as shown above

Part IV Range Restriction Aspect

  • Content Assist (Ctrl+Sapce) in actifsource shows all instances of a desired type; It is often useful to restrict this selection
  • Learn how to apply range restrictions to filter instances for a given type

Without Range Restriction

image25 image25

  • Let's discover the needs for a range restriction aspect
  • Create a Statemachine named Statemachine2 in the Package specific
  • Add the Event instances open and close
  • Add the States instances Initialize Opened and Closed

image26 image26

  • Create any new Transition
  • Use Content Assist (Ctrl+Space) to add a targetState of type State
Info

Note that all instances of State are listened instead of just the ones from Statemachine2

Add a Range Restriction Aspect

image27 image27

  • In Transition open the useRelation targetState

  • Press Enter on aspect[RangeRestrictionAspect]

image28 image28

  • Select ResourceSelectorAspectImplementation
  • Click OK
Info

Note that you can choose between a JavaAspectImplementation and a SelectorAspectImplementation

  • Selecting the JavaAspectImplementation allows you to write Java Code for complex operations
  • Selecting the ResourceSelectorAspectImplementation allows you to use the easy Selector syntax

image29 image29

  • Let's restrict the range of targetState to instances of States owned by the own Statemachine

  • The useRelation targetState is found in Transition

  • We have to navigate from Transition to all States of the Statemachine

    • Navigate backwards from Transition via transition to State
    • Navigate backwards from State via state to Statemachine
    • Navigate forward from Statemachine via state to State

image30 image30

  • Enter the Selector Transition.-transition.-state.state using Content Assist (Ctrl+Space)

Use the Range Restriction Aspect

image31 image31

  • Use Content Assist (Ctrl+Space) again to add the targetState Opened of type State
Info

Note that only instances of State from Statemachine2 are listed

image32 image32

  • Get familiar with Decorating Relations and Range Restrictions
  • Write an actifsource Code Template to generate a state machine

Part V Code Template for Statemachines

  • Write a code template for instances of Statemachine

Write a code template for Statemachines

image33 image33

  • Create a package ch.actifsource.tutorial.statemachine.template
  • Select the new package and choose New->Template from the context menu.

image34 image34

  • Insert StatemachineImpl as Template Name
  • Choose the Base Type ch.actifsource.tutorial.statemachine.generic.Statemachine
  • Click Finish

image35 image35

  • Insert Statemachine.name on the Filename Line and make sure that the language (C++) is automatically detected.
  • Write the skeleton for a class Statemachine.name

image36 image36

Next, we define an enumeration variable with the all the States of a Statemachine as enumerators. This variable stores the current state of a Statemachine

  • Write the declaration of enumeration variable m_aState
  • Insert a LineContext in the enumeration list and choose the Selector Statemachine.state with the support of the Content Assist
  • Insert State.name in the newly created LineContext. Append a ','. Then mark the ',' and select NotLast to make sure that there is no comma after the last entry in the enumeration list.

image37 image37

We define a member function for each event of our Statemachine which will later handle all the possible transitions triggered by the event:

  • Create a new LineContext and choose Statemachine.event as the selector of the line context
  • Write the skeleton of a function returning void named Event.name

image38 image38

We write a switch-statement with the current state m_aState as control variable and define a LineContext that iterates over all Transitions referring to an Event through the relation Transition.event

  • Create a switch-statement with the m_aState as control variable
  • Create a LineContext inside the switch-statement
  • Choose Event.-event as the Selector of the new LineContext

image39 image39

We create a LineContext that iterates over all States that refer to a Transition through the relation State.transition

  • Create a LineContext on the same line as LineContext that we have crated before
  • Choose Transition.-transition as the Selector of the new LineContext

image40 image40

We write a case-statement for each State that is (indirectly) referring to an Event through State.transition.event

  • Insert a case State.name and add a break at the end of the case-statement

image41 image41

We update the current state as follows: We first select for an Event the Transitions that refer to the Event trough Transition.event For each Transition we select the States that are connected to Transition by State.transition For each State it holds that if the current state m_aState is equal to State then the new State of the Statemachine is Transition.targetState

  • Write code to assign Transition.targetState.name to the variable m_aState

image42 image42

In order to generate code from the template we have implemented before, we setup the project properties for Actifsource:

  • Select the project ch.actifsource.tutorial.statemachine and choose Project->Properties from the main menu

image43 image43

  • In the Properties dialog choose Actifsource and select the tab Target Folders

image44 image44

  • In the dialog Select Target Folder, click on the button Create folder

image45 image45

  • Enter src as Folder Name in the New Folder dialog

  • Click on OK in the New Folder dialog and then in the Select Target Folder dialog

image46 image46

  • Check the settings on the Target Folders tab and close the dialog by clicking on OK

image47 image47

The code generator now applies the template StatemachineImpl to the two Statemachine instances and stores the resulting files to the src folder:

  • Open the src folder and check that the two files Statemachine1Impl.hpp and Statemachine2Impl.hpp have been generated
  • If the files have not been generated, make sure that Generate Automatically is active under Project in the main menu

image5 image5

  • Open the newly generated files and inspect and compare the code for the two Statemachines
  • Learn how to extend the Statemachine by conditional transitions and actions executed together with a transition by working through the Actifsource Tutorial Code Snippet
  • Complete the generated classes by adding a member function initialize()

actifsource-point-large

Language

logo-large

Tutorial Actifsource Tutorial – Language
Required Time - 15 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Enabling syntax highlighting for any programming language
Topics covered - Create a new Language
- Use the new Language
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Preparation
  • Create a new Language
  • Using the Language

Part I Preparation

image2 image2

  • Prepare a new actifsource Project named ch.actifsource.tutorial.language as seen in the Actifsource Tutorial Simple Service

Part II Create a new Language

  • Instances of Language describe the following language elements

    • Keywords
    • Single Line Comments
    • Multi Line Comment
    • Color and font type
  • Let’s create an new Language instance for a fictitious math language

image3 image3

  • Select the package language
  • Use the New Resource Tool to create a Resource of type Language

image4 image4

  • Name the Language Math

  • Click Finish

image5 image5

  • Define the file name extension for the new language
  • Define your keyword style: color DarkRed, fontModifier Bold
  • Define your keywords: var, add, sub, mul, div
  • Define your single line comment style: color DarkGreen, fontModifier Italic
  • Define your single line comment tag: #
  • Use a StringStyle to define string coloring

Part III Use the new Language

  • The actifsource template editor is now supporting the new Languagefor the specific file extensions
  • Let's test the new syntax highlighting

image6 image6

  • Create a new Template in the Package language

image7 image7

  • Name the Template Test
  • Click Finish
  • Ignore the warning “No build config selected.”

image8 image8

  • In the file line, choose the file extension .math
  • The Language is Math selected automatically
  • Use Content Assist (Ctrl+Space) to select the language manually (i.e. if there is no file extension)
  • Use Ctrl+Click on the Language to open the Language Resource

image9 image9

  • Add some Code using the new keywords
  • Try to write some comments

actifsource-point-large

Literal Aspect

logo-large

Tutorial Actifsource Tutorial – Literal Aspect
Required Time - 30 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Writing an aspect for custom literal types
- Validate custom literals
Topics covered - Create a simple demo model
- Add a new Literal
- Implement the Literal Aspect
- Using the Literal Aspect
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create a simple demo model
  • Add a new Literal

image2 image2

  • Setup the project

image3 image3

  • Implement the Literal Aspect
  • Using the Literal Aspect

image4 image4

Part I Setup a simple demo model

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial Simple Service with name and namespace ch.actifsource.tutorial.literal.aspect as shown in this tutorial

image5 image5

  • Create a new class as shown in the picture with name Component and one attribute
  • As you can see in the content assist, there is no Literal for representing a date.
  • Create a new Literal using the content assist

image2 image2

  • Set the name to DateLiteral
  • For the moment there is not much more we can do, since we first need to setup the project.

Part II Setup the project

image30 image30

  • First we need to to convert this project to a Eclipse Plugin Project
  • Right click on the project ch.actifsource.tutorial.literal.aspect in the navigator to open the context menu.
  • Go into the submenu Configure and click on Convert to Plug-in Projects…
Info

Note that eclipse allows a project to be an actifsource project and a Eclipse Plugin project at the same time.

image31 image31

  • Check the checkbox in front of ch.actifsource.tutorial.literal.aspect
  • Click Finish

image32 image32

  • This will convert the project however there will be some error and warning needed to be fixed.

image33 image33

  • Right click on the Actifsource classpath container
  • Go into the submenu Build Path and select Remove from Build Path

image34 image34

  • Open the MANIFEST.MF

image35 image35

  • Now you have a Plug-In project and need to set the dependencies to actifsource plugin defining the Literal Aspect. In this case it is the ch.actifsource.core"-Plug-In.
  • Add a dependency to the ch.actifsource.core" and the ch.actifsource.ui.refactoring-Plugin

image36 image36

  • Create a new java source folder for the aspect implementation.
  • We recommend naming the new source folder src
  • Click Finish

Part III Implement the Literal Aspect

  • After the project setup, we are ready to create a java class using an actifsource core interface
  • Java Class implementing the ch.actifsource.tutorial.literal.aspect.ILiteralAspect.

image11 image11

  • There are four methods to implement
  • getValueType The java type representing the literal value. In our case the java “Date” class.
  • getValue A conversion method to convert the literal value to an instance of the value type, which may return “null”, if the value is invalid
  • allowMultiLine True, to allow the use to type in multiple lines using line breaks
  • isValid Returning an error string if the value is invalid or “null” if valid
  • Implement the LiteralAspect as following
package ch.actifsource.tutorial.literal.aspect;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

import javax.annotation.CheckForNull;


import ch.actifsource.core.INode;
import ch.actifsource.core.job.IReadJobExecutor;
import ch.actifsource.core.model.aspects.ILiteralAspect;
import ch.actifsource.core.scope.IResourceScope;

public class DateLiteral implements ILiteralAspect {

  @Override
  public boolean allowMultiline() {
    return false;
  }

  @Override
  public @CheckForNull Object getValue(IReadJobExecutor executor, IResourceScope arg1, INode value) {
    DateFormat dateInstance = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    try {
      return dateInstance.parse(value.toString());
    } catch (ParseException e) {
      return null;
    }
  }

  @Override
  public Class<?> getValueType() {
    return Date.class;
  }

  @Override
  public @CheckForNull String isValid(IReadJobExecutor executor, IResourceScope scope, String value) {
    DateFormat dateInstance = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    try {
      dateInstance.parse(value.toString());
      return null;
    } catch (ParseException e) {
      return e.getMessage();
    }
  }

}

Part IV Using the Literal Aspect

  • Go back to the “DateLiteral” and add new value for the aspect [LiteralAspect] relation.

image13 image13

  • Type “Date” and use the content assist to select the class.

image14 image14

  • The Literal is now ready to use, since we created the Literal early with the content assist, the attribute in the “Component” is already using it

image15 image15

image16 image16

  • To test the literal, just create a new instance of the “Component” and define a “releaseDate”.

image4 image4

actifsource-point-large

Refactoring

logo-large

Tutorial Actifsource Tutorial – Refactoring
Required Time - 45 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Writing an aspect for refactoring instances
- Refactor instances to match the new specification literals
- Update templates
Topics covered - Create and register a refactoring aspect
- Update the simple service model
- Execute a refactoring
- Update the templates
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create and register a refactoring aspect

image2 image2

  • Update the simple service model

image3 image3

  • Write a simple refactoring

image4 image4

  • Execute the refactoring

image5 image5

  • Update the templates

image6 image6

Part I Create and register a refactoring aspect

Setup a project

image7 image7

  • Open the project created during the Actifsource Tutorial Simple Service or make an new one with the new project with name and namespace ch.actifsource.tutorial.refactoring as shown in this tutorial
  • Create a new Package with name refactoring
  • Create a Refactoring resource of type ch.actifsource.ui.refactoring.Refactoring with name Refactoring

image3 image3

  • You need to convert this project to a Eclipse Plugin Project
  • Right click on the project ch.actifsource.tutorial.builtin in the navigator to open the context menu.
  • Go into the submenu Configure and click on Convert to Plug-in Projects…

image4 image4

  • Check the checkbox in front of ch.actifsource.tutorial.refactoring
  • Click Finish

image5 image5

  • This will convert the project however there will be some error and warning needed to be fixed.

image6 image6

  • Right click on the Actifsource classpath container
  • Go into the submenu Build Path and select Remove from Build Path

Create and register a refactoring aspect

image8 image8

  • Open the MANIFEST.MF

image9 image9

  • Add a dependency to the ch.actifsource.core" and the ch.actifsource.ui.refactoring-Plugin

image10 image10

  • Create a new java source folder for the aspect implementation.

image11 image11

  • We recommend naming the new source folder src-aspect
  • Click Finish

image12 image12

  • Create a new java class extending the ch.actifsource.core.model.aspects.impl.AbstractRefactorerAspect class

image13 image13

  • Add the following constructor function to the class
public CallGroupRefactoringAspect() {
  super("1.0.0",
        Date.from(LocalDate.of(2024, 1, 6).atStartOfDay(ZoneId.systemDefault()).toInstant()),
        "Call to Callgroup");
}
  • The first parameter defines a version string for the aspect. The following three parameters are used to specify the date when the refactoring was written.The last parameter is the name. The arguments are shown in the dialog and used to sort the refactoring aspects.

image2 image2

  • Register the java class in the Refactoring instance

image14 image14

  • The result should look like above. There must be no more model inconsistencies be present.

Part II Update the simple service model

image15 image15

  • Open the Service class
  • Select the call relation and cut the resource by using the clipboard (Ctrl+X)

image16 image16

  • Create a new Relation named group with a new Class named “CallGroup” used as the range

image17 image17

  • Paste the call relation from the clipboard into the new Callgroup

image18 image18

  • Add an additional Attribute named async of type boolean with default value false
  • We only use an attribute to keep the tutorial simple. An alternative would be to create a subclass of CallGroup instead.

Part III Write a simple refactoring

Select project Properties Select project Properties

  • First we want to have more convenient access to the resource guids.
  • To accomplish this, we need to check a setting in the project settings of ch.actifsource.tutorial.refactoring
  • Right-click on the project and select Properties

actifscource project Properties actifscource project Properties

  • Check in the actifsource settings whether the option “generate javamodel” is set

image19 image19

  • If the “generate javamodel” option is not set, this can be set or add a the ExportWithoutStatements buildconfig to the src-gen target folder for exporting java classes for the SimpleService packages
  • This will generate a class for each package containing a constant for each resource.

actifscource project Built-in Dependencies actifscource project Built-in Dependencies

-If you cannot use the buildconfig ExportWithoutStatements, check in the Built-in Dependencies tab whether the JAVAMODEL is available. If not, add it via the Add Builtin button.

  • Implement the refactor method

image20 image20

  • The refactor method has only two parameters an IModifiable and a list of packages. The modifiable provides the context to access the actifsource resources. The package list contains the actifsource packages selected by the user when starting the refactoring. How the packages selection is interpreted is up to the implementer.

  • In general you need to use the two classes Select and Update. These are facades providing a convenient way to select and update resource information in a context. To get information about the available methods, open the class and a have a look at the javadoc comments on how to use them.

  • The actifsource API works with statements and resources. A Statement is a triple connecting two resources (subject, object) through a property (predicate). The subject is the resource whose type (class) defines the predicate (property). The object is an instance of properties range. This is almost the same you see in the resource editor. In our example Patient is an instance of Service Person refers the Call throw the call defined in the Service class. For example you will get a statement Person (subject), call (predicate), Create (object) because Person refers to Create through the call relation. This is different from the diagram editor where subject and object are represented by their type.

  • The old model looked like this

    image3 image3

    and the new model looks like this now

    image21 image21

The only thing the refactoring has to do is adding a CallGroup into each Service and move the Call into the group.

image22 image22

  • Select all Service instances in packages posted to the refactorer
  • The instanceWithPackage method takes an ISelectable and the GUID of a class. The result is an Iterable providing all instances reachable through the selectable. Since each IModifiable is also an ISelectable, you can use the IModifiable passed to the refactorer.

image23 image23

  • Create a new CallGroup using the Update-Facade and add it to the Service-Instance
  • The Update-Facade always requires an IModifiable to work with. Using the createAndInitializeResource method you can create a new instance of a type in the specific package. If you have a named resource, it is recommended to use the overload taking a name, in this case group. The last parameter defines the default values for the attributes and relations when creating the resource and can be left out. For each property not found in the defaultValue map the default defined in the model will be used.

image4 image4

  • Move the Call to the group
  • This time the method is located on the RefactorUtil. The reason for this is that the Update-Facade only provides simple modification methods and no selects. The moveStatements method uses methods from both the Select and Update method and is more complex. The moveStatements method take the IModifiable, a Property, the source and the target. It is simply often used when moving a Property from one class to another.
  • By using the cut and paste in ResourceEditor, actifsource automatically detected that you have moved the Property call

Part IV Execute a refactoring

image24 image24

  • Open the Patient to see that it is actually invalid.
  • As you can see the group relation that is already there and it would be possible to do change the model by hand.

image25 image25

  • Open the context menu on the project or the package containing the Patient service

image26 image26

  • Select the Call to Callgroup.
  • Press Finish.

image27 image27

  • The Patient service is now refactored
  • As you can see, the values passed to the constructor are shown in the refactoring dialog. In actifsource we use the aspects to provide refactorings whenever we change the metamodel.

Part IV Update the templates

image28 image28

  • The refactoring you have written only updates the instances. This is common practice, writing a refactoring for the service model and the templates makes no sense, since updating the classes is different for each step. The same applies for the templates.
  • Open the ServiceImpl template
  • Go to the Service.call selector by clicking on the first errormarker
  • Change it to Service.group.call

image6 image6

  • Add a new line using the async attribute

image29 image29

  • Open the generate PatientImpl.java and update the protected regions.
Tip

You may play around a little bit with the model by adding an additional CallGroup to the Patient with the async attribute set to true.

actifsource-point-large

Builtin Models

logo-large

Tutorial Actifsource Tutorial – Builtin-Models
Required Time - 45 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Creating an eclipse plugin containing an actifsource builtin model
Topics covered - Create an actifsource project
- Convert an actifsource project to a plugin project
- Define the exported resource folders
- Define a builtin
- Create a feature and setup an updatesite
- Install the example feature
- Using the builtin
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Learn how to specify an actifsource Builtin

    • Create an actifsource plugin
    • Define the extensions needed to provide a model as Builtin
    • Create a feature and a updatesite for deploying the plugin
  • Install the feature and use builtin

Part I Create an actifsource project

  • Since creating a builtin doesn’t make sense without having a model, just create an actifsource project name ch.actifsource.tutorial.builtin with some resources.

image2 image2

  • YourClass is a NamedResource

Part II Convert an actifsource project into a plugin project

image3 image3

  • Right click on the project ch.actifsource.tutorial.builtin in the navigator to open the context menu.
  • Go into the submenu Configure and click on Convert to Plug-in Projects…

image4 image4

  • Check the checkbox in front of ch.actifsource.tutorial.builtin
  • Click Finish
  • This will convert the project however there will be some error and warning needed to be fixed. image5 image5

image6 image6

  • Right click on the Actifsource classpath container
  • Go into the submenu Build Path and select Remove from Build Path

image7 image7

  • Double click on the MANIFEST.MF to open the manifest editor

image8 image8

  • Go to the build.properties tab
  • Click on the yellow warning sign left to the source.. line
  • Select Add src-gen/ to the source.. build entry, if it is not already there.
  • This will add the src-gen folder to the source build when exporting a plugin including source code. This is not a requirement to export the actifsource model as builtin however we want to get rid of this warning
  • There may be more warning depending on your eclipse configuration, you may fix them the same way if you like.

image9 image9

  • Activate the Dependencies tab
  • Click on Add...
  • Enter ch.actifsource.core in the textbox to start filtering
  • Select ch.actifsource.core
  • Click on Add

image10 image10

  • If you do the conversion on an existing project, you may need to add additional dependencies. You might see this by looking into the generated files, the actifsource project dependencies and the java build path.

  • When exporting a model as plugin, you have to make sure that you have a plugin dependency to all required projects. This means all required projects need to be converted into plugins.

Part III Define the exported resource folders

  • Before defining exports you need to have access to the required extension point declarations. This is done by adding a dependency to ch.actifsource.environment.

image11 image11

  • Go back to the Dependencies tab in the manifest editor
  • Click on Add…
  • Enter ch.actifsource.en to start filtering
  • Select ch.actifsource.environment
  • Click on Add

image12 image12

  • Activate the Extension tab
  • Click on Add…
  • Select ch.actifsource.core.RegisterModel
  • Click on Finish

image13 image13

  • You don’t need to specify an ID and Name for the extension, we leave it empty.
  • Open the context menu by right click on the extension
  • Go into the Submenu New and select ResourceFolder

image14 image14

  • Select the empty (ResourceFolder) entry

  • Enter the project relative path asrc to the resource folder

  • You may define different resource folders as defined in your actifsource project configuration. This is useful if you want to write templates inside your plugin to generated code and don’t want to deliver the template and related resources. Just put the templates in a separate resourcefolder which is not registered in the extension.

image15 image15

  • Switch to Build tab
  • Check the asrc Folder in the binary build
  • This is needed to include the asrc in the binary release, if you fail to do so the plugin won’t contain any resources.

Part IV Define a builtin

  • A builtin provides a way to define dependencies to actifsource model defined in a plugin inside a non-plugin projects. This step is not required if you want to use your model only in plugin projects.

image16 image16

  • Go to the Overview tab
  • Make sure you, that the plugin ID is ch.actifsource.tutorial.builtin

image17 image17

  • Switch back to Extension tab
  • Click on Add…
  • Select ch.actifsourc.environment.RegisterBuiltin
  • Click on Finish

image18 image18

  • Select the predefined (Builtin) entry
  • Define a name EXAMPLE_BUILTIN
  • The other options are not used in this example:
    • defaultBuiltin If true, the builtin will be added by default whenever a new actifsource project is created and must be explicitly removed.
    • isExtendable If true, other plugins are allowed to define a builtin with the same name. This will result in merging the dependencies together. You may find this useful, if you provide extensions to your builtin, which you want to have automatically applied as soon as a plugin is installed.

image19 image19

  • Select the predefined (Plugin) entry
  • Enter the pluginId of your plugin ch.actifsource.tutorial.builtin
  • This is not required to be the plugin defining extension point, this might be useful if you don’t want to have a plugin dependency to ch.actifsource.environment in the plugin providing the resourcefolder.

Part V Create a feature and setup an updatesite

  • In order to deliver a plugin you need to create an eclipse feature containing the plugin and a updatesite where the feature is published

image20 image20

  • Open the menu File
  • Go into the submenu New
  • Select Project…

image21 image21

  • Select Feature Project
  • Go to the next page.

image22 image22

  • Enter the project name ch.actifsource.builtin.feature for the feature
  • As you can see, the default feature ID is set to the project name.
  • Press next to step further

image23 image23

  • Select the plugin ch.actifsource.tutorial.builtin
  • Exit the wizard using Finish

Dialog Open Associated Perspective? Dialog Open Associated Perspective?

  • Eclipse will ask you if it should open the associated Plug-in Development perspective
  • Answer this question by click on No

image24 image24

  • After finishing the wizard of feature editor will open automatically.
  • Switch to the Dependencies tab
  • Press Add Feature…
  • Select ch.actifsource
  • Hit OK
  • This will add actifsource enterprise as dependency, disallowing to installing the feature without having actifsource installed. As a result eclipse will automatically select actifsource enterprise for installation if the location of actifsource is known and contacting other updatesites is enabled (see later)
  • In order to make the feature visible on the updatesite, you need to create a category otherwise eclipse will hide the feature in the categorized view of the installation wizard.

image25 image25

  • Open the File menu
  • Select New
  • Click on Other…

image26 image26

  • Select Category Definition
  • Press the Next button

image27 image27

  • Select your feature ch.actifsource.tutorial.builtin.feature
  • This is only the location of the file, this doesn’t associate the feature with the category.
  • Leave the filename unchanged and press Finish

image28 image28

  • Press New Category
  • Enter the id actifsource.tutorial.category
  • Enter the name Tutorial Category

image29 image29

  • Select the category
  • Press Add Feature…
  • Select the your feature ch.actifsource.tutorial.builtin.feature
  • Press the Add button
  • At this point we are ready to export the feature to an updatesite

image30 image30

  • Right click on the feature.xml
  • Select Export…

image31 image31

  • Select Deployable features
  • Click on Next

image32 image32

  • Select Options
  • Click on Browse…

image33 image33

  • Select category.xml
  • Close with OK

image34 image34

  • If you don’t want to increase the micro version each time you export, it is recommended to set a qualifier. Failing to change the version or qualifier will cause eclipse to not overwrite an existing on the update site.
  • Check the Qualifier replacement checkbox
  • Enter the current date and time in reverse order
  • Be careful if the major, minor and micro version of two versions are the same, a text comparison between the qualifiers is done. This means write the date the other way around will cause eclipse to select the wrong latest version.

image35 image35

  • Go back to the Destination tab
  • Enter the location of the updatesite, we use $HOME\updateSite
  • Depending on your installation you may have to choose a different directory, where you have write access.
  • Press Finish

Part VI Install the example feature

  • For this step you need to have installation rights on the running eclipse. To get around this, you may download a new eclipse from www.eclipse.org and test it on a writable location.

image36 image36

  • Go Help
  • Select Install New Software….

Install the example feature

image37 image37

  • Enter the location of the updatesite, we used file:/c:/tmp/updateSite
  • Eclipse requires the use of the file-URL. In order to distribute the updateSite on the web, just upload the content of the directory to your webserver.
  • Check Contect all update sites during install to find required software
  • This option uses the required feature defined in the feature where we added the ch.actifsource.
  • Press Next

image38 image38

  • This dialog will show addition features if eclipse found missing feature required for installation. However you will see an error message if any feature is missing that wasn’t found. This happens when eclipse doesn’t know an updatesite containing the feature. Another reason for installation failures are conflicts between installed versions, you may need to uninstall conflicting plugins first or try to update all at once using the Check For Update dialog
  • Press Next

image39 image39

  • Read the license(s)
  • Accept the license
  • Press Finish
  • Eclipse will start downloading the required features and plugins from the updatesites

image40 image40

  • Before starting the installation of a feature, eclipse will check if the feature and the plugins are signed. This option can be activate in the export wizard, however this goes beyond this tutorial. Simply accept all certificates by clicking on the Trust Selected button
  • Since we know from the verification dialog, that only our feature is going to be installed, safely click OK

image41 image41

  • Press Yes to restart

Part VII Using the builtin

  • Now we can use the builtin. You have two options, creating a plugin dependency or adding the builtin in the actifsource preferences

image20 image20

  • Select File
  • Go to New
  • Click on Project…

image42 image42

  • Enter a project name for the usage, we use ch.actifsource.tutorial.builtin.usage
  • Switch to the Next page

image43 image43

  • Activate the Built-in Dependencies tab
  • Click on Add Builtin…
  • Select EXAMPLE_BUILTIN
  • Hit OK
  • Finish the wizard and you are ready to go
  • As mentioned when defining the builtin this step can be omitted if you have defined builtin with the defaultBuiltin-attribute set to true.

actifsource-point-large

JavaListFunction

logo-large

Tutorial Actifsource Tutorial – Java List Functions
Required Time - 20 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – Complex Service
Goal - Learn about JavaListFunctions
- Create your own JavaListFunction to sort resources
Topics covered - JavaListFunction
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Let’s create a simple model for a club with its members with a resource which represents the date of birth

  • Let’s write a JavaListFunction which can sort members by their date of birth and use it in a template

    Templateview of ClubOverview Templateview of ClubOverview

  • Create some html output for the club members sorted by the date of birth (month and day)

    Generated sorted HTML output Generated sorted HTML output

Part I Preparation

Metamodel of ch.actifsource.tutorial.javalistfunction Metamodel of ch.actifsource.tutorial.javalistfunction

  • Create a simple design consist of a club, containing members having a date of birth

  • Club is a NamedResource

  • Club owns 1..N Member

  • Member is a Resource

  • Member contains the following Attributes of type StringLiteral:

    • firstName
    • lastName
  • Member owns 1*1 DateOfBirth

  • DateOfBirth is a Resource

  • DateOfBirth contains the following Attributes of type IntegerLiteral:

    • Year
    • Month
    • Day
Info

The attributes for the individual classes can be displayed in the Class Diagram Editor by selecting the Show Attributes option the context menu (right mouse button on the class).

Show Attributes in context menu Show Attributes in context menu

Nameaspect of Member Nameaspect of Member

  • Create your own name aspect for Member
Info

Note that this step is not necessary for sorting

Nameaspect of DateOfBirth Nameaspect of DateOfBirth

  • Create your own name aspect for DateOfBirth
Info

Note that this step is not necessary for sorting

Part II Creating an HTML Template

Templateview of ClubOverview Templateview of ClubOverview

  • Create a simple html template to display all club members and their birthdays

Generated HTML output Generated HTML output

  • The generated result should look like shown above

Part III Creating a JavaListFunction

New created FunctionSpace New created FunctionSpace

  • Create a new FunctionSpace called MyFunctions
  • Create a new FunctionContext for the typeRef Member

Inserted new JavaListFunction Inserted new JavaListFunction

  • Create a new JavaListFunction called sortByDateOfBirth
  • Select GenericContextListType as returnType
  • Please note that the GenericContextListType automatically converts to the same type as used as the function target in the selector
  • You will love this feature if your type (typeRef) has sub classes
  • Imagine to create a sortByName function for NamedResource
  • Calling A.sortByName for A as a sub class of NamedResource will return A as the type of result and not NamedResource even sortByName has been defined for NamedResource

Generated JavaListFunction skeleton Generated JavaListFunction skeleton

  • After saving the FunctionSpace MyFunctions the folder src-gen will contain a Java file named the same as your FunctionSpace
  • Find the generated function body for the JavaListFunction sortByDateOfBirth
  • Let’s write some Java code to sort our club members by their date of birth

First code fragment First code fragment

  • Since the memberList passed by Actifsource is marked final we have to copy the list in order to modify\

    ArrayList<T> memberListSorted = new ArrayList<>(memberList);
  • Return the copied list to get rid of compile errors\

    return memberListSorted;

Importsection Importsection

  • Please make sure to place the import statement for ArrayList in the ProtectedRegion
  • Otherwise the your import will be overwritten from the generator

Completed code fragment Completed code fragment

  • Using the static function Collections.sort() from the Java collection framework allows us to pass a so called Comparator
  • Let’s implement the anonymous class of type Comparator<T> as shown above
  • Comparator.compare shall return 0 if objects are equal, -1 if o1 is a predecessor of o2, or +1 if o1 is a successor of o2
  • Since the variables o1 and o2 are fully typed we can directly access the properties of Member using the selectXYZ() functions
  • The code shown above is sorting dates regarding month and day only
  • Try to implement a sort function which shows the oldest member first

Part IV Putting it all together

Templateview of ClubOverview 2 Templateview of ClubOverview 2

  • Use the sortByDateOfBirth function to sort any selected list of members by their date of birth

Generated sorted HTML output Generated sorted HTML output

  • As a result your members are sorted by month and day

actifsource-point-large

Workbench Enterprise

Team Support

Share project using your favorite VCS (Version Control System). Learn how to use the Local History and resolve conflicts. more…

Project Generator

Creating Eclipse Projects automatically using actifsource. more…

Diagram with Graphviz

Learn how to use the GraphvizBuildTask to generate diagrams from generated DOT files using Graphviz. more…

Domain Diagram Type

Learn how to customize domain diagrams to your specific need using a diagram type. more…

Domain Diagram Type II

Developing an easy to use state machine model. Show possible events in every transition. Restrict transition target to state instances of the own state machine. more…

Code Snippet

Learn how transform code snippets into your target language. more…

UML Statemachine

Create UML State Machines with states, superstates, history states, (entry, exit, state) actions and transition guards more…

Meta Model Documentation

Learn how to document your own Meta Model and to generate a browsable HTML documentation. more…

Subsections of Workbench Enterprise

Team Support

logo-large

Tutorial Actifsource Tutorial – Team Support
Required Time - 20 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Compare actifsource Resources using the Local History
- Edit Conflicts using the actifsource Resource Compare Editor
Topics covered - Setup VCS (Version Control System)
- Install Eclipse Team Provider
- Share Project
- Local History
- Edit Conflicts
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Setup your VCS (Version Control System)

  • Install an Eclipse Team Provider

  • Share your project using the Eclipse Team Support

  • Compare actifsource Resources using the Local History

    image2 image2

  • Edit Conflicts using the actifsource Resource Compare Editor

    image3 image3

Part I Preparation

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial Simple Service

    • Setup the Target Folder src
    • Create a Generic Domain Model
    • Create a Specific Domain Model
    • Create a Code Template
  • Use any package structure. For Example

image4 image4

Part II Share Project

Info

The Eclipse Team Support comes all ready with the default installation of Eclipse.

Share Project

image5 image5

  • Share your Project via the context menu Team on your project

image6 image6

  • The shared project shows revisions and icon overlays

Part III Local History

  • The Local History is part of the Eclipse Team Support
Info

Note that the Local History works also on non-shared projects

Local History

image7 image7

  • Change any of your Resources
  • Save the Resource

image8 image8

  • The '>' in the Resource Navigator indicates, that the Resource has been changed
  • From the context menu of Patient choose Team/Show Local History…

image2 image2

  • Select two of the shown versions of your interest
  • From the context menu, select Compare with Each Other

image9 image9

  • The actifsource Resource Compare Editor will show you any changes between the selected versions

Part III Edit Conflicts

  • Working in a team may lead to conflicts if more than one developer changes the same resource at the same time
  • The Resource Compare Editor helps to resolve these conflicts

Edit Conflicts

image10 image10

  • In the meantime, another developer (Developer 2) added a new Call DeleteEverything to the Service Patient
  • As we have added the Call DeleteAll in the same resource before, there will be a conflict when updating from the repository
  • To simulate another developer, just check out your project on a different location
  • Modify the resource as shown above
  • Check in the modified resource to your repository

image11 image11

- Back to Developer

  • Before checking in our modification (Call DeleteAll to the Service Patient) let's check for updates
  • From the context menu of your project, select Team/Update

image12 image12

  • As expected, a conflict occurs

image13 image13

  • From the context menu of the conflicting resource Patient select Team/Edit Conflicts…

image3 image3

  • The actifsource Resource Compare Editor will show you the changes
  • Your local version on the left
  • The repository version on the right
  • Use the marked tools to copy changes from one version to the other

image14 image14

  • Once resolved all conflicts, choose Team/Mark as Merged from the context menu

image15 image15

  • From the context menu, select Team/Commit to commit the actual work to your repository

actifsource-point-large

Project Generator

logo-large

Tutorial Actifsource Tutorial – Project Generator
Required Time - 30 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Generate Eclipse Projects using actifsource
Topics covered - Create a project to generate eclipse projects
- Generate the project settings
- Create and distribute non-generated files
- Generate .projectconfig files to enable project creation
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create an eclipse project generator project

  • Generate the project settings

    image2 image2

  • Place non-generated files

    image3 image3

  • Generate .projectconfig files to enable project creation

    image4 image4

Part I Preparation

image5 image5

Part I Create Project Data

image6 image6

  • Create a new Class named “Project” in the package ch.actifsource.tutorial.project.generator.spec using the New Resource Wizard

image7 image7

  • Create a new Template named “ProjectSettingsTemplate” by right clicking the newly created class Project and selecting the New Template Wizard.
  • Since you clicked on the resource Project actifsource automatically fills in the base type, meaning the template is executed for each instance of the class Project

image2 image2

  • Write the content of the .project file or copy it from one of your existing eclipse project.
  • Replace the variable information by linking to the actifsource model (Use Content Assist: Ctrl+Space).
  • Use the project name to create a subdirectory for each project in the target folder.
  • In this example we only generate the project name from the model, feel free to extend the model to fit your needs.

Part II Add non generated files

image3 image3

  • Sometimes you may have configuration files equal for all projects, in this case just put them into a folder in the generator project.
  • Create a “src_common” folder and copy the .asproject and the .classpath file of a preconfigured project into it or use the ones on the following page.

image8 image8

image9 image9

Part III Create Project Configuration

  • Now after you generated and copied all project files, like the .project, .classpath and .asproject, you need to generate a .projectconfig file.
  • You need to create a .projectconfig file for each project. The .projectconfig defines the eclipse name of the project and the initial file structure. Since all settings are stored inside the projects file structure as setting-files, this also defines the initial project setup.

image4 image4

  • Write a template for the .projectconfig file, as before use the projectname from the model.

  • Actifsource provides the following elements inside the project-element.

    • dir with attribute name to create a directory in project root
    • file with attribute src and dst to copy a file from the generator project to the generated project use the overwrite attribute to specify if the file is overwritten each time generator runs again
    • workingset with attribute name to add the project to a specific

Part IV Setup BuildConfig and Targetfolder

image10 image10

  • Create a BuildConfig named “ProjectBuild” using the New BuildConfig Wizard and including all templates.

image12 image12

  • Create a new package ch.actifsource.tutorial.project.generator.usage.

image13 image13

  • Create an instance of the Project class in the package ch.actifsource.tutorial.project.generator.usage named “TestProject”.
  • This step will result in the first try to generate the project, but fails due to missing the buildconfig setup.

image14 image14

  • Right click on the project and select properties
  • Click on the category actifsource
  • Goto the target folder tab and click on the src-folder
  • Add the buildconfig ProjectBuild
  • Add the package ch.actifsource.tutorial.project.generator.usage
  • Now actifsource will generate the xml files with current xml-comment and the project builder creates a new project.

Part V Conclusion

  • As you have seen generating projects is very similar to generating any other file, except that you have to generate the project type specific settings files and a project configuration file.
  • Depending on your needs you may define the builders listed in .project files or the required libraries listed in .classpath files based on your models information.

actifsource-point-large

Diagram with Graphviz

logo-large

Tutorial Actifsource Tutorial – Diagram with Graphviz
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Write a template to generate a UML Class Diagram as Graphviz DOT file
- Generate a SVG graphic using GraphvizBuildTask
Topics covered - Setup Graphviz
- Create an UML model
- Create a graph template for Graphviz
- Add Visibility to Methods and Attributes
- Distinguish Association types
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Setup Graphviz
  • Create a UML model

image2 image2

  • Create a graph template for Graphviz
  • Add more UML features

Part I Preparation

  • Setup the Graphviz software.
  • Set Built-in Dependencies of an actifsource Project for graph generation.

Setup Graphviz

  • Before you can generate UML diagram, you need a running environment of Graphviz. If you already have the Graphviz commands working from command line (with the PATH environment variable set), you can skip the following setup and proceed with the actifsource Project settings.

  • Graphviz is an open source graph visualization software. Previously developed by AT&T it is now available under Eclipse Public Licence.

  • Start your internet browser and open the address www.graphviz.org.

  • Goto “Download” and check the licence agreement (Eclipse Public Licence).

  • Select the executable package provided for your operating system, download the current release and run it.

  • Follow the steps of the installation routine.

  • Add the “bin” folder of the installation path (e.g. C:\\Program Files\\Graphviz\\bin) to your PATH environment variable.

Create a Project

  • Prepare a new actifsource Project named ch.actifsource.tutorial.graphviz as seen in the Actifsource Tutorial Simple Service

    • Setup the Target Folder graph

image3 image3

  • Use the this package structure

image10 image10

  • There is an optional Built-in for Graphviz providing a build task that compiles the generated graphviz files into SVG graphics.
  • Open the Project Properties.
  • Select the actifsource Settings.
  • On the tab “Built-in Dependencies” add GRAPHVIZ.

Part II Create a UML Model

  • We need a metamodel that provides those features we want to get displayed on our UML Class Diagram.
  • The generated diagram will depend only on this model. So, in order to create a Class Diagram that displays the same classes as the generated code, we will have to write a template that generates for every class in the code a class in the Class Diagram.

Create a UML MetaModel

image11 image11

  • Create a ClassDiagram named Metamodel.
  • Add a new **Class**es for Class Method Attribute Association and Cardinality
  • Add a new Enum Visibility
Info

You don’t have to model the UML features explicitly in your real project – but you must be aware how to read those features out of your model. To avoid code duplication, Functions as in the Actifsource Tutorial Complex Service might help.

image12 image12

  • Ctrl+ Left-Click on Cardinality to edit Cardinality in the Resource Editor.
  • Add to IntegerLiteral-**Attribute**s named min and max
  • Set the (subject-)Cardinality of both attributes to 0..1.
  • Change the supertype extends from NamedResource to Resource, since cardinalities are identified by their minimum and maximum and not by a name.

image13 image13

  • Ctrl+ Left-Click on the Enum Visibility to edit Visibility in the Resource Editor.
  • Add the value public protected private and package to this Enum.

image14 image14

  • Add a Aggregation extends from Class to itself.
  • Add a Composition from Class to Association
  • Add a Aggregation target back from Association to Class
  • Set the (subject-)cardinality of target to exactly 1.
  • Add **Composition**s from Class to Method and Class to Attribute
  • Add a Relation from Association to Cardinality let it be an Composition for simplicity sake.
  • Add a Aggregation from Attribute to Visibility and from Method to Visibility
  • Set the (subject-)cardinality of the 3 Relations to 0..1.

Create a UML Meta

image15 image15

  • Now let us create a Class Model package ch.actifsource.tutorial.graphviz.specific that shows the features we want to look at.
  • For instance, create a Class Vehicle
  • Create Subclasses Car Bicycle and Airplane i.e. Class having the extends-Relation set to Vehicle
  • Create Classe Sedan Convertible SUV as Subclasses of Car
  • Create a Class Wheel and a Class Wing
  • Add an Association wheels to both Car and also to Bicycle and set the corresponding target to Wheel.
  • Add an Association wings to Airplane which points to Wing

Part III Create a graph template for Graphviz

  • We will generate graph definitions in the Graphviz DOT language and then in layout the graph to define our UML Class Diagram using the Graphviz DOT command. You can find the documentation of the DOT language on the Graphviz homepage.
  • Graphviz provides several output formats: raster graphics like PNG, or vector graphics like PostScript or SVG.
    We will prefer SVG as output format since it can easily be post-processed, and the graphics can be embedded in HTML Pages and contain tooltips and hyperlinks.

Create a build configuration

image16 image16

  • Select the package ch.actifsource.tutorial.graphviz.template.
  • Create a new BuildConfig and name it Diagram

image17 image17

  • Create a new Template named ClassDiagram
  • The Template ClassDiagram is now placed into the selected BuildConfig Diagram

image18 image18

  • Select the ClassDiagram TemplateGeneratorTask.
  • Insert after the selection a GraphvizBuildTask with Ctrl+Enter.
  • The GraphvizBuildTask will effect that every File with File Extension .dot in the Target Folder and its subdirectories is processed with the Graphviz DOT command and an SVG File with the same name but File Extension .svg is written.
Info

Note that the GraphvizBuildTask has to be executed after all DOT Files have been generated. Therefore it is always the last BuildTask in the list. If you add new **Template**s to the BuildConfig, move the GraphvizBuildTask to the end (by pressing Alt+PgDn).

Create a graph template

image19 image19

  • If you are interested in the full capabilities of Graphviz, consult the documentation on www.graphviz.org.

  • Open the ClassDiagram Template with the Template Editor.

  • Create a directed graph (digraph) with the following attributes:

    • Default rankdir (i.e. rankdir=TB: top-bottom), so unconnected nodes (i.e. Class will appear on top.
    • ordering=out: Preserve the order of the outgoing edges (i.e. left sibling before right sibling, etc.)
    • nodesep=0.5; ranksep=0.5: Space among nodes of same rank, Space between ranks
    • splines=spline: Draw the edges (i.e. Association and extends as cubic splines.
  • Place nothing in it but a single cluster, that will be drawn with a frame around

    • Label this cluster Class Diagram.
  • The main elements of a DOT file are graph, node and edge.

    • graph Definition: graph GraphID { … }
    • node Definition: NodeID [attr~1~=value~1~, … , attr~n~=value~n~];
    • edge Definition: NodeID~tail~ -> NodeID~head~ [attr~1~=value~1~, … , attr~n~=value~n~];
  • The default values of the attributes can be set with special statements:

    • node [attr~1~=value~1~, … , attr~n~=value~n~];
    • edge [attr~1~=value~1~, … , attr~n~=value~n~];
  • Set the default attributes for Class Set its node shape to record and set fill color to lightyellow.

  • Set the default attributes for the extends Relation: The arrow should point from bottom to top (dir=back) and have an empty arrow head.

  • Set the default attributes for the Association The arrow head should have a V-shape (vee).

Declare Classes, Subtype relations and Associations

image20 image20

  • Let us now insert line contexts for the UML artifacts we discussed before:
  • Add a line context for all Class
  • Be sure you choose ch.actifsource.tutorial.graphviz.generic.Class and not ch.actifsource.core.Class
  • Add a line context for all Class with a nested line context which iterates over Class.extends
  • The Class of the outer (hidden) context is named in the template editor with Class[2], the Class of the inner context (so the base class) is named with Class.
  • Add an edge statement back from Class to Class[2].
  • Add a line context for all Class with a nested line context for all Association
  • Add an edge statement from Class to the Association.target labeled with the Association.name

Add Methods and Attributes

image21 image21

  • We want to subdivide the class nodes to display the methods and attributes. For this feature, it will help we did not choose a simple rect shape for class nodes, but a record shape: With pipe characters “|” we can subdivide node shapes and with curly brackets “{” and “}” swap the direction of division from left-right to top-bottom and vice versa.

image22 image22

  • Change the label of the class node, so the node is partitioned vertically into 3 fields with the Class.name in the first field, all fields left-justified.
  • It is not possible to have column contexts nested.
  • Therefore split the label into three lines using the backslash “\” at the line end.
  • Add line contexts to iterate over the Method of a Class and over the Attributes of a Class

Add Visibility to Methods and Attributes

image23 image23

  • We need the visibility symbols in our model in order to display it in the graph. Or, we need a Java function (see Actifsource Tutorial Complex Service) that maps the Visibility elements in the model onto the UML symbols.
  • Open the Enum Visibility in the Resource Editor.
  • Add a StringLiteral Property umlSymbol with (subject-)cardinality exactly 1.
  • Set the umlSymbol of the enumeration values to the respective UML symbols: +, #, -, ~.

image5 image5

  • In the template, insert a new Column Context in the Context which iterates over all Method

  • Select in this Context the Method.visibility

  • In this context Insert Visibility.umlSymbol

  • Repeat the 3 steps for Attribute.visibility

  • You can eliminate the empty record fields in the class nodes of the graph by checking if there are any methods or attributes:

image6 image6

  • Add a Line Context inside the context which iterates over all Class
  • Set the Selector to Class.method union Class.attribute
  • This will iterate over the set union of the Elements in Class.method and those in Class.attribute
  • Choose First (Alt + 1), so that this Context is entered at most once.
  • Add a line that generates only a simple rect for a Class
  • Choose Empty (Alt + 5), so that this line is evaluated if the ContextClass.method union Class.attribute is empty.

Add Cardinality

  • We did not cover cardinalities so far.

image7 image7

  • Add a Line Context that selects the Association Cardinality

  • In this Context, add a headlabel, that contains the min and max Cardinality:

    • In the label insert a Column Context for Cardinality.min and one for Cardinality.max
    • For empty Cardinality.min context (Alt + 5), insert 0.
    • For empty Cardinality.max context (Alt + 5), insert *.

Distinguish Association types

  • In UML, associations are marked with a diamond, if they are aggregations or compositions.
  • Add the Class: Aggregation and Composition which are subclasses of Association
  • Edit the typeOf Property of the **Relation**s wheels and wings and replace Association by Aggregation and Composition respectively.

image8 image8

  • Add a Line Context

  • In the Selector, cast Association to Aggregation and Composition respectively. The Line Contexts will be entered then only if it os an Aggregation or Composition

  • Set the arrowhead attribute to diamond and to ediamond (=empty diamond).

UML Class Diagram

  • The resulting graph will look now similar to this one:

image9 image9

actifsource-point-large

Domain Diagram Type

logo-large

Tutorial Actifsource Tutorial – Domain Diagram Type
Required Time - 30 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – Statemachine
Goal - Define Diagram Types to create and edit domain models in a graphical editor
Topics covered - Create a user defined diagram type to display and edit domain specific diagrams
- Create a domain diagram based on the diagram type to edit the underlying root resource
- Define a highlight path from node to node over any edge
- Define a tooltip for elements on the domain diagram
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create a user defined diagram type to display and edit domain specific diagrams
  • Create a domain diagram based on the diagram type to edit the underlying root resource
  • Define a highlight path from node to node over any edge
  • Define a tooltip for elements on the domain diagram

Part I Preparation

image2 image2

  • Prepare a new actifsource Project as seen in the Actifsource Tutorial Statemachine
  • Create a generic Domain Model as shown above
  • State.transition 🡪 Decorating Relation with Decorator State.-state.event
  • Transition.targetState 🡪 Use Relation with RangeRestriction Transistion.-transition.-state.state

Part II Create a Diagram Type

  • Create a user defined diagram type to display and edit domain specific diagrams

Create a Diagram Type

image3 image3

  • Create a new DiagramType named Statemachine in the Package generic

image4 image4

  • The Root Class defines the Resource which contains the elements that shall be managed on your domain diagram

  • Select Statemachine as Root Class

image5 image5

  • The Allowed Class defines all the Resources which shall be managed on your domain diagram

  • Select State as Allowed Class since we want to design a state machine

image6 image6

  • Allowed Classes might be created using the domain diagram editor via a Palette Tool

    • HidePaletteEntry: No Palette Entry to create this Allowed Class
    • ShowPaletteEntry: Palette Entry named as the Allowed Class
    • ShowRenamedPaletteEntry: Palette Entry named as defined
  • Select the PaletteEntry ShowPaletteEntry or ShowRenamedPaletteEntry

image7 image7

  • Allowed Relations are relations that shall be displayed on the domain diagram

    • AllowedDependencyRelation: Dotted Line that shows dependencies between components
    • AllowedDirectRelation: Direct relation between resources A and B
    • AllowedIndirectRelation: Indirect relation between resources A and B via X
  • We like to see a transition from state to state just as a simple arrow

  • Define the Selector State.transition.targetState for the Indirect Relation

  • Define openEditor as false if you do not want to open the Resource Editor automatically after creating the transition via domain diagram editor.

Info

Note that the resource Transition is displayed as an arrow

Part III Create a Domain Diagram

  • Create a domain diagram based on the diagram type to edit the underlying root resource

image8 image8

  • Create a new Statemachine named Statemachine1 in the Package specific

image9 image9

  • We could now define Event, State and Transition using the Resource Editor
  • Let’s now try the Domain Diagram Editor

image10 image10

  • Create a new Domain Diagram named Statemachine1 for the Statemachine Statemachine1 in the Package specific
  • Use the context menu directly on the Statemachine Statemachine1

image11 image11

  • The domain diagram shall be named Statemachine1
  • DiagramType is detected automatically based on the Root Resource
  • Single Root is filled in automatically based on the context of new Domain Diagram

image12 image12

  • Create new States named Open Close Opening and Closing using the State Tool from the Palette
Info

Note that the palette entry is influenced by DiagramType.allowedClass.paletteEntry

image13 image13

Info

Note that the dependent Statemachine Statemachine1 is modified accordingly

image14 image14

  • Start adding Transitions using the Relation Tool from the Palette

image15 image15

  • Therefore you are asked for an Event when creating a new Transition
  • Create a new Event called Command_Close using Content Assist (or choose an existing Event
Info

Note that Transitions are based on Events by using the Decorating Relation

image16 image16

  • The Event Command_Close has been created
  • The Transition based on the Event Command_Close with targetState Closing has been created

image17 image17

  • Add some more Transitions based on the new Events Command_Open Sensor_Closed Sensor_Opened

image18 image18

  • Add two more Transitions based on the existing Events Command_Close and Command_Open
  • Use Context Assist to choose the existing Events

Part IV Define a Highlight Path

  • Define a highlight path from node to node over any edge

image19 image19

  • Let’s see where transitions are leading to from source to target state
  • Define a HighlightPath for the Allowed Class State as shown in the example above

image20 image20

  • Hoover your cursor on any State to activate the HighlightPath from State via Transition to TargetState

Part V Define a Tooltip

  • Define a tooltip for elements on the domain diagram

image21 image21

  • Create a new FunctionSpace named Tooltip in the Package generic

image22 image22

  • Create a new ResourceInfo with typeRef State
  • Create a new TemplateFunction named tooltip

image23 image23

  • Open the Template Editor by double clicking Tooltip.State.tooltip in the Project Explorer

image24 image24

  • Print the State.name
  • For every Transition in State: Print Transition.event.name
  • For every Transition in State: Print Transition.targetState.name

image25 image25

  • Use the TemplateFunction tooltip@Tooltip by using a SelectorTooltip in the Diagram Type

image26 image26

  • Hoover your cursor on any State to activate the Tooltip

actifsource-point-large

Domain Diagram Type II

logo-large

Tutorial Actifsource Tutorial – Domain Diagram Type 2
Required Time - 70 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – Domain Diagram Typ
Goal - Define Diagram Types to create and edit domain models in a graphical editor
Topics covered - Create a Diagram Type
- Working with Diagram Editor
- Define shapes, figures and ports to use in Diagram Editor
- Add conditions to figures
- Add a search function to a domain diagram
- Add notes to domain diagrams
- Add labels to ports
- Insert links in Domain Diagrams to (external) diagrams (e.g. UML State Machines)
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create a new (Domain) Diagram Type for a simple meta model of systems composed of processes that have (outgoing) out-ports and (incoming) in-ports to communicate with each other:

image2 image2

Define the properties of the Domain Diagram such that names of processes can be edited, ports can be created and out-ports (Port_Out) can be connected to in-ports (Port_In).

  • Add a search function that allows you to search for specific processes in a Domain Diagram

  • Add links to (existing) state diagrams to Domain Diagrams, e.g., to associate an UML state machines with a specific process to describe its behavior

Part I Preparation

  • Prepare a new actifsource Project named ch.actifsource.tutorial.diagramm.ports as seen in the Actifsource Tutorial Simple Service
  • Use the following package structure image3 image3

image4 image4

  • Create a ClassDiagram named Design in the Package generic using the DiagramEditor

  • Create the following Classes

    • System Process Port Port_Out

image5 image5

  • Insert an Composition between

    • System and Process

    • Process and Port_In

    • Process and Port_Out

  • Insert a Association between

    • Port_Out and Port_In
  • Adjust the Cardinalities as shown above

image6 image6

  • Create a new Resource of type System in the package ch.actifsource.tutorial.diagramm.ports.specific (Right-click on the package and choose New->Resource from the menu)

  • Give the name SystemA to the the newly created resource in the New Resource Wizard

Part II Define a new Diagram Type

image7 image7

We create a new Diagram Type called System in order to define properties of Domain Diagrams of Systems:

  • Select the resource System in the package ch.actifsource.tutorial.diagramm.ports.generic and choose New -> Diagram Type from the menu

Define a new Diagram Type

image8 image8

  • Enter SystemDiagram as name for the newly created DiagramType in the New DiagramType Wizard

  • Make sure that ch.actifsource.tutorial.diagramm.ports.generic.System has (automatically) been chosen as RootClass

image9 image9

We create a new Domain Diagram for the resource SystemA

  • Select the resource SystemA and choose New ->Domain Diagram from the menu

  • Enter SystemA as the name of the new diagram in the New Domain Diagram Wizard

  • Click Finish

image10 image10

Next, we create a shape and a figure for the class Process in order to define how elements of type Process are displayed and handled in the Diagram Editor:

  • Open SystemDiagram in the Resource Editor

  • Create a statement allowedClass refering to an AllowedClass with class ch.actifsource.tutorial.diagramm.ports.generic.Process

  • As paletteEntry choose the type ShowPaletteEntry

image11 image11

  • Create a new ClassStyle as style and add a new ModelShape as shape to it

image12 image12

  • Choose ProcessShape as name of the new ModelShape

  • Create a statement figure that refers to a new ch.actifsource.ui.diagram.figure.CompactFigure

image13 image13

  • Choose ProcessFigure as name of the new CompactFigure

  • Create a new drawElement and choose the type DrawRectangle from the Type Selection dialog

  • Define a fillColor by choosing DarkGray with the help of the Content Assist

  • Create a position (x=0, y=0) and a size (width = 100%, height=100%) statement as shown above

Info

Note that the conventions for drawing graphic elements follows in general the conventions used in Java native libraries (e.g. Java AWT). This means that (x=0,y=0) is positioned in the upper left hand corner.  The grid is then numbered in a positive direction on the x-axis (horizontally to the right) and in a positive direction on the y-axis (vertically going down).

image14 image14

We define a childContainer for the ProcessShape

  • Create a ChildContainer
  • In the newly created ChildContainer define a Point as position with x = 0% and y = 20% (the container should not cover the uppermost rectangular section of the shape)
  • Define a Size with width=100% and height=100%

image15 image15

We define the label of a process shape to be the name of the corresponding Process choose the initialization properties of a process shape and define a minimum size of process shapes:

  • Create a labelSelector of type FigureEditableLabelSelector (this allows us to edit the name of a Process directly from the Diagram Editor)
  • Create a minShapeSize with width = 100 and height = 100 (size in Pixels)
  • Create a ShapeInitialization and change its show Part not hide its parts when newly created

image16 image16

We create two Process instances, ProcessA and ProcessB in the Domain Diagram Editor:

  • Open the DomainDiagram SystemA in the Diagram Editor
  • Select Process from the Palette
  • Left-Click in the diagram to open the New Resource Wizard and choose ProcessA as the name of the new Process resource
  • Repeat the previous step and choose ProcessB as the name of the second resource

image17 image17

Check and inspect the newly created resources:

  • Check that Ctrl+Click on the label of a Process opens the corresponding process in the Resource Editor
  • Choose Edit from the Palette and edit the name of a process shape by left-clicking on its label.
Info

Note that the name in the resource editor is immediately updated when editing the label.

image18 image18

Next, we define a shape and figure for Port_Ins:

  • Add a new AllowedClass with class Port_In and define a palleteEntry of type ShowPaletteEntry
  • Add a statement style and then create a new shape statement refering to a new ModelShape
  • Give the name PortInShape to the new resource

image19 image19

  • Create a figure of type CompactFigure with the name PortInFigure

image20 image20

  • Add a drawElement of type DrawArc to the PortInFigure
  • Define the fillColor as White and the lineColor as Black
  • Create a position with x=60% and y=0%
  • Create a statement size refering to a resource of type Size with width=40% and height=90%
  • Define an offset with startArc=90 and endArc=180 (degrees)
Info

Note that 0° is positioned at the 3 o'clock position and positive values indicate a counter-clockwise rotation, negative values a clockwise rotation.

image21 image21

  • Add a second drawElement of type DrawLine to the PortInFigure
  • Create a startPosition with x=30% and y=50%
  • Create an endPosition with x=60% and y=50%

image22 image22

  • Add a third drawElement of type DrawRecangle to the PortInFigure
  • Create a statement position and set x=0% and y=0%
  • Create a statement size and set width=40% and height=100%

image23 image23

  • Open SystemDiagram in the Resource Editor
  • Create a new AllowedClass that refers to the class Port_Out
  • Create a new ClassStyle that refers to a new ModelShape. Give the name PortOutShape to the newly created ModelShape.

image24 image24

  • Add a CompactFigure with the name PortOutFigure to PortOutShape as shown above

image25 image25

  • Add a drawElement of type DrawRecangle to the PortOutFigure
  • Create a statement position and set x=0% and y=0%
  • Create a statement size and set width=40% and height=100%

image26 image26

  • Add a second drawElement of type DrawLine to the PortInFigure
  • Create a startPosition with x=30% and y=50%
  • Create an endPosition with x=60% and y=50%

image26 image26

  • Add a second drawElement of type DrawLine to the PortInFigure
  • Create a startPosition with x=30% and y=50%
  • Create an endPosition with x=60% and y=50%

image27 image27

  • Add a third drawElement of type DrawOval to the PortOutFigure
  • Define the fillColor as White and the lineColor as Black
  • Define the position with x=60% and y=0%
  • Define the size with width=40% and height=100%

image28 image28

We define the position of ports relative to their process shapes and their behavior:

  • Create a MovablePortShape in the ProcessShape

  • Define an anchorPoint with x=20% and y=0%

  • Define a movableRange with a position with x=0% and y=0% and a size with width=100% and height=100% (meaning that a port can be moved to any point on the boundary of the rectangular process shape)

  • We do not define an orientation (the shape of a port is thus rotated when moved along the boundary of its parent shape)

image29 image29

We define a selector for all the allowed Port figures:

  • Open the SystemDiagram in the Resource Editor and create a ChildFigureSelector as Decorator for portFigureSelector[Port]
  • Define the selector Process.port_In union Process.port_Out which selects all ports of type Port_In and Port_Out that belong to a Process

image30 image30

Next, we a PortIn and PortOut to each of our two Processes:

  • Open the Domain Diagram SystemA in the Diagram Editor (Note: If the diagram is still open, close it first and then re-open it in order to update the behavior of the diagram)
  • Choose Port_In from the Palette and left-click on ProcessA
  • Choose the name in_a in the opened New Resource Wizard
  • In the same way create a Port*In with name in_b for ProcessB
  • Choose Port_Out from the Palette and left-click on ProcessA
  • Choose the name out_a in the opened New Resource Wizard
  • In the same way create a Port*In with name out_b for ProcessB

image31 image31

  • Open the Domain Diagram SystemA in the Diagram Editor and position the newly created ports by selecting them and moving them on the boundary of their process shapes.

image32 image32

Finally, we want to be able to connect outgoing ports Port_Out to ingoing ports Por_In by the relation Port_Out.port_In

  • Open the SystemDiagram in the Resource Editor
  • In the allowedClass for Port_Out create an allowedRelation of type AllowedDirectRelation and define the selector Port_Out.port_In

image33 image33

We connect out_a with in_b as follows:

  • Choose Relation from the Palette
  • Click on the port out_a. Then drag the mouse to the port in_b and click on port in_b
  • In the same way connect out_b to in_a
  • Open and inspect the newly created statements by opening SystemA in the Resource Editor as well:

image34 image34

Part III Add conditions to figures

image35 image35

Next, we want the Process shape to change its color when its parts are hidden:

  • Open ProcessFigure in the Resource Editor and add a third drawElement of type DrawRectangle and define the properties size and position as above (Note that you can also simply copy and paste the existing DrawRectangle).
  • Define the fillColor as ActifsourceForeground
  • Create a condition by using the Content Assist and choosing ShowContainerCondition (i.e., the shape should have the color ActifsourceForeground when its container is not hidden)

Add conditions to figures

image36 image36

  • Add a condition HideContainerCondition to the first drawElement of type DrawRectangle of the ProcessFigure (thus, the shape will be DarkGray when its container is hidden).

image37 image37

  • Open the Domain Diagram SystemA in the Diagram Editor and righ-click on one of the Process shapes
  • Select Show/Hide Resource Part color of the shape changes accordingly

Part IV Add notes to Domain Diagrams

image38 image38

  • Open the SystemDiagram in the Resource Editor
  • Create a TypeStyle
  • Create a NoteStyle for the new TypeStyle
  • Choose NoteClipFigure as figure
  • Define a labelSelector of type FigureEditableLabelSelector and add the placementSelector NoteItem:NoteItem and the propertySelector NoteItem.nodeText

image39 image39

  • Open the Domain Diagram SystemA in the Diagram Editor
  • Select New Note from the Palette
  • Right-click on the shape ProcessB to place the note

image40 image40

  • Select Edit from the Palette
  • Right-click on the note and edit the text
  • Write a note (such as This shape represents ProcessB)

Part V Add search functions to Domain Diagrams

image41 image41

We add a search function to our Domain Diagrams that allows us to search for all Processes

  • Open SystemDiagram in the Resource Editor
  • Create a SearchPath in the AllowedClass for class Process and define the selector Process:Process as path

image42 image42

  • Close and re-open the Domain Diagram SystemA in the Diagram Editor
  • Open the Content Assist in the search field and select ProcessA from the proposals

image43 image43

Info

Note that the process selected in the search function has been colored (blue).

Part VI Add labels to ports

image44 image44

Finally, we want to display the name of a port as label in the Domain Diagram Editor:

  • Open PortOutShape in the Resource Editor
  • Use the Content Assist to add a borderShape statement that refers to NameBorderShape

image45 image45

  • Open SystemDiagram in the Resource Editor
  • Add a FigureLabelSelector with the selector Port_Out.name as Decorator to labelSelector

image46 image46

  • Open SystemA in the Diagram Editor
  • Check that the name of outgoing ports are now displayed as labels next to their ports
  • Try to move and re-position the labels (in the Select Mode)
  • We want to specify the behavior of our coummicating processes: ProcessA should be a simple coin machine that is connected to a dispenser ProcessB
  • We create an UML State Machine that defines the behavior of ProcessA and link the state machine to our Domain Diagram

image47 image47

First, we make all (built-in) resources needed to build UML diagrams available in our project:

  • Right-click on the project ch.actifsource.tutorial.diagramm.ports and choose Properties from the menu
  • Select actifsource in the opened Properties dialog and click on Add Builtin
  • Select UML from the opened built-in dependency Selection dialog and close both dialogs by clicking OK

image48 image48

We create a ch.actifsource.solution.uml.statediagram.generic.simple.Statemachine called ProcessA_State_Machine as described in Actifsource Tutorial – UML Statemachine in the package ch.actifsource.tutorial.diagramm.ports.specific.

image49 image49

We add a reference to an UML state machine (that describes the behavior of the Process) to Process

  • Open Process in the Resource Editor
  • Add a UseRelation called statemachine to Process
  • Define the range of the relation as ch.actifsource.solution.uml.statediagram.generic.simple.Statemachine

image50 image50

  • Open SystemA in the Resource Editor
  • Create a statemachine statement that referers to ProcessA_State_Machine to ProcessA

image51 image51

We define an action that is triggered by double-clicking on a process shape in our Domain Diagram and opens the UML state machine associated with the corresponding Process

  • Open SystemDiagram in the Resource Editor
  • With the help of the Content Assist, add an OpenDiagram_DoubleClickAction to the AllowedClass for the class Process
  • Create a DiagramSelectorActionProperty as Decorator for shapeActionProperty and define the selector Process.statemachine.stateDiagram (i.e., the action should open the selected diagram)

image52 image52

  • Open the Domain Diagram SystemA in the Diagram Editor
  • Double-Click on ProcessA and make sure that the diagram ProcessA_State_Machine is automatically opened in the Diagram Editor

actifsource-point-large

Code Snippet

logo-large

Tutorial Actifsource Tutorial – Code Snippet
Required Time - 120 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – State Machine
Goal - Add conditional expression to a transition
- Add code as an action to a transition which will be executed together with the transition
Topics covered - Code Snippet Editor
- Code templates to generate code from code snippets
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Create a meta-model for Statemachine instantiate Statemachine and write a code template to generate a simple implementation of your Statemachines in C++ as seen in the Actifsource Tutorial State Machine

image2 image2

  • Add a Code Snippets with conditional expressions to Transition
  • Create a Domain Diagram for an instance of Statemachine and show the conditions for Transitions in the diagram
  • Generate code for Statemachines that checks the associated condition before executing a transition
  • Add a Code Snippet with an action to Transition and generate code that executes the action together with the state transition

Part I Preparation

image3 image3

Setup a project ch.actifsource.tutorial.statemachine.code with a meta-model for Statemachine create two instances of Statemachine and implement a code template for Statemachine as seen in the Actifsource Tutorial State Machine:

  • Prepare a new Actifsource Project ch.actifsource.tutorial.statemachine.code
  • Create a meta-model for Statemachine
  • Create two instances of type Statemachine namely Statemachine1 and Statemachine2
  • Write a code template StatemachineImpl for the type Statemachine
  • Use the package structure shown above

Part II Implement conditional transitions

image4 image4

First, we import all the resources needed to enable the support of Code Snippets in our project:

  • Select the project ch.actifsource.tutorial.statemachine.code and choose Project->Properties from the main menu
  • In the properties dialog choose Actifsource and go the Built-in Dependencies tab
  • Click on Add Builtin
  • In the dialog Select a built-in dependency choose CODESNIPPET and click on OK

image5 image5

  • Close the Properties dialog by clicking on OK

image6 image6

We add a Code Snippet relation to class Transition:

  • Open the class Transition in the Resource Editor
  • Add a (third) property to the class
  • Choose StructuredCodeSnippetRelation in the dialog Type Selection

image7 image7

  • Insert condition as name of the relation
  • Create a new CodeSnippetRelationAspect as shown above
  • Choose Cardinality0_1 as subjectCardinality and as objectCardinality
  • Create a new language statement by calling the Content Assist and choosing CMinusCondition

image8 image8

We add a new Composition called variable to the class Statemachine:

  • Open Transition in the ResourceEditor
  • Add a new property and choose Composition in the Type Selection dialog
  • Insert variable as the name of the relation
  • Choose new ch.actifsource.core.Class as the range with the support of the Content Assist

image9 image9

  • Insert Variable as name of the newly created class, which is opened automatically in the Resource Editor

image10 image10

A conditional expression for a Transition should be able to use all Variables that are owned by the Statemachine of the Transition as variables:

  • Insert a RelationTokenProvider
  • Define the Selector Transition.-transition.-state.counter which selects all Variables that are owned by the Statemachine of the Transition
  • Choose ch.actifsource.codesnippet.metamodel.TokenType.Variable as tokenType

image11 image11

We add a condition to the state transition triggered by the event start that restricts the number of times the Statemachine can switch to the State Started

  • Open the instance Statemachine1 in the ResourceEditor
  • Add two statements for variable to Statemachine1
  • Choose startCounter as the name of the first and startLimit as the name of the second Variable

image12 image12

image13 image13

We add a conditional expression to the state transition triggered by the Event start in the State Initialized

  • Open the state Initialized in the Resource Editor and then open its Transition start
  • Open the Code Snippet Editor by selecting the relation condition and pressing Enter
  • Call the Content Assist in the Code Snippet Editor and choose startCounter
  • Enter ' < ' in the Code Snippet Editor and call the Content Assist again
  • Choose startLimit in the Content Assist

image14 image14

We enforce that the Statemachine can only switch a maximum of startLimit times to the State Started by adding the same conditional expression also to the Transition triggered by the Event start in the State Stopped

  • Enter the conditional expression in the same way as on the previous page

Part III Create a Domain Diagram

image15 image15

We create a new Diagram Type called Statemachine in order to define properties of Domain Diagrams of Statemachines:

  • Select the package ch.actifsource.tutorial.statemachine.code.generic and choose New -> Diagram Type

image16 image16

  • Enter Statemachine as name for the newly created DiagramType in the New DiagramType Wizard
  • Choose ch.actifsource.tutorial.statemachine.code.generic.Statemachine as RootClass

image17 image17

  • Define allowedClass as ch.actifsource.tutorial.statemachine.code.generic.State
  • Choose ShowPaletteEntry as paletteEntry
  • Insert an allowedRelation of type AllowedIndirectRelation with selector State.transition.targetState

image18 image18

Now we create a new Domain Diagram for Statemachine1 based on the newly created Diagram Type:

  • Select ch.actifsource.tutorial.statemachine.code.specific and choose New -> Domain Diagram

image19 image19

  • Check the chosen settings in the open dialog and click Finish

image20 image20

image21 image21

  • Choose Select in the Palette of the Diagram Editor and arrange the States such that all transitions are visible

image22 image22

Next, we will see how to display the conditional expressions associated with a Transition in the Domain Diagram. First, we create a function that generates the displayed text from the conditional expression:

  • Select the package ch.actifsource.tutorial.statemachine.code.generic and choose New -> FunctionSpace

image23 image23

  • Enter NameFunctions as name of the FunctionSpace

image24 image24

  • Create a new FunctionContext with typeRef ch.actifsource.tutorial.statemachine.code.generic.Transition
  • Create a new function in the FunctionContext and choose TemplateFunction in the Type Selection dialog

image25 image25

  • Enter displayName as name of the TemplateFunction
  • Open the TemplateFunction in the Template Function Editor by double-clicking on displayName in the Project Explorer

image26 image26

The function should display the name of the event triggering the Transition and in brackets the conditional expression if there is one:

  • Enter Transition.event.name in the TemplateEditor followed by '[]'
  • Place the cursor inside the brackets and choose Insert ColumnContext from the menu

image27 image27

  • Choose Transition.condition as selector for the column context
  • Enter CodeSnippet.displayCodeSnippetSingleLine@DisplayCodeSnippet in the column context. This function outputs a string that represents the expression in the Code Snippet as entered by the user, i.e., without parsing or processing it

image28 image28

We will use the newly created function displayName to define a NameAspect for Transitions

  • Create a NameAspect with the Content Assist and choose TextSelectorAspectImplementation in the Select Decoration Type dialog

image29 image29

  • Enter Transition.displayName@NameFunction as selector of the NameAspect, i.e., the name of the Transition will be the output of the function we have defined before

image30 image30

  • Open the Statemachine1 Domain Diagram again and check that the Transitions are now displayed with their name including the conditional expressions as specified above

Part IV Generate code for conditional transitions

image31 image31

In this part, we will extend the template StatemachineImpl as implemented in the Actifsource Tutorial State Machine such that the statemachine executes a state transition only if the associated condition is fulfilled:

  • Open the template StatemachineImpl in the Template Editor

image32 image32

We write an if-statement with the conditional expression associated with a Transition as condition:

  • Insert a new Line Context and write the selector Transition.condition for the newly created context

image33 image33

  • Write an if-statement in the new line context and insert a call to the function toC@CodeSnippetToCode on the CodeSnippet available in the this context as condition of the if-statement
  • Add opening and closing braces around the existing assignment expression

image35 image35

  • Open the generated files Statemachine1Impl.hpp (overwritten) and Statemachine2Impl.hpp (unchanged) and inspect the changes.

Part V Customized variable names

image36 image36

  • The built-in template functions that we used so far generate the name of variables (and also functions) by calling simple name on the corresponding resource
  • In this part we will change the generated variable names by adding a prefix to the variable names according to our naming convention

image37 image37

  • Create a new Java source folder: select the project ch.actifsource.tutorial.statemachine.code and choose New -> Source Folder from the menu

image38 image38

  • Insert aspects as name of the new folder

image39 image39

image40 image40

  • Create a new package ch.actifsource.tutorial.statemachine.code.generic in the aspects folder: select the aspects folder and choose New -> Package from the menu

image41 image41

  • Select the package ch.actifsource.tutorial.statemachine.code.generic in the folder aspects and choose New -> Interface from the menu
  • Write IMyNameProvider as name of the new interface
  • Choose ch.actifsource.codesnippet.metamodel.template.INameProvider as Extended interface

image42 image42

  • Select the package ch.actifsource.tutorial.statemachine.code.generic in the folder aspects and choose New -> Class from the menu
  • Write MyNameProviderLiteralAspect as name of the new class
  • Choose ch.actifsource.core.model.aspects.impl.AbstractStatelessAspectImpl as Superclass
  • Choose ch.actifsource.core.model.aspects.impl.IGenericLiteralAspect<IMyNameProvider> as Interface
  • Click Finish
package ch.actifsource.tutorial.statemachine.code.generic;

import javax.annotation.CheckForNull;

import ch.actifsource.core.INode;
import ch.actifsource.core.Literal;
import ch.actifsource.core.job.IReadJobExecutor;
import ch.actifsource.core.model.aspects.impl.AbstractStatelessAspectImpl;
import ch.actifsource.core.model.aspects.impl.IGenericLiteralAspect;
import ch.actifsource.core.scope.IResourceScope;

public class MyNameProviderLiteralAspect extends AbstractStatelessAspectImpl implements IGenericLiteralAspect<IMyNameProvider> {

  @Override
  public boolean allowMultiline() {
    return false;
  }

  @Override
  public @CheckForNull String isValid(IReadJobExecutor executor, IResourceScope scope,
    String value) {
    return null;
  }

  @Override
  public Literal create(IMyNameProvider value) {
    return new Literal(value.toString());
  }

  @Override
  public @CheckForNull String getJavaConstructionExpression(IReadJobExecutor executor,
    IResourceScope scope, INode node) {
    return null;
  }

  @Override
  public @CheckForNull IMyNameProvider getValue(IReadJobExecutor executor,
    IResourceScope scope, INode node) {
    return null;
  }

  @Override
  public Class<IMyNameProvider> getValueType() {
    return IMyNameProvider.class;
  }

}
  • In the newly created class remove all TODO comments
  • Write the statement return MyNameProvider.class; in the method getValueType()
  • Write the statement return new Literal(value.toString());

image44 image44

  • Create a new Literal type: select the package ch.actifsource.tutorial.statemachine.code.generic in the folder asrc and choose New -> Resource from the menu
  • Choose the type ch.actifsource.core.Literal as Type of the new Resource
  • Write MyNameProviderLiteral as Name of the new Resource

image45 image45

  • Open the new Literal in the Resource Editor
  • Create a LiteralAspect with type JavaAspectImplementation and choose the class ch.actifsource.tutorial.statemachine.code.generic.MyNameProviderLiteralAspect as className
  • Let the MyNameProviderLiteral extend ch.actifsource.codesnippet.metamodel.parsetree.template.NameProvider, which is the default NameProvider and generates names by calling simpleName@BuiltIn

image46 image46

  • Create a new FunctionSpace Select the package ch.actifsource.tutorial.statemachine.code.generic in the asrc folder and choose New -> FunctionSpace
  • Insert TokenNameFunctions as the name of the FunctionSpace and click Finish

image47 image47

  • Let the new FunctionSpace TokenNameFunctions extend from TokenToName

image48 image48

  • Open the FunctionSpace TokenNameFunctions in the Resource Editor
  • Create a new FunctionContext with typeRef MyNameProviderLiteral
  • Create a new function and choose TemplateLineFunction from the Type Selection dialog

image49 image49

  • Insert variableName as the name of the new TemplateLineFunction
  • Create a parameter Param of type ClassType and with classRef ch.actifsource.core.Resource
  • Insert m_Resource.simpleName@BuiltIn as text, i.e., the function appends the prefix m_ to the output of Resource.simpleName@Builtin
  • Warning: Please choose the exact function name for variableName or functionName since these functions are overwritten

image50 image50

  • Create a new FunctionContext with typeRef Statemachine
  • Create a new function and choose JavaFunction from the Type Selection dialog

image51 image51

  • Insert generateNameProvider as name of the function
  • Create a statement returnType of type LiteralType with literalRef MyNameProviderLiteral

image52 image52

    @Override
    public ch.actifsource.tutorial.statemachine.code.generic.IMyNameProvider generateNameProvider(final ch.actifsource.tutorial.statemachine.code.generic.javamodel.IStatemachine statemachine) {
      /* Begin Protected Region [[835774eb-ee6c-11ef-8f29-099ac721970d]] */
      return new IMyNameProvider() {};
      /* End Protected Region   [[835774eb-ee6c-11ef-8f29-099ac721970d]] */
    }
  • Save the FunctionSpace TokenNameFunctions
  • Open the newly generated file TokenNameFunctions.java in the Java Editor
  • Write the statement return new IMyNameProvider(){} inside the protected region in the method body of the method generateNameProvider
  • Save the file

image54 image54

  • Open the template StatemachineImpl in the Template Editor
  • Insert a new LineContext on the line after the case expressions
  • Choose Transition.condition as the selector of the new context

image55 image55

  • Insert a new LineContext on the same line
  • Choose Statemachine.generateNameProvider@TokenNameFunctions:NameProvider as selector of the new context
  • Write an if-statement with CodeSnippet.toCwithNameProvider@CodeSnippetToCode
Info

Note that there is an error on the edited line because the parameter to the function cannot be resolved

image56 image56

  • Insert a new line context on the same line and choose CodeSnippet:CodeSnippet (This dummy context allows Actifsource to correctly and automatically resolve the parameter to the function from the contexts)

  • Save the template and make sure that the code is generated

image58 image58

  • Open the file Statemachine1Impl.hpp and check that the variable names have been generated with the defined prefix "m_"

Part VI Implement actions for transitions

image59 image59

In this part, we will see how to add an action to a transition. We add the code corresponding to the action as a Code Snippet to the model. This code will be executed together with the transition:

  • Open the class Transition in the Resource Editor and add a Code Snippet relation as already seen in Part II
  • Insert action as name of the StructuredCodesnippetRelation choose subjectCardinality and objectCardinality Cardinality0_1
  • Create a RelationTokenProvider with selector Transition.-transition.-state.variable and tokenType Variable
  • Choose the language CMinus

image60 image60

We will now increment the startCounter each time that we switch to the State Started:

  • Open Statemachine1 in the Resource Editor
  • Add an action to the State Initialized and insert the code startCounter = startCounter + 1; into the Code Snippet Editor
  • Add an action to the State Stopped and insert the code startCounter = startCounter + 1; into the Code Snippet Editor

image61 image61

  • Open the template StatemachineImpl in the Template Editor
  • Add a new line context after the assignment statement that updates the state
  • Choose Transition.action as the selector of the state (to insert code for Transitions which have an action defined)
  • Call the function toCwithNameProvider@CodeSnippetToCode on the CodeSnippet in the new line context
Info

Note that there is an inconsistency because we have not yet added a NameProvider to our contexts which can be used as the parameter to the function

image62 image62

  • Add a new line context on the same line as before and choose Statemachine.generateNameProvider@TokenNameFunctions:NameProvider as selector of the context
  • Add another line context on the same line and choose the selector CodeSnippet:CodeSnippet (needed for the parameter matching)
  • Save the template and make sure that the code in Statemachine1Impl.hpp is generated and overwritten

image64 image64

  • Open the file Statemachine1Impl.hpp and check that the code that increments the counter has been correctly inserted
  • Complete the generated classes by adding a member function initialize() and the missing variables (and probably adding the cases for the missing enumeration values to make the compiler happy).

actifsource-point-large

UML Statemachine

logo-large

Tutorial Actifsource Tutorial – UML Statemachine
Required Time - 70 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – Domain Diagram Typ
- Actifsource Tutorial – Domain Diagram Type II
Goal - Create UML State Machines using the built-in Actifsource solution
Topics covered - Create UML State Machines with states, superstates, history states, (entry, exit, state) actions and transition guards
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

image2 image2

  • Design an UML state machine for a simple coin machine process and create a state diagram that represents the UML state machine:

Part I Preparation

image3 image3

  • Create a new Actifsource project with the name ch.actifsource.tutorial.umlstatemachine

  • Change to the tab Built-in Dependencies in the New Actifsource Project dialog

  • Add the built-in dependency UML (which makes all resource needed to build and represent UML state machines available in our new project).

  • Close both dialogs by clicking OK and Finish

Part II Design an UML State Machine

image4 image4

  • Create a new resource of type ch.actifsource.solution.uml.statediagram.generic.simple.Statemachine

  • Enter CoinMachineStateMachine as the name of the new resource

Design an UML State Machine

image5 image5

  • Open the state diagram of CoinMachineStateMachine StateDiagram_1, in the Domain Diagram Editor

image6 image6

First, we create two superstates, called NormalMode and DiagnosticMode:

  • Select SuperState from the Palette and left-click in the Diagram Editor to create a superstate

  • Enter NormalMode as the name of the new SuperState in the New Resource Wizard

  • In the same way, create a SuperState called DiagnosticMode

  • Select Start from the palette and right-click in the Diagram Editor to create a start state (i.e., the default or initial state of the state machine)

  • In the Select mode, you can now re-size and re-position the states as usual in the Diagram Editor

image7 image7

  • Select Relation from the Palette and insert a relation from the start state symbol to the superstate NormalMode

image8 image8

Now, we create nested states to define the behavior in the NormalMode

  • Select State from the Palette and left-click in the lower section of the NormalMode state to create a nested state in the superstate NormalMode

  • Enter the name Locked as name of the State in the New Resource Wizard

  • In the same way create the two nested states Locked and Empty in the NormalMode and the two nested states TestLock and TestCoin in the superstate DiagnosticMode

image9 image9

  • Select Start from the Palette and left-click in the lower section of the NormalMode state (see above) to create a default or start state

  • As before, select Relation from the Palette and create a relation from the start state to the state Locked

  • In the same way, create a start state in the DiagnosticMode and create a relation from this start state to the state TestLock

image10 image10

Next, we define the state transitions and events:

  • Select Relation from the Palette and create a relation from the state Locked to the state Unlocked

  • With Control+Click on the GUID of the newly created relation, you can now open the transition in the Resource Editor

image11 image11

  • In the Resource Editor, create a new Event for the transition from state Locked to Unlocked

  • Give the name Coin to the newly created event

image12 image12

  • Switch to the open StateDiagram_1 in the Diagram Editor and check that the transition from Locked to Unlocked is now labeled 'Coin'

  • In the same way, create the following transition and events: Unlocked Empty Empty TestCoin TestLock

image13 image13

We want to create a condition that is only true if the machine is non-empty. Thereto, we introduce a variable stockItems that keeps track of the number of items left in the machine:

  • Open CoinMachineStateMachine the Resource Editor
  • Add a PrivateVariableField to the CoinMachineStateMachine
  • Create a VariableField with name stockItems and with type INTEGER as field

image14 image14

Next, we add guards to transitions such that the corresponding transitions only fire if the guard evaluates to TRUE:

  • By Control+Click on the transition Unlocked open the transition in the resource editor
  • Use the Content Assist to create a new ModelGuardImpl named hasStockItems as guard of the transition (see above)

image15 image15

  • Add a GreaterExpression as booleanExpression to the ModelGuardImpl
  • Create an operand1 of type VariableFieldExpression with a fieldRef with the VariableField stockItems as field
  • Create an operand2 of type LiteralExpression with value
  • Close the booleanExpression:
Info

Note that the Boolean expression stockItems > 0 is now displayed to represent the condition of the guard

image16 image16

image17 image17

Next, we add actions that are executed together with transitions and introduce shared functions which can be used as actions by multiple transitions:

  • Open CoinMachineStateMachine in the Resource Editor
  • Create a new SharedFunction called lightOff as sharedFunction to CoinMachineStateMachine
  • Create a new ManualFunctionImpl with viewName lightOff as functionImpl to the SharedFunction

image18 image18

  • Add a transitionFunction of type ManualFunctionImpl to the transition Locked (see above)

  • In the same way create the following transitionFunctions of type ManualFunctionImpl:

    • rejectCoin Empty
    • lightOn TestCoin

image19 image19

  • Add a transitionFunction of type SharedFunctionRef to the transition TestLock which uses the sharedFunction lightOff

image20 image20

When the event Refilled occurs, the variable stockItems (i.e, the private variable that counts the number of stock items) should be set to the initial numbers of items:

  • Add a transitionFunction of type ModelFunctionImpl to the transition Empty
  • Add a statement of type Assignment to the ModelFunctionImpl
  • Insert a fieldRef with field stockItems
  • Add an operand of LiteralExpression with value INITIAL_STOCK_ITEMS

image21 image21

Each time the machine is unlocked, the number of stock items should be decremented by one:

  • Create a new ModelFunctionImpl named decrementStockItems as entryFunction of the state Unlocked
  • Add an Assignment as statement with an operand of type DecExpression
  • Add an operand of type VariableFieldExpression to the DecExpression
  • Add a fieldRef of type FieldRef to the VariableFieldExpression and use stockItems as field

image22 image22

  • Open the StateDiagram_1 in the Diagram Editor and check that all the actions are displayed correctly as shown above

image23 image23

We add a transition that is triggered by an event Diagnose from the NormalMode to the DiagnosticMode (i.e., a technician should be able to switch to this diagnose state from any state in the normal mode). To save the state of the machine before switching modes, we introduce a history state:

  • Add a history state by selecting History from the Palette
  • Insert a transition triggered by a new event Return from the DiagnosticMode to the history state
  • Create a transition triggered by a new event Diagnose from the NormalMode to the DiagnosticMode

image24 image24

Since the state of the DiagnosticMode is not saved before returning to the NormalMode, the light should be switched off when entering the diagnostic mode:

  • Open the CoinMachineStateMachine in the Resource Editor
  • Add an entryFunction of type SharedFunctionRef to the DiagnosticMode and use lightOff as the sharedFunction
  • The entry function is now displayed when selecting the DiagnosticMode in the Diagram Editor (see above)

Part III Generate code from an UML State Machine

image25 image25

Finally, we want to generate code that implements the specified UML state machine:

  • Right-click on the project ch.actifsource.tutorial.umlstatemachine in the Project Explorer and select Properties from the menu
  • Select actifsource in the Properties dialog and go to the Target Folder tab
  • Click on Add Target Folder, create a new folder called src, select this folder and click OK
  • Select the folder src and click on Add BuildConfig and choose the build configuration StateDiagram_C from the dialog. Close both dialogs by clicking OK

image26 image26

  • Open the folder src and make sure that the two files Statemachine_CoinMachineStateMachine.c and Statemachine_CoinMachineStateMachine.h have been generated and inspect the generated code
  • If the two files have not been generated, check that the option Generate Automatically is active. If not, the code can also be generated manually as follows: right-click on the project in the Project Explorer and choose Generate Code from the menu.

image27 image27

actifsource-point-large

Meta Model Documentation

logo-large

Tutorial Actifsource Tutorial – Meta Model Documentation
Required Time - 20 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
Goal - Learn how to document your own Meta Model
- Generating browsable HTML documentation
Topics covered - Meta Model Documentation Builtin model
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Install Graphviz
  • Create your meta model
  • Prepare your project
  • Create the documentation model

Part I Install Graphviz

image2 image2

  • Install the graphviz tool from www.graphviz.org
  • Make sure that graphviz is added to your system path
  • The Actifsource meta model documentation generator is looking for the graphviz executable dot.exe in your system path.

Part II Create your meta model

  • Create a simple meta model as shown in the Actifsource Tutorial Simple Service
  • We recommend to make a new project for this tutorial ch.actifsource.tutorial.metamodel.docu
  • Make sure to use a Class Diagram for the meta model design

Create your meta model

image3 image3

  • Create a simple meta model as shown in the Actifsource Tutorial Simple Service
  • Use a Class Diagram named Design

image4 image4

  • Add proper comments to all classes, relations and attributes

Part III Prepare your project

  • Add a Builtin Dependency to DOCUMENTATION_METAMODEL
  • Add a target folder to generate the documentation

Prepare your project

image5 image5

  • Open the properties of your project
  • Add a Builtin Dependency to DOCUMENTATION_METAMODEL

image6 image6

  • Open the properties of your project
  • Add a new Target Folder docu
  • Add the Build Config Documentation_MetaModel_html to the Target Folder
  • Make sure you have added the Builtin Dependency to DOCUMENTATION_METAMODEL before

Part IV Create the documentation model

  • Instantiate a new resource of type Documentation
  • Add chapters and sub chapters to your documentation

Create the documentation model

image7 image7

  • Select a resource folder
  • Create a new resource of type Documentation using the new resource tool

image8 image8

Create a new resource named Service Documentation of type Documentation

image9 image9

  • Open the resource Service Documentation
  • Add some descriptions where needed
  • Add a new Chapter named Service Design
  • Make sure to refer to your Class Diagram named Design
  • Save your resource

image10 image10

  • Find the generated html documentation in the Target Folder docu

actifsource-point-large

CIP Tool

CIP State Machine - Lamp Legacy

Design a simple state machine that allows you to switch on a lamp, while switching it off is delayed. This tutorial is intended for users of the old CIP application. more…

CIP State Machine - Lamp

Design a simple state machine where you can switch on a lamp while switching off will be delayed. more…

CIP State Machine - Test Suite - Console

Learn how to specify a CIP Test Suite model and how to run unit tests on your CIP state machine. more…

CIP State Machine - Arduino

Learn how to download and run the generated C code from your CIP machine on the Arduino platform. more…

Subsections of CIP Tool

CIP Statemachine - Lamp

logo-large

Tutorial Actifsource Tutorial – CIP Statemachine - Lamp
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – Installing Actifsource
-Actifsource Tutorial – Simple Service
Goal - Creating a state machine using the CIP method
- Generating real time C code for any embedded system
Topics covered - Setting up a new CIP Project
- Communicating with the Outer World
- Specify the State Machine
- Generating State Machine Code
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Learn how to specify a simple state machine

  • Example

    • Button to turn on and off a lamp
    • Turning off the lamp shall be delayed
  • CIP Method

    • The CIP System is the root element

    • The CIP System consists of Clusters

      • Clusters are used to model distributed state machines
    • The CIP Cluster consists of Processes

      • The process declares the state of the state machine
    • The CIP Process consists of Modes

      • Modes are used for different situations like normal, error, run-in, run-out
      • The mode declares the transitions between the states

Part I Setting up a new CIP Project

  • Create a new CIP Project with the CIP Project wizard

image2 image2

  • Prepare a new Actifsource/CIP Project using the Actifsource CIP wizard

    • File/new/other
    • Actifsource/CIP Project
  • Click Next

image3 image3

  • Specifiy Project name
  • Specify Project type
  • Click Next

image4 image4

  • You may add other build configs (i.e. test suites) as needed
  • Click Finish
Info

Note that the BuildConfigs in TargetFolder are equivalent to the previously selected project type

image5 image5

  • Link with Editor
  • Enable Actifsource Presentation Flag Group Aggregations By Relations

Part II Communicating with the Outer World

  • Let’s communicate with the outer world
  • Channels are providing messages from physical device

Communicating with the Outer World

image8 image8

  • Open the Communication Diagram (if not already open)

    • Double-Click on CommunicationDiagram in the Tree View of resource Lamp_CipSystem
    • A new Communication Diagram editor will open on the left

image9 image9

  • Create two new Channels named Button and Lamp using the Channel tool from the Palette

image10 image10

  • Arrange the Graphical Editor and the Resource Editor together on the same screen as shown above

  • Add the two ChannelMessages Push and Release to the Channel Button

    • Ctrl+Click on the Button label
    • Add ChannelMessage Push and ChannelMessage Release
  • Add the two ChannelMessages Bright and Dark to the Channel Lamp

    • Ctrl+Click on the Lamp label
    • Add ChannelMessage Bright and ChannelMessage Dark
  • Messages are given as function calls from the other world to the state machine and vice versa

image11 image11

  • The CIP Method specifies that every physical process needs a logical counterpart in the model
  • Add the two Processes Button and Lamp to the Cluster LampCluster
Info

Note that different Clusters may run on different processors. This allows you to design distributed state machines using the CIP Method.

image12 image12

  • Channels are Delivering Messages to a Process via Port. Doing so allows you to consider the Process to a self-consistent component.
  • Create an Inport ButtonPort and a relation from the Channel Button to the Port ButtonPort
  • Create an Outport LampPort and a relation from the Port LampPort to the Channel Lamp

image13 image13

  • Since every Process is a self-consistent component we have to specify a Message interface on the port to. The = tool in the Message Translation helps us to create the same messages as found on the Channel also on the corresponding Port.

  • Configure the Message Translation between the Channel Button and the Process Button

    • Double-Click on the hexagon of the relation between the Channel Button and the Process Button
    • Select the ChannelMessages Button.Push and Button.Release
    • Use the =-Tool to create the corresponding Messages on the Port ButtonPort of the Process Button
  • Configure the Message Translation between the Process Lamp and the Channel Lamp

    • Double-Click on the hexagon of the relation between the the Process Lamp and the Channel Lamp
    • Select the ChannelMessages Lamp.Bright and Lamp.Dark
    • Use the =-Tool to create the corresponding Messages on the Port LampPort of the Process Lamp

Part III Specify the State Machine

  • We are now set to specify the state machines for each process

  • Note that the CIP Method knows so called Modes

    • A Process can have one or more Modes
    • States are declared by the Process
    • Transitions are declared by the Mode
  • Making this difference it becomes possible to provide several Modes for several situations

    • Normal Mode
    • Error Mode
    • Run-In Mode
    • Run-Out Mode
  • There are the following rules

    • States are defined in the Process
    • States are shared for every Mode
    • Transitions are defined in the Mode

Specify the State Machine

image14 image14

  • Navigate the Resource View of Lamp_CipSystem down up you see Button_normal
  • Double-Click on Button_normal. Actifsource will automatically open new StateDiagram

image15 image15

  • Enter two new States Released and Pushed using the Palette
  • State are shared for every mode
  • Enter the desired State name Released and Pushed

image17 image17

  • Create a new Transition from State Released to State Pushed using the Relation Tool from the Palette
  • Create a new Transition from State Pushed to State Released using the Relation Tool from the Palette

image18 image18

  • Every Transition needs an input to be triggered
Info

Note that the Actifsource Validator marks all resources that are incomplete

  • Add the input message to Transition from State Released to State Pushed

    • Ctrl-Klick on the italics label Input
    • Select the InportMessage Push
  • Add the input message to Transition from State Pushed to State Released

    • Ctrl-Klick on the italics label Input
    • Select the InportMessage Release
Info

Note that you now selecting the Messages that we have previously created on the Port Button using the =-Tool in the Message Translation

image19 image19

  • Use Messages to communicate with Processes from the outer world

  • Use Pulses to communicate between Processes within the same Cluster

  • Add the Outpulse On to Transition from State Released to State Pushed

    • Ctrl-Klick on the italics label Outpulse

    • Enter the desired Outpulse named On and press Ctrl-Space

      • Select an existing Outpulse or
      • Create a new Outpulse (as we do in our example)
  • Add the Outpulse Off to Transition from State Pushed to State Released

image20 image20

  • Set the Init-State to specify the State to start with

    • Open the LampCluster in the Resourceeditor
    • Set the initstate to Released State

image21 image21

  • Use Pulses to communicate between Processes within the same Cluster
  • The PulseCastDiagram specifies which Processes sends Pulses to which other Processes
  • Navigate the Resource View of Lamp_CipSystem down up you see PulseCastDiagram
  • Double click on PulseCastDiagram. Actifsource will automatically open new PulseCastDiagram

image22 image22

  • Add the Process Button and the Process Lamp to your PulseCastDiagram

    • Right-Click on the Diagram
    • Show Resource
    • Select Button and Lamp
  • Connect the Process Button and the Process Lamp using the Relation Tool from the Palette

  • Configure the Pulse Cast between the Process Button and the Process Lamp

    • Double-Click on the circle of the relation between the the Process Button and the Process Lamp
    • Select the Outpulses Button.On and Button.Off
    • Use the =-Tool to create the corresponding Inpulses on the Process Lamp

image23 image23

  • Double-Click on Process Lamp to open the StateDiagram

image24 image24

  • Open the StateDiagram for ProcessLamp (if not already done)

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1
  • Create States Dark Bright and Delayed

  • Make State Dark the Init-State

  • Create Transition as shown above

    • Select Pulses which have been created in the Pulse Translation
    • TIMEUP is a special pulses emitted if timer expires
    • Select Lamp Messages to the outer world

image25 image25

  • Start Timer in Transition #2

    • Ctrl-Click in label Ext
    • Select SET_TIMER
    • Specify DelayOperation (see next page)
  • Stop Timer in Transition #4

    • Ctrl-Click in label Ext
    • Select STOP_TIMER

- Specify the State Machine

image26 image26

  • Create a SetTimer_DelayText
  • The DelayText shall return the delay in system ticks

Part IV Generating State Machine Code

  • We have to define the details for the state machine implementation to generate the code

Generating State Machine Code

image27 image27

  • Create a new Implementation for System System1
  • On the System View Right-Click on System1
  • Create a new Implementation

image28 image28

  • Create a new Implementation as shown above

image29 image29

  • Find the generated code in the folder cip-gen
  • Find the documentation (html) code in the folder cip-gen

actifsource-point-large

CIP Statemachine - Lamp Legacy

logo-large

Tutorial Actifsource Tutorial – CIP Statemachine - Lamp
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – Installing Actifsource
-Actifsource Tutorial – Simple Service
Goal - Creating a state machine using the CIP method
- Generating real time C code for any embedded system
Topics covered - Setting up a new CIP Project
- Communicating with the Outer World
- Specify the State Machine
- Generating State Machine Code
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Learn how to specify a simple state machine

  • Example

    • Button to turn on and off a lamp
    • Turning off the lamp shall be delayed
  • CIP Method

    • The CIP System is the root element

    • The CIP System consists of Clusters

      • Clusters are used to model distributed state machines
    • The CIP Cluster consists of Processes

      • The process declares the state of the state machine
    • The CIP Process consists of Modes

      • Modes are used for different situations like normal, error, run-in, run-out
      • The mode declares the transitions between the states

Part I Setting up a new CIP Project

  • Create a new CIP Project with the CIP Project wizard

image2 image2

  • Prepare a new Actifsource/CIP Project using the Actifsource CIP wizard

    • File/new/other
    • Actifsource/CIP Project
  • Click Next

image3 image3

  • Specifiy Project name
  • Specify Project type
  • Click Next

image4 image4

  • You may add other build configs (i.e. test suites) as needed
  • Click Finish
Info

Note that the BuildConfigs in TargetFolder are equivalent to the previously selected project type

image5 image5

  • Link with Editor
  • Enable Actifsource Presentation Flag Group Aggregations By Relations

image6 image6

  • Open CIP System View

    • Window/Show View/Other…
    • Actifsource – CIP / System

image7 image7

Part II Communicating with the Outer World

  • Let’s communicate with the outer world
  • Channels are providing messages from physical device

Communicating with the Outer World

image8 image8

  • Open the Communication Diagram (if not already open)

    • Right Click on System1 in the System View
    • Select CommunicationDiagram from the context menu
    • Open CommunicationDiagram_1

image9 image9

  • Create two new Channels named Button and Lamp using the Channel tool from the Palette

image10 image10

  • Arrange the Graphical Editor and the Resource Editor together on the same screen as shown above

  • Add the two ChannelMessages Push and Release to the Channel Button

    • Ctrl+Click on the Button label
    • Add ChannelMessage Push and ChannelMessage Release
  • Add the two ChannelMessages Bright and Dark to the Channel Lamp

    • Ctrl+Click on the Lamp label
    • Add ChannelMessage Bright and ChannelMessage Dark
  • Messages are given as function calls from the other world to the state machine and vice versa

image11 image11

  • The CIP Method specifies that every physical process needs a logical counterpart in the model
  • Add the two Processes Button and Lamp to the Cluster LampCluster
Info

Note that different Clusters may run on different processors. This allows you to design distributed state machines using the CIP Method.

image12 image12

  • Channels are Delivering Messages to a Process via Port. Doing so allows you to consider the Process to a self-consistent component.
  • Create an Inport ButtonPort and a relation from the Channel Button to the Port ButtonPort
  • Create an Outport LampPort and a relation from the Port LampPort to the Channel Lamp

image13 image13

  • Since every Process is a self-consistent component we have to specify a Message interface on the port to. The = tool in the Message Translation helps us to create the same messages as found on the Channel also on the corresponding Port.

  • Configure the Message Translation between the Channel Button and the Process Button

    • Double-Click on the hexagon of the relation between the Channel Button and the Process Button
    • Select the ChannelMessages Button.Push and Button.Release
    • Use the =-Tool to create the corresponding Messages on the Port ButtonPort of the Process Button
  • Configure the Message Translation between the Process Lamp and the Channel Lamp

    • Double-Click on the hexagon of the relation between the the Process Lamp and the Channel Lamp
    • Select the ChannelMessages Lamp.Bright and Lamp.Dark
    • Use the =-Tool to create the corresponding Messages on the Port LampPort of the Process Lamp

Part III Specify the State Machine

  • We are now set to specify the state machines for each process

  • Note that the CIP Method knows so called Modes

    • A Process can have one or more Modes
    • States are declared by the Process
    • Transitions are declared by the Mode
  • Making this difference it becomes possible to provide several Modes for several situations

    • Normal Mode
    • Error Mode
    • Run-In Mode
    • Run-Out Mode
  • There are the following rules

    • States are defined in the Process
    • States are shared for every Mode
    • Transitions are defined in the Mode

Specify the State Machine

image14 image14

  • Open the StateDiagram for Process Button

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1

image15 image15

  • Enter two new States Released and Pushed using the Palette
  • State are shared for every mode
  • Enter the desired State name Released and Pushed

image17 image17

  • Create a new Transition from State Released to State Pushed using the Relation Tool from the Palette
  • Create a new Transition from State Pushed to State Released using the Relation Tool from the Palette

image18 image18

  • Every Transition needs an input to be triggered
Info

Note that the Actifsource Validator marks all resources that are incomplete

  • Add the input message to Transition from State Released to State Pushed

    • Ctrl-Klick on the italics label Input
    • Select the InportMessage Push
  • Add the input message to Transition from State Pushed to State Released

    • Ctrl-Klick on the italics label Input
    • Select the InportMessage Release
Info

Note that you now selecting the Messages that we have previously created on the Port Button using the =-Tool in the Message Translation

image19 image19

  • Use Messages to communicate with Processes from the outer world

  • Use Pulses to communicate between Processes within the same Cluster

  • Add the Outpulse On to Transition from State Released to State Pushed

    • Ctrl-Klick on the italics label Outpulse

    • Enter the desired Outpulse named On and press Ctrl-Space

      • Select an existing Outpulse or
      • Create a new Outpulse (as we do in our example)
  • Add the Outpulse Off to Transition from State Pushed to State Released

image20 image20

  • Set the Init-State to specify the State to start with

    • Open the LampCluster in the Resourceeditor
    • Set the initstate to Released State

image21 image21

  • Use Pulses to communicate between Processes within the same Cluster

  • The PulseCastDiagram specifies which Processes sends Pulses to which other Processes

  • Open the PulseCastDiagram for Cluster Lamp

    • On the System View Right-Click on System1.LampCluster
    • Select PulseCastDiagram
    • Select PulseCastDiagram_1 (or create a new one if necessary)

image22 image22

  • Add the Process Button and the Process Lamp to your PulseCastDiagram

    • Right-Click on the Diagram
    • Show Resource
    • Select Button and Lamp
  • Connect the Process Button and the Process Lamp using the Relation Tool from the Palette

  • Configure the Pulse Cast between the Process Button and the Process Lamp

    • Double-Click on the circle of the relation between the the Process Button and the Process Lamp
    • Select the Outpulses Button.On and Button.Off
    • Use the =-Tool to create the corresponding Inpulses on the Process Lamp

image23 image23

  • Double-Click on Process Lamp to open the StateDiagram

image24 image24

  • Open the StateDiagram for ProcessLamp (if not already done)

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1
  • Create States Dark Bright and Delayed

  • Make State Dark the Init-State

  • Create Transition as shown above

    • Select Pulses which have been created in the Pulse Translation
    • TIMEUP is a special pulses emitted if timer expires
    • Select Lamp Messages to the outer world

image25 image25

  • Start Timer in Transition #2

    • Ctrl-Click in label Ext
    • Select SET_TIMER
    • Specify DelayOperation (see next page)
  • Stop Timer in Transition #4

    • Ctrl-Click in label Ext
    • Select STOP_TIMER

- Specify the State Machine

image26 image26

  • Create a SetTimer_DelayText
  • The DelayText shall return the delay in system ticks

Part IV Generating State Machine Code

  • We have to define the details for the state machine implementation to generate the code

Generating State Machine Code

image27 image27

  • Create a new Implementation for System System1
  • On the System View Right-Click on System1
  • Create a new Implementation

image28 image28

  • Create a new Implementation as shown above

image29 image29

  • Find the generated code in the folder cip-gen
  • Find the documentation (html) code in the folder cip-gen

actifsource-point-large

CIP Test Suite - Console

logo-large

Tutorial Actifsource Tutorial – CIP Test Suite - Console
Required Time - 30 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – [Installing Actifsource]../../..(/tutorials/\10_community/10_install/index.html)
-Actifsource Tutorial – Simple Service
- Actifsource Tutorial – CIP Statemachine - Lamp
Goal - Creating Unit Tests for a CIP Statemachine
Topics covered - Setting up the code options
- Setting up a CIP Test Suite
- Generate the CIP Test Suite
- Generate the CIP Test Suite Documentation
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Learn how to specify a CIPTestSuite model

    • Specify message events (input)
    • Specify message action expectations (output)
  • Run the unit tests

Part I Setting up the CIP project

  • Make sure to properly setup the lamp project as seen in the previous tutorial

image2 image2

  • Create a new CIP Project using the wizard
  • Select CIP_C_Statemachine to generate a CIP state maschine
  • Select CIP_C_TestSuite_Console to generate a console test suite
  • Select CIP_HTML_TestSuite_Documentation to generate a html documentation
  • Click Next >

image3 image3

  • The necessary build configs are automatically added to your target folder
  • Click Finish

image4 image4

  • Create the Lamp state machine as shown in the previous tutorial

image5 image5

image6 image6

  • Set the timer delay to 3 ticks

image7 image7

  • Create a new Implementation in your CIPSystem
  • Select the LampCluster in your CipMachine
  • Select input and output channels
  • Select Default_C_CodeOptions

image8 image8

  • Install the CDT (C/C++ development tool)
  • Convert your project to a C/C++ Project

image9 image9

  • Convert to C Project
  • Create an Executable
  • Click Finish

image10 image10

  • To automatically compile choose Build on resource save in the project properties

image11 image11

  • Rearrange the CDT Builder to the last position to make sure that the actifsource generator runs before compiling

Part II Setting up a CIP Test Suite

  • Create a new Resource of type CipTestSuite
  • Specify your test cases

image12 image12

  • Create a new Resource of type CipTestSuite
  • Reference you CIP system and the implementation unit which shall be tested

image13 image13

  • Create a new TestCase called LampOnOff
  • Make sure to properly comment all resources via the comment attribute.

image14 image14

  • Define the first test event of type MessageEvent

  • First define the event message which is sent to the CIP machine

  • Let’s switch on the light by pressing the button

    • Select event message Button.Push
    • Define the expected action message Lamp.Bright

image15 image15

  • Define the second test event of type MessageEvent

  • First define the event message which is sent to the CIP machine

  • Let’s activate the switch off delay by pressing the button

    • Select event message Button.Release
  • Since switching off is delayed, we do not expect the light to be switched off

image16 image16

  • Define the third test event of type TickEvent

  • Define the number of ticks to time up the delay

    • 3 ticks in this example
    • Define the expected action message Lamp.Dark
  • The light is expected to be switched off after 3 ticks

Part III Running the CIP Test Suite

  • In the second part we want to generate an executable which can run the previously defined test cases
  • Make sure to install the CDT (C/C++ Development Tool) and mingw or gcc for C language support

image17 image17

  • Your lamp system should have been generated by now
  • Select your executable and run configuration

image18 image18

  • Select the command line options

    • Select regressive to automatically run test cases
    • Select manual to manually stimulate the event

image19 image19

  • Run the Local C/C++ Application

image20 image20

  • The test out can be found in the console
Info

Note that you can directly link back from the console output in the corresponding model by clicking on the blue GUID links

image21 image21

  • Delete the expectation Lamp.Bright in your first test event and run the test again
  • Link back to the model by clicking the GUID link next to the assertion failure
  • Correct your test model

Part IV Generate the CIP Test Suite Documentation

  • Last but not least we want to generate the test suite documentation
  • The documentation can be used for communication and to ensure quality
  • Make sure to define a new test case any time a problem in your state machine hast been corrected

image22 image22

  • The documentation is generated because of the BuildConfig CIP_HTML_TestSuite_Documentation
  • A file Test_CipSystem_TestSuite_Documentation.html is generated in your target folder

image23 image23

  • Use the generated documentation to ensure quality and communicate with your team mates.

image24 image24

  • Click on messages in the test cases to link back to the system information

actifsource-point-large

CIP Statemachine - Arduino

logo-large

Tutorial Actifsource Tutorial – CIP Statemachine - Arduino
Required Time - 120 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – CIP Statemachine - Lamp
Goal - Compiling and running the CIP Statemachine on the Arduino UNO
Topics covered - Arduino SDK
- Simple Arduino project
- CIP Arduino project
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Arduino SDK

    • The Arduino SDK contains all the necessary source code for your Arduino
    • Installing the com port driver for your Arduino
  • AVR Eclipse Plugin

    • The AVR Plugin is an extension to the C/C++ Development Toolkit to support development for the Atmel AVR series of embedded processors.
    • Configure the AVR Plugin for your Arduino board
  • Simple Arduino project

    • Setup a new C/C++ project
    • Write a very simple code which switches an LED on and off
    • Compile the project including the Arduino core
    • Download to the Arduino target and run
  • CIP Arduino project

    • Modeling a reactive state machine using the CIP method
    • Generating C code for the state machine
    • Connecting the generated state machine code to the Arduino I/O
    • Downloading and testing to the Arduino board

Part I Installing Eclipse & Arduino

  • Install the Eclipse IDE for C/C++ Developers (C/C++ Development Tool) www.eclipse.org/downloads
  • Install the Actifsource Enterprise plugin
  • The Arduino SDK contains all the necessary source code for your Arduino
  • Installing the com port driver for your Arduino

Arduino Software Setup

image2 image2

  • Download your Arduino SDK from www.arduino.cc

  • Unzip the Arduino SDK on your hard disk

    • We use C:\arduino-1.0.3\ in this example

image3 image3

  • Plugin your Arduino to a USB port

    • The installation will fail
  • Open the Device Manager from the Control Panel

  • Find the failed device

  • Install new driver

  • Search the driver on your computer

  • Specify C:\arduino-1.0.3\drivers as the place to look for the driver

    • Warning: You must not select C:\arduino-1.0.3\drivers\FTDI USB Drivers

image4 image4

  • Check if the driver has been installed correctly

  • Important: Remember the com port

    • COM3 in this example

image5 image5

  • Open the boards.txt file in C:\arduino-1.0.3\hardware\arduino

  • Print the information for your hardware platform

    • Arduino Uno in this example
  • For Linux you can simply install gcc-avr avr-libc avrdude:

sudo apt-get install gcc-avr avr-libc avrdude

AVR Eclipse Plugin

  • The AVR Plugin (for this tutorial version 2.4.1 will be used)for Eclipse is an extension to the C/C++ Development Toolkit to support development for the Atmel AVR series of embedded processors.
  • Configure the AVR Plugin for your Arduino board

image6 image6

  • Start your Eclipse with a new workspace

    • workspace_arduino in this example
  • In your Eclipse, click Help/Install new Software…

  • Add the AVR-Eclipse plugin update site avr-eclipse.sourceforge.net

  • Installing the plugin requires eclipse to restart

image7 image7

  • Configure the AVR Eclipse Plugin under Windows/Preferences/AVR/Paths
  • Set AVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\bin or /usr/bin
  • Set GNU make to custom value C:\arduino-1.0.3\hardware\tools\avr\utils\\bin or /usr/bin
  • Set SVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\avr\\include or /usr/lib/avr/include
  • Set SVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\bin or /usr/bin
  • Important: Press Apply

Part II Simple Arduino project

  • Setup a new C/C++ project
  • Write a very simple code which switches an LED on and off
  • Compile the project including the Arduino core
  • Download to the Arduino target and run

Simple Arduino project

image11 image11

  • Create a new C++ Project

  • You have to create a C++ project even if you plan to write C code since we have to compile the Arduino Core

  • If you can’t create a C/C++ Project you have probably not downloaded the Eclipse for C/C++ Developers

image12 image12

  • Create a new C++ project named ch.actifsource.tutorial.cip.arduino
  • Choose AVR Cross Target Application
  • Choose the AVR-GCC Toolchain
  • Click Next

image13 image13

  • Do not create a Debug Version

  • The debug code is too large to fit on the Arduino Uno

  • See boards.txt for the maximum code size

    • uno.upload.maximum_size=32256 for this example
  • Click Fish

  • Open the C/C++ Perspective if you are asked or open it manually in the upper right corner image15 image15

Arduino Build Variables Arduino Build Variables

  • For the newly created ch.actifsource.tutorial.cip.arduino, choose Properties (Mouse-Click-Right on the project)
  • Select C/C++ Build
  • In the Build Variables Tab, enter the following variables:
    • AVRDUDEOPTIONS, set to -p atmega328p -c arduino -P/dev/ttyUSB0 -b 115200
    • AVRTARGETFCPU, set to 16000000
    • AVRTARGETMCU, set to atmega328p
  • Click Apply

Arduino Environment Variables Arduino Environment Variables

  • In the Environment Tab, enter the following variables:
    • AVRTARGETFCPU, set to 16000000
    • AVRTARGETMCU, set to atmega328p
  • Click Apply

Ardunio Settings Ardunio Settings

  • In the Settings Tab, set AVRDude to true. This will automatically download the program to the attached board
  • Click Apply

image18 image18

  • This step is only needed on Windows

  • SimpleProject/Properties/C/C++Build/Settings/AVR Compiler/Directories

  • Set Include Path C:\arduino-1.0.3\hardware\tools\avr\avr\include

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\cores\arduino

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\variants\standard

    • See boards.txt (uno.build.variant) for your variant (standard for this example)
  • Click OK

image19 image19

  • Do the same again for SimpleProject/Properties/C/C++Build/Settings/AVR C++ Compiler/Directories

  • Set Include Path C:\arduino-1.0.3\hardware\tools\avr\avr\include

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\cores\arduino

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\variants\standard

    • See boards.txt (uno.build.variant) for your variant (standard for this example)
  • Click OK

image20 image20

  • Create a new folder src in the project

image23 image23

  • Create a new file main.c in the folder src
#include <avr/io.h>
#include <util/delay.h>

#define DELAYTIME 500  // 500ms Verzögerung

int main(void)
{
  DDRB |= _BV(DDB5); // Setze Pin PB5 (Arduino LED) als Ausgang

  while (1) {
    PORTB |= _BV(PORTB5);  // LED einschalten
    _delay_ms(DELAYTIME);  // Wartezeit

    PORTB &= ~_BV(PORTB5); // LED ausschalten
    _delay_ms(DELAYTIME);  // Wartezeit
  }

  return 0; // Dieser Punkt wird nie erreicht
}
  • Write a very simple Arduino program in the file main.c as shown above
  • If you enabled Build on resource save (Auto build) in Project/Properties/C/C++Build/Behaviour before, the code should now be built
  • You can also build manually by pressing Project/Build All (Ctrl+B ) or the build button in the Eclipse toolbar image24 image24
Info

Your code is probably not linking if you named your file main.cpp instead if main.c

image25 image25

  • Download your code to the Arduino

image27 image27

  • Mount your LED between Pin 13 and GND

    • Don’t forget the 330Ω resistor for a 1.7V LED with 10mA 🡪 (5V-1.7V)/0.01A = 330Ω
  • The program starts automatically after the download has been completed

    • The LED should switch on and off once per second

Part III CIP Arduino project

  • Modeling a reactive state machine using the CIP method
  • Generating C code for the state machine
  • Connecting the generated state machine code to the Arduino I/O
  • Downloading and testing to the Arduino board

CIP Arduino project

image28 image28

  • Switch to the Actifsource Perspective image29 image29
  • Select your project ch.actifsource.tutorial.cip.arduino in the Project Explorer
  • Select Configure/Add Actifsource Nature

image30 image30

  • Open Properties/actifsource/Resource Paths
  • Add the Resource Path asrc
  • Press Apply

image31 image31

  • Open Properties/actifsource/Built-in Dependencies
  • Add Builtin CIP
  • Add Builtin DATATYPE
  • Important: Press Apply

image32 image32

  • Open Properties/actifsource/Target Folders
  • Add the existing folder src as target folder
  • Add the BuildConfig CIP_C to the target src
  • Press OK

image33 image33

  • Select the Resource Folder asrc in the Project Explorer
  • Select CipSystem from the New Resource Tool in the Eclipse toolbar

image34 image34

  • Enter ch.actifsource.tutorial.cip.arduino as Namespace
  • Enter LampSystem as Name
  • Press Finish

image35 image35

image36 image36

  • Create a new Implementation named LampSystemImplementation in your LampSystem
  • Create a new ImplementationUnit named LampSystemUnit in your LampSystemImplementation
  • Create a new CipMachine in your LampSystemUnit
  • Reference the Cluster LampCluster in your CipMachine
  • Create a new CipShell in your LampSystemUnit
  • Reference the input channel Button
  • Reference the output channel Lamp
  • Create a new C_CodeOption named LampSystem_CodeOption using Content Assist (Ctrl+Space)

image37 image37

  • Configure the newly created LampSystem_CodeOption
  • Set useInterface to useMessageInterface
  • Set usePostFix to InitPostFix
  • Set enable_PENDING_Information to true
  • The code for your CIP system is now generated in the target folder src
#include <avr/io.h>
#include <util/delay.h>
#include "sLampUnit.h"

#define LED_PIN     PB5   // LED connected to PB5 (Arduino Pin 13)
#define BUTTON_PIN  PB4   // Button connected to PB4 (Arduino Pin 12)

void AI_LampUnit_C2_Dark() {
  PORTB &= ~_BV(LED_PIN); // Turn LED OFF
}
void AI_LampUnit_C2_Bright() {
  PORTB |= _BV(LED_PIN);  // Turn LED ON
}
void iMSG_LampUnit() {
  OUT_LampUnit.C2_Dark = AI_LampUnit_C2_Dark;
  OUT_LampUnit.C2_Bright = AI_LampUnit_C2_Bright;
}

int main(void)
{
  if (!fINIT_LampUnit()) {return 1;} // init cip
  // Set LED_PIN as an output
  DDRB |= _BV(LED_PIN);

  // Set BUTTON_PIN as an input and enable internal pull-up resistor
  DDRB &= ~_BV(BUTTON_PIN);  // Configure as input
  PORTB |= _BV(BUTTON_PIN);  // Activate internal pull-up (idle state = HIGH)

  int oldbuttonState = 0;

  while (1) {
  int newButtonState = PINB & _BV(BUTTON_PIN); // read button pin
  TRG_LampUnit.TICK_();
  // ticking time
  if(oldbuttonState!=newButtonState && newButtonState==1) {
    IN_LampUnit.C1_Push();
  }
  if(oldbuttonState!=newButtonState && newButtonState==0) {
    IN_LampUnit.C1_Release();
  }

  oldbuttonState=newButtonState;

  while (TRG_LampUnit.PENDING_.ANY_) {
    TRG_LampUnit.STEP_();
  }
    delay_ms(4);
  }

  return 0; // Never reached
}
  • Rewrite your main.c as shown above
Info

Your code is probably not linking if you named your file main.cpp instead if main.c

image38 image38

  • Download your code to the Arduino

    • Select your project SimpleProject in the Project Explorer
    • Press the AVR download button in the Eclipse toolbar image26 image26

image39 image39

  • We built a lamp with a delayed off switch

    • Pin 2 on GND means Button is released
    • Pin 2 on 5V means Button is pressed
  • Start while Button is released

  • Press Button 🡪 Light should switch on

  • Release Button 🡪 Light should switch off with delay

    • Tune with the delay function of your timer and the delay_ms() call in the main.c

actifsource-point-large

Glossary

The glossary contains all relevant terms to understand the actifsoure documentation.

Filter terms according to their categories

Tool Select all Deselect all

Click on the [+] indicators below to get a longer explanation for any particular term.

  • Actifsource
    Actifsource is a domain-specific modeling workbench. [+]
    It is realized as plug-in for the software development environment Eclipse. Actifsource supports the creation of multiple domain models which can be linked together. It comes with a UML-like graphical editor to create domain-specific languages and a general graphical editor to edit structures in the created languages. It supports code generation using user-defined generic code templates which are directly linked to the domain models. Code generation is integrated into Eclipse’s incremental build process.

Subsections of Glossary