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