Simple Service

Table of Contents

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