UML Profiling and DSL UserGuide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

UML PROFILING AND DSL

user guide

No Magic, Inc. 2009

All material contained herein is considered proprietary information owned by No Magic, Inc. and is not to be shared, copied, or reproduced by any means. All information copyright 1998-2009 by No Magic, Inc. All Rights Reserved

CONTENTS

1
6

Advanced customization engines Exchanging Profiles via XMI 8

Working with UML Profiles


Creating Profile 9 Modifying Profile 9

Opening Profile as a project 10 Modifying profile in the read-write mode 10

Using profile, stereotypes and tags

10

Applying stereotypes 11 Specifying tagged values 11 Using scalable stereotype icons 12

Advanced profiling

13

Initializing opposite association end 13

Invisible stereotypes, tags and constraints 14 Applying different Icons for the same stereotype 15 Grouping tags inside stereotype 17 Creating tags with default values 19 Customizing style of stereotyped elements 19

Custom Diagram Wizard 20


Name, base type, abbreviation Used profiles 23 Custom diagram toolbars 24 Custom toolbar buttons 25 Custom styles 27 Smart manipulators 27 21

DSL Customization engine


General principles 28

28
31

Creating Customization data 29

Customizing specification dialog box


Hiding standard UML properties 31 Always visible properties 33

Copyright 1998-2009 No Magic, Inc.

CONTENTS
Creating your own property groups 33 Meta property substitution (changing name of UML property) 34

Customizing element shortcut menu


Quick property editor 35 Quick stereotype applying 36

35

Quick element creation from the shortcut menu, customized category Custom model initialization 38
Default values 38 Stereotypes on relationship ends 38 Required Generalization or Interface Realization 39

36

Inheritance of DSL customization 39 Custom rules for relationships 40 Customization of possible owned elements 41
Custom owned types 41 Custom owned diagrams 42 Custom suggested relationships 42

Customization of symbols
Custom path style 43

43

Setting default symbol size of DSL element 45 Rules of stereotypes that cannot be allowed to apply 45 Type restriction for custom table in specification dialog 46 Hiding DSL elements in the type selection dialog 46

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN SPECIFIC CUSTOMIZATIONS

View Online Demo

Domain Specific Language (DSL)

NOTE

Domain Specific Language customization engine is available in Standard, Professional, Architect, and Enterprise editions only.

UML is a general purpose visual modeling language for specifying, constructing and documenting the artifacts of systems that can be used with all major application domains and implementation platforms. It has been widely adopted by both industry and academia as the standard language for describing software systems. However, the fact that UML is a general-purpose notation may limit its suitability for modeling some particular specific domains (e.g. web applications or business processes), for which specialized languages and tools may be more appropriate. OMG defines two possible approaches for defining domain-specific languages. The first one is based on the definition of a new language, an alternative to UML, using the mechanisms provided by OMG for defining object-based visual languages (i.e., the same mechanisms that have been used for defining UML and its metamodel). In this way, the syntax and semantics of the elements of the new language are defined to fit the domain's specific characteristics. The problem is that standard UML tools will not be able to deal with such a new language. The second alternative is based on the particularization of UML by specializing some of its elements, imposing new restrictions on them but respecting the UML metamodel, and without modifying the original semantics of the UML elements (i.e., the properties of the UML classes, associations, attributes, etc., will remain the same, but new constraints will be added to their original definitions and relationships). UML provides a set of extension mechanisms (stereotypes, tag definitions, and constraints) for specializing its elements, allowing customized extensions of UML for particular application domains.

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS

These customizations are sets of UML extensions, grouped into UML profiles. However UML profiles for specific domain cant play role of specialized tool, they are just specialized metamodels. MagicDraw UML tool provides ability to use brand-new engine for adapting domain specific profiles to create your own custom diagrams, custom specification dialogs, custom real-time semantic rules and other. In other words user is able to create low-budget specialized domain-specific tool and hide UML underneath. DSL customization is model-driven approach, based on UML profiling.

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S

Definitions

Profile
Special kind of package (Profile) that holds collection of stereotypes.

Metaclass
Type defined in UML specification (like Class, Component, Package, State etc.). All metaclasses are available in UML Standard Profile::UML2 Metamodel.

Module
Piece of model in file used in other project by reference (not contained)

DSL
Domain Specific Language

DSL Customization
Special profiling for MagicDraw adaptation to some DSL

DSL type
Stereotype customized to be as new independent type

Customization class
Class with applied <<Customization>> stereotype

Customization model
Collection of Customization classes

Simply stereotyped element


Element with applied not customized stereotype

Advanced customization engines


MagicDraw introduces several advanced customization engines, based on UML Profiles:
Custom Diagram Wizard allows creating your own diagram types for custom profile, with your own toolbars, stereotyped

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS

elements, symbol styles and custom smart manipulators. Such customization is saved in the special diagram descriptor, that could be exchanged between users, allowing them use your own custom diagrams.
Domain Specific Language Customization Engine (DSL customization engine) allows tuning domain specific profiles, customizing multiple GUI, model initialization, and semantic rules, creating your own Specification dialogs. DSL customization is model-driven approach, based on UML profiling. Customization is saved as a UML model. Advanced UML Profiling allows using some profiling enhancements that are not defined in UML, but that helps to solve some common problems like tag grouping, unwanted stereotypes and tags hiding etc.

Below is the list of MagicDraw areas that are possible to customize using MagicDraw advanced customization engines.
Customization Custom diagrams Customization engine

Diagram type name Base diagram type Diagram abbreviation Used profiles Diagram toolbar customization Symbol styles Scalable icon Custom draw and layout rules Smart manipulators Context actions for property changing Keywords Representation text

Custom diagram wizard Custom diagram wizard Custom diagram wizard Custom diagram wizard Custom diagram wizard Custom diagram wizard Profiling Open API Custom diagram wizard DSL engine DSL engine DSL engine

Custom shapes

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Working with UML Profiles

Custom paths

Line style Line width Arrow types or end icons

Profiling Symbol properties Profiling

Custom model initializations and constraints

Default values for primitive UML prop- Custom diagram wizard erties. Default values for tags with primitive types Default super classes and interfaces Profiling DSL engine DSL engine DSL engine DSL engine DSL engine DSL engine

Connection rules

Allowed metaclasses or stereotypes for end Stereotypes that must be applied on relationship ends

Custom Specification dialogs

Grouping into nodes Native UML properties on/off Always visible custom properties

Exchanging Profiles via XMI


Using UML XMI interchange mechanisms it is possible to interchange profiles between tools, together with models to which they have been applied. A profile must therefore be defined as an interchangeable UML model. In addition to exchanging profiles together with models between tools, profile application should also be definable by reference; that is, a profile does not need to be interchanged if it is already present in the importing tool. See the next chapter for instructions for interchangeable profile creating.

Working with UML Profiles


Profile in UML is a special kind of Package, used to contain collections of stereotypes, domain specific datatypes, and libraries.

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Working with UML Profiles

Creating Profile
Profile can be created in any Project, however often the same profiles are used among many projects. In order to reuse the same profile, it must be created as an independent file with shared data called module. To create Profile as a module
1. Create a new project. 2. In the Browser, right-click the root Data model and create new Profile 3. Create a new Class diagram inside Profile. 4. Create stereotypes in the diagram. 5. Use Extensions, Associations and Generalizations between them if needed. 6. In the Browser, from the created Profile shortcut many choose Modules and then Share Packages command. 7. Select Profile as shared, enter description, and click OK. 8. Save project. Now you may use this profile in other projects.

To use the created profile in other projects


From the File menu, choose Use Module and select the module file. In such a way only shared packages of the module will be loaded into the project. TIP!

If the Profile contains diagrams, they will be also loaded in the user projects. If you dont want to see these diagrams in your project, move diagrams from shared packages into root model or other non-shared packages in your module. In such a case diagrams with stereotype hierarchies will be available to users who are working directly on the profile creation, but not for users who are using this profile as a module.

Modifying Profile
If you want to make any changes in the profile, you may modify it by opening profile as a regular project or modify it in the read-write mode (see below).

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Working with UML Profiles

Opening Profile as a project


This is the most natural and safe way to modify your profiles. It helps to see all not shared infrastructure including diagrams, tests, examples and etc. To open Profile as a project
In the Browser, from the used Profile shortcut menu, choose Modules, and then Open Module as Project. Open Profile as simple Project by choosing Open from the File menu.

Modifying profile in the read-write mode


Using profile in the read-write mode is the fastest way to add changes when you are not in teamwork and dont care of possible editing conflicts. It helps to perform basic refactoring of your modules to move elements directly from one module to another. You may choose read-write usage mode when trying to use some profile as a module. To use Profile in the read-write mode
1. From the File menu, choose Use Module or, if the profile is already in use, from the Options main menu, choose Modules. The Use Module dialog box appears. 2. Select the Profile. 3. In Module Settings tab, choose Read-Write option button. 4. By setting this option you will be able to change the profile directly in your project.

Using profile, stereotypes and tags


The description of how to use profile in your project you may find in Section Using Project Module.

10

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Working with UML Profiles

Applying stereotypes
A stereotype defines how an existing metaclass may be extended, and enables the use of platform or domain specific terminology or notation in place of, or in addition to, the ones used for the extended metaclass. When a stereotype is applied to a model element, the values of the properties may be referred to as tagged values. To apply stereotype to an element:
From the element shortcut menu in the Browser or Diagram: from the element shortcut menu, choose Stereotype. In the element specification dialog box. Choose the stereotype from the Applied Stereotypes field or go to Tags and enter value for some tag. In this case stereotype will be applied automatically. Type stereotype name directly on elements symbol. On the diagram pane in the element name area, type two angle brackets <<, type stereotype name and close angle brackets (or press Ctrl+Space and choose from auto-completion list). Then you may type element name itself. For example: if you want to name element Books and assign <<table>> stereotype, in the element name area, type the following: <<table>>Books.

To apply stereotype to multiple elements


Select multiple elements and from their shortcut menu, choose Stereotype command or choose stereotype in the Quick Properties panel below model tree.

Specifying tagged values


Special Stereotypes and Tags tree is used to reflect all stereotypes and tags that are applied or could be applied to this element. To specify tagged values
1. Open element Specification dialog box. 2. Specify tagged values in the Tags pane.

In the Tags pane there are multiple filters that help to distinguish or group tags with different status.

11

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Working with UML Profiles

To filter and group tags

Group by stereotype Group by special tag groups ( Show only tags with values Show type of tag definition

Show tags only from applied stereotypes

Using scalable stereotype icons


MagicDraw allows using scalable icons for stereotypes in such a way overriding standard UML notation. Good-looking scalable shapes are very important for scalable document formats (like *.pdf), presentations, and large printed diagrams. To use custom large scalable icon instead of standard UML shape.
1. In the Stereotype specification dialog box, assign *.svg icon for stereotype. 2. Apply stereotype to some element in diagram. 3. Suppress content for this shape (suppress all possible compartments and select Suppress content presentation option in shortcut menu). 4. Resize the appeared icon to any size.

Example: Before applying a stereotype:

12

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Advanced profiling

After applying a stereotype (in such a case stereotype has its own style blue color and icon):

After suppressing content:

Icon can be scaled up without the loss of quality:

Advanced profiling
MagicDraw allows using several profiling enhancements that are not defined in UML, but that helps to solve some common problems in everyday modeling.

Initializing opposite association end


If two stereotypes are connected with Association and there are roles at both ends, role at one end will be initialized automatically when opposite role is specified.

13

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Advanced profiling

Example:

When <<dog>> Rex is set as a pet for <<human>> Tom, Tom will be automatically set as master for Rex.

Invisible stereotypes, tags and constraints


Normally tags are used to hold some additional specific information that helps to interpret basic elements somehow different by some external tools, like transformations, code engineering, etc. In these cases users dont want to make impact on existing diagrams, only mark model. Tag definitions are properties of stereotype in UML2, so UML doesnt allow using tagged values without assigning of stereotype. That means your diagrams will be changed when some tags are added into model. MagicDraw provides ability to make chosen stereotypes or tags not visible in diagrams. To make stereotype invisible
The stereotype, which you want to make invisible, must be inherited from <<InvisibleStereotype>> (from MagicDraw profile). 1. Create a custom stereotype. 2. Create Generalization between your stereotype and InvisibleStereotype You custom stereotype will be not displayed on symbols where it will be applied. Note that all tags also will be invisible on symbols.

14

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Advanced profiling

Example: It is not desirable to see an author tag in diagrams. To accomplish this, follow these steps:
1. Create stereotype <<copyrighted>> that extends Element metaclass. 2. Create property author: String for <<copyrighted>> stereotype. 3. Inherit this stereotype from <<InvisibleStereotype>> (create generalization in the model or diagram).

Now you may enter tagged value author for any element in your model. Stereotype <<copyrighted>> will be applied automatically but will be invisible in diagrams. To create an invisible tag
Apply InvisibleStereotype on your tag definition (property of stereotype) All such hidden tags will be invisible on symbols of stereotyped elements.

Example: Stereotype <<identification>> has two tags: ID and Description. The user would like to see Description value on elements in diagrams, but ID should be hidden as it is used in some external model transformation tools or similar activities. Apply <<InvisibleStereotype>> on ID property of <<identification>> stereotype and it will be not visible on stereotyped elements on diagrams. To make a constraint invisible A new capability to define invisible constraints has been introduced. To make a constraint invisible, apply the <<InvisibleStereotype>> stereotype to the constraint. Invisible constraints may be used while creating validation constraints, in DSL customization, or in other modeling cases.

Applying different Icons for the same stereotype


MagicDraw provides ability to create stereotype, which uses different icons, depending on stereotype kind.

15

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Advanced profiling

Example: PseudoState is one in UML, but it uses different notation, depending on PseudoStateKind. The similar situation could appear in your model. To apply different icons on the same stereotype
1. Create Enumeration (in our example supercarKind). Enumeration will define all stereotype kinds. 2. Apply <<iconHolder>> stereotype on enumeration. 3. Create as many EnumerationLiterals as different kinds you would like to have (in our example it is ferrari and audi). 4. Apply stereotypes with different icons to every EnumerationLiteral (in our example <<ferrari>> and <<audi>>). 5. Create Stereotype (in our example supercar) with property (tag definition), which type is such enumeration (supercarKind). Default value could be selected. 6. Assign the created stereotype to an element and select one of enumeration value in tags. Stereotyped element will change its icon regarding enumeration value.

16

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Advanced profiling

Example:

Grouping tags inside stereotype


When some stereotype has many properties, it is very useful to group logically these properties into named groups. For this purpose every property could have tagged value with its group name. To group tags
1. Open specification dialog of stereotype property. 2. Go to Tags panel. 3. Type group name as groupName value, << hasGroupName >> stereotype will be assigned automatically. 4. Repeat these step for every stereotype property

17

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Advanced profiling

Example 1. Real example of grouped properties from UseCase Description Profile

18

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Advanced profiling

Creating tags with default values


1. Create tag definition (Property). 2. Specify default value for this tag. 3. Specify multiplicity larger than 0 (1, 1..*, 2, etc.).

Such multiplicity means that this tag is mandatory. When stereotype will be applied, mandatory tags will be automatically created and default values will be assigned.

Customizing style of stereotyped elements


There are several ways to customize symbol style of stereotyped elements. To extend UML symbol styles by creating new styles for stereotyped elements
1. In the Project Options dialog box, the Symbols Properties Styles tree, right-click the Stereotypes branch. The list of stereotypes appears.

19

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Custom Diagram Wizard

2. Select the check box near the stereotype and click the Apply button. Stereotype will be included into the Stereotypes branch. Set the stereotype style properties in the right pane of the Project Options dialog box.

The best practice is to create styles for stereotypes in the Profile, loading it as a project. When some project uses Profile, styles for stereotypes will also be loaded and used. These styles will be applied right after applying stereotype on some element and will be used in all diagrams. Style for stereotype in custom diagram Custom diagram wizard allows specifying styles for stereotyped elements. Note, that this style will be used only in diagrams of this type. For more details of how to work with Custom Diagram Wizard, see the next chapter.

Custom Diagram Wizard


Custom diagram wizard is a powerful engine that allows creating your own diagram types for specific domain, platform, technology, or other purposes. It allows you to create your own custom elements in diagram toolbar, custom symbol styles and other customizations. To open the Customize Diagrams Dialog box
From the Diagrams menu, choose Customize.

You may change properties of existing diagrams (Edit function) or create your own brand new diagram type (Create function). Diagram customization descriptors are saved into separate file for every diagram, so you are able to exchange these customizations with your partners or colleagues (use Import or Export function). Reset to default botton in Customize Diagrams dialog box restores default configuration for diagrams bundled with MagicDraw installation (it does not work with user defined diagrams). Click Edit or Create to open Custom Diagram Wizard.

20

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Custom Diagram Wizard

All custom diagram wizard steps with explanations are described in the chapters below.

Name, base type, abbreviation


All Custom Diagrams are based on some standard UML diagrams (like Class, Use Case, Sequence etc.). Start to create your own diagram from these steps:
Diagram type name (e.g. Robustness Diagram) Base Diagram type standard UML diagram which is extended. All configurations, semantics and other settings will be inherited from this diagram type. Abbreviation short form of diagram name. It will be used in Diagram Frames header or Diagram shapes used in Content diagrams.

21

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Custom Diagram Wizard

Icons several icons for your custom diagram representation in MagicDraw GUI.

22

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Custom Diagram Wizard

Used profiles
Custom Diagrams are oriented to some new specific domain, technology or platform and are often based on some custom profile.

In the second Wizard step (Specify Modules) you may select required modules or profiles. Custom diagram could use stereotyped elements, so profiles that define these stereotypes must be used by custom diagram. The selected modules/profiles will be loaded when custom diagram will be created in user projects. By default UML Standard Profile is used (and must be used).

23

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Custom Diagram Wizard

You may choose stereotype for diagram itself by clicking the Diagram Stereotype button.

Custom diagram toolbars


Every diagram differs by elements that are used in these diagrams. In the Specify toolbars tab, you may group standard or custom elements in any toolbars or order you want. You may:
Create your own custom diagram toolbar Create your own toolbar, name it, and select the icon. Choose standard toolbars that will be visible in your diagram. Select existing toolbars inherited from base diagram type (e.g. see UseCases toolbar in Class diagram subtype). Order toolbars using Up and Down buttons Select which toolbars will be expanded or collapsed by default (use Open checkbox)

24

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Custom Diagram Wizard

In this step you may manipulate with toolbars, in the next step you will be able to customize buttons inside selected toolbars.

Custom toolbar buttons


In the Specify toolbar buttons tab, select standard or stereotyped elements for your own diagram toolbars.

Click Add and select standard UML elements or click Add and then New Button to create your own buttons for your own customized or stereotyped elements creation. Customize the following properties when creating the new button:
Model element type.

25

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


Custom Diagram Wizard

Custom icon for button. Shortcut that activates this button. Description that will be visible in the tooltip. Stereotype(s) that will be applied for created element. Symbol style. The selected symbol properties will be used only when element will be created using this button. Default values for some primitive model element properties (like isAbstract = true or similar)

26

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


Custom Diagram Wizard

Custom styles
In the Specify symbols properties step, you may customize style for any element that appears in your custom diagram (e.g. class dropped in your diagram should be suppressed and red). You may change the appearance of standard symbols, symbols of stereotyped elements, and custom diagram itself. Customized element style will be used only in the appropriated custom diagram type.

Smart manipulators
Smart manipulators are special small buttons that appear in the popup window when symbol is selected in diagram. In the Specify smart manipulators step, you may configure what kind of Relationships will be suggested when custom element is selected in diagram. There are three major steps:
1. Create new configuration (or modify existing one).Select element you want to be customized. Smart manipulators configuration can be related to:
Element (displayed as [Element name]) Element + stereotype(s) Symbol (displayed as {Symbol name}) Symbol + stereotype(s) Stereotype(s) (displayed as <<Stereotype name>>)

2. Select suggested relationships for the selected configuration. 3. Select target elements for the selected relationship.

If few configurations could be applied for the same selected element in diagram, only one configuration will be used by such priority: # 1 2 3 Configuration Symbol + stereotype(s) Stereotype Symbol Comment When stereotype(s) for symbol applied

27

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

4 5

Element + stereotype(s) Element

When stereotype(s) for element applied

Note:

If there are created configurations for few stereotypes (ex. Stereotype1 and stereotype2) in the same diagram, after both stereotypes will be applied for one Symbol on that diagram pane, first configuration (in this ex. Stereotype1) will be used, if there are no symbol+ stereotype(s) configuration specified.

Inheritance of configurations All diagrams have base diagram from which they inherit configurations. For example there is such hierarchy: Any diagram->Static diagram->Class diagram->Generic DDL diagram If you add new configuration to Class diagram (ex. Symbol A + stereotype B) this configuration will be used in Generic DDL diagram as Class diagram is its base diagram. Any and Static diagrams will not have such configurations. To change configuration from the base diagram type
From the Configurations list, select configuration by element type and choose Specify own configuration option button. Inherited configuration will be overwritten.

DSL Customization engine


DSL customization is model-driven approach, based on UML profiling. Special DSL Customization Profile is used for this purpose. This chapter explains how stereotypes from DSL Customization Profile should be used to customize your own domain specific profile.

General principles
MagicDraw DSL customization engine is able to process user-defined rules for DSL elements and reflect this in MagicDraw GUI and diagrams behavior.

28

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

All customization information is stored as special tagged model. There are two ways, how you may create and use this customization data:
Create customization model in a DSL profile, in a separate package. This way is the most intuitive and comfortable, but the profile will be polluted (additional package will be added). It is not acceptable when profile shall be standard compliant Create customization as separate module file. This customization module shall use original DSL Profile. This way helps to avoid profile pollution, but is more confusable, because customization module shall be used in projects instead of the original profile. The original profile will be used indirectly.

In this case all user projects shall use customization module instead of custom DSL profile. Custom DSL profile will be used as secondary module automatically.

Creating Customization data


All DSL customization rules are stored as tag values in Classes, marked with <<Customization>> stereotype. These classes will be parsed and interpreted after reloading the project. To create customization data
1. Create a package for customization data. 2. Create a class in package (or class in class diagram in this package). 3. Assign <<Customization>> stereotype to this class.

29

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

4. Specify values for tags of the <<Customization>> stereotype.

Purpose of all tags are described in chapters below, here we describe just common mandatory Mandatory tags:

30

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

customizationTarget stereotype(s) which you are going to customize. hideMetatype if true, it means that this stereotype acts like new standard element type in MagicDraw.

Example: If <<Block>> stereotype for class is customized with hideMetatype=true, all stereotyped classes will be interpreted as Blocks, but not Classes. The UML Class underneath will be hidden. All chapters below are organized by customization purpose.

Customizing specification dialog box


The main purpose of DSL customization is to hide UML, so extensions would look in MagicDraw as standard elements, but not stereotyped UML elements. Domain specific element properties will appear in Specification dialog box and Quick Properties panel as regular properties, but not tags. There are several customizations and grouping cases for properties.

Hiding standard UML properties


DSL element specification may contain extended UML element properties + custom properties (tags) defined in stereotype. All extended element properties will be used by default, but you may select which extended UML element properties should be used and which hidden in customized specification dialog.
usedUMLProperties tag of <<Customization>> stereotype is used for this purpose. Open customization class, go to Tags panel and create new value for usedUMLProperties tag.

31

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

Special editor will let you to select UML properties of extended UML element.

Properties could be hidden using Standard/Expert property modes also. Customizing Standard/Expert property mode You may save the default configuration for every stereotype inside Customization model, standardExpertConfiguration tagged value, using the same editor as in Specification dialogs, Customize functionality. Dialog contains list of used UML properties + custom properties (tags), so user is able to customize which UML properties and DSL specific properties should appear in specification dialogs. Property groups (nodes) could be customized also, they appear at the end of list, undesirable nodes could be hidden.

32

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Always visible properties


DSL properties will be visible in specification dialog only after applying DSL stereotype, but you may customize tags to be visible as properties in specification dialog even if stereotype is not applied to element. It allows specifying some domain specific values for regular UML elements. Required stereotypes will be applied automatically. Such approach is already used in MagicDraw for To Do notes, hyperlinks, and type modifiers (see screenshot below). stereotypes.

Use showPropertiesWhenNotApplied : boolean tag of <<Customization>> stereotype. When true, all tags of customized stereotype will be visible even if stereotype is not applied to an element. Example: "Java properties" node with multiple Java properties appears in Class specification dialog, when Java profile is used in the project. Only when some java properties are specified, <<JavaClass>> stereotype is applied to this class.

Creating your own property groups


You may create own property group (node) in specification dialog.
1. Create attribute in customization class (class with <<Customization>> stereotype applied).

33

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

2. Type attribute name (it will be used as a group name). 3. Apply stereotype <<propertyGroup>> that allows specifying more information: To store the list of properties grouped into this group, use properties tag. Use special editor for properties selecting (as in usedUMLProperties)
useAsNode : boolean if true, this group will be represented as separate node in specification dialog, otherwise as group in the main (default) panel. To select properties that should be used as table columns, use columns tag. Table should be used in specification dialog, when only one multivalued property is selected to display in node (e.g. ownedOperation in Class).

Meta property substitution (changing name of UML property)


Sometimes standard UML property needs to be customized, to represent more restricted types, or under different name (renamed). Name substitution Example: DSL element should use blockName property instead of name from UML.
1. Create name attribute in customization class. 2. Apply <<metaProperty>> stereotype. 3. Specify new name blockName in tag newName of <<metaproperty>> stereotype.

Type substitution (restriction) Example: The type of <<BlockProperty>> shall always be <<Block>>.
1. Create type attribute in customization class. 2. Apply <<metaProperty>> stereotype. 3. Add <<Block>> stereotype as value of newTypes tag.

34

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Suggesting predefined values There is an ability to create such properties, where list of predefined values will be suggested for the end user (as now with type modifier).
1. Create attribute in customization class 2. Name attribute as tag which should be customized 3. apply <<metaProperty>> stereotype 4. enter suggested values into suggestedValues tag.

Combobox editor with predefined values will be used to edit such customized property.

Customizing element shortcut menu


The main customization of shortcut menu shall be done using User perspectives functionality. However perspectives just provide ability to hide/show existing menus, but not to create new one. New shortcut menu items could be created using customization model.

Quick property editor


Some properties are most often used and shall be accessible in shortcut menu of stereotyped elements. To specify properties that shall be in shortcut menu, use inShortcutMenu : Property [*] tag. Only these types can be edited from the shortcut menu:
Boolean, boolean use checkbox editor. Enumeration select one of the listed enumeration literals. Reference to one element (sublass of Classifier) use element list to select type.

Properties of all other types will be ignored.

35

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

Quick stereotype applying


Stereotypes as <<continuous>>, <<buffer>> and others act like a flag, so it would be nice to use quick checkbox to set these stereotypes from the element shortcut menu. To reference metatypes in which shortcut menu quick stereotype applying checkbox shall be added, use tag quickApplyingFor : Class [*] in customization class. Example
Customization class of stereotype <<continuous>> shall have tag quickApplyingFor=ObjectNode. Checkbox editor with stereotype name will be added at the end of shortcut menu for every object node.

Quick element creation from the shortcut menu, customized category


You can group elements with categories in the New Element menu in Containment Tree or in various create menus in dialog boxes and specifications. The category tag of <<Customization>> stereotype is used for category creation. Example:
Create the Customization class, specify category tag and other tags (see Figure 1 on page 37).

The stereotyped Business Requirement class will be added to the package shortcut menu > the New Element command > the Requirements group (see Figure 2 on page 37).

36

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Figure 1 -- The BusinessRequirement class

Figure 2 -- In the package shortcut menu, the New Element command, there is added Requirements category with possibility to create stereotyped class Business Requirement

37

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

Custom model initialization


DSL customization provides behavior when some model element initialization could be done after applying stereotype on it.

Default values
Tags as any other properties can have default values. These values will be used when tag is created. Tag definition shall have multiplicity greater then 0, only in this case it will be created automatically when applying a stereotype.

Stereotypes on relationship ends


Sometimes DSL requires applying stereotypes on some elements after stereotyped relationship connection to those elements. Several tags are defined in <<Customization>> stereotype for this purpose:
applyToSource : Stereotype [*] stereotypes that must be applied on the source element of this relationship after connection. applyToTarget: Stereotype [*] stereotypes that must be applied on the target element of this relationship after connection.

Source and Target are respectively source and target of directed relationship. The first connected element will act as source for non-directed relationship. Example:
1. Create stereotype <<serve>> for Dependency. 2. Create stereotypes <<master>> and <<servant>> for Element. 3. Customize <<serve>> stereotype, create customization class and specify tags: . customizationTarget = <<serve>>
applyToSource = <<master>> applyToTarget = <<servant>>

4. Now, when you will draw <<serve>> dependency from one element to another, stereotypes <<master>> and <<servant>> will be applied on these elements.

38

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Required Generalization or Interface Realization


Sometimes DSL requires that elements should be subtypes of some general abstract class or interface. Tag for this purpose is defined in <<Customization>> stereotype:
superTypes : Element [*] types that should be super types of stereotyped element. Generalization or InterfaceRealization (If interface) will be created in the model after such customized stereotype applying.

Example Every JAVA class should be subclass of Object class, so every Class marked with <<JAVAClass>> stereotype should be inherited from Object.
Create customization class for <<JAVAClass>> stereotype Specify tag superTypes = Object

Inheritance of DSL customization


For the convenience of end user, DSL customization is inherited when stereotype is inherited, so user dont need to modify existing DSL customization when extending the (standard) profile. For example, if user decides to create its own subtype of SysML Requirement, lets say Performance Requirement, it is enough to define new stereotype << Performance Requirement>> and add Generalization between SysML <<Requirement>> and << Performance Requirement>>. All predefined symbol properties (style) and semantics rules of SysML Requirement will be reused on elements stereotyped by << Performance Requirement>>. The subtype could have their own customization with some basic tags, like human name, etc. Customizations will be merged, so only additions should be defined. It is duty of DSL customizer to avoid conflicting customizations as result could be unpredictable. Generalization between <<Customization>> classes itself is also possible.

39

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

In this case specific (subclass) customization inherits customization rules if these rules are not redefined in subclass (tag is empty). If both customizations have the same tag filled, the rules are not merged, the one from subclass will be used.

Custom rules for relationships


Stereotyped relationships may have special rules, describing what kind of elements can be connected. Several tags are defined in <<Customization>> stereotype for that purpose:
typesForSource: Class[*] metaclasses or stereotypes that should be allowed to connect as source of this relationship. Types cannot conflict with UML permitted types for this relationship (extended by stereotype - customizationTarget). If relationship is not directed, the first connected end should be as source, second - as target. typesForTarget : Class [*] metaclasses or stereotypes for target.

Subtypes of specified end type are allowed only if type is abstract (like Classifier), otherwise only concrete types must be used. Example1: TypesForSource=Classifier Class, Component and etc will be allowed. Simply stereotyped Classifiers will be allowed also (not DSL type). Example2: Class only Class and simply stereotyped Class is allowed. Example3: <<Block>> as type. Only Block shall be allowed, ConstraintBlock is not allowed. Tags that should be used for customizing non-relationships:
allowedRelationships : NamedElement [*] types of relationships that are allowed to connect to this type of element. Only these types shall be allowed if specified. disallowedRelationships : NamedElement [*] types of relationships that are not allowed on this element.

40

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Subtypes of specified allowed/disallowed relationship will be analyzed only when specified relationship type is abstract metaclass (like DirectedRelationship and similar). In other cases only concrete types will be checked. Example1: If only <<Trace>> is allowed, subtypes of trace <<copy>> and <<verify>> shall not be allowed. Example2: If Association is allowed, Extension (subtype) is not allowed, but simple stereotyped Associations are allowed. All DSL Associations are not allowed. Example3: If Dependency is not allowed, simple stereotyped Dependencies like <<delegate>> are not allowed, but subtypes of Dependency like Abstraction and DSL types based on Dependency are allowed.

Customization of possible owned elements


Domain specific diagrams and model requires that some elements of particular predefined DSL types (stereotypes) shall be created inside some other DSL elements. SysML Example: Block shall contain BlockProperty elements, but not simple Property. Block shall own InternalBlockDiagram instead of standard CompositeStructureDiagram All these cases could be customized using special tags.

Custom owned types


These tags of <<Customization>> stereotype are used to customize owned element types:
suggestedOwnedTypes : Stereotype [*] - contains the list of stereotypes that shall be suggested then inner elements are created in customization target type element. hiddenOwnedTypes : Class[*] contains the list of types that shall be not suggested as inner elements. Metaclasses from UML 2,0 metamodel shall be selected. Abstract metaclasses could be selected also (like Classifier, Element); in this case all subtypes will be hidden.

41

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

When some stereotyped elements shall be suggested to create in standard UML element, like package, its not possible to customize standard (not stereotyped) element. In this case customization shall be done upside-down, by specifying possible owners.
possibleOwners : Class[*] all standard UML types, where elements with current customized stereotype shall be suggested to create as owned elements.

Example: You would like to have possibility to create your own type Project inside standard packages from the browser. Create customization class for <<Project>> stereotype and specify possibleOwners = Package.

Custom owned diagrams


The same principles are used for the inner Diagrams customization:
suggestedOwnedDiagrams : String[*] diagram types as Strings. Only these diagrams will be suggested for creation. Other diagrams will be hidden. hiddenOwnedDiagrams : String[*] diagram types as Strings.

Custom suggested relationships


MagicDraw provides the ability to create relationships directly in the model, from model browser, starting from source or target element. List of suggested relationships could be customized (DSL elements will also be added into this list):
If DSL relationship has no connection rules for restricted end types and has hideMetatype=true (is DSL type), it will be added into all lists where extended UML type is suggested. (e.g. <<allocation>> in SysML will be suggested everywhere Dependency is suggested) If DSL relationship has some connection rules, it will be suggested to create only from/to these restricted types (all connection rules will be analyzed).

42

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Customization of symbols
Custom path style
Appearance of standard UML paths is strictly limited by UML specification. UML provides the ability to customize appearance of stereotyped elements, by specifying stereotypes with icons, but these icons can be effectively used to overlap shapes only, but not paths.

The format of stereotype icon is not restricted by UML, so MagicDraw introduces unique icon format for paths appearance extensions. There are several properties for paths that could be customized:
Line style (dashes, dots, solid line, etc). Arrow style at first end.Arrow style at second end. Custom scalable icon for the first end.

43

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

Custom scalable icon for the second end..

All these properties together forms path icon content saved as normal stereotype icon. Additionally, Line width property is added as standard symbol property for paths. Stereotype shall extend Relationship (plus Message, Activity Edge, InstanceSpecification, Transition, Connector) in order to use special path icon. Path icon usage rules:
Custom appearance will be used when stereotype is applied. End icons will by rotated according path position and direction End icon size will be scaled according font size (the same as for standard arrows)

44

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Example:

Setting default symbol size of DSL element


Default size can be defined in DSL customization, using new tag in <<Customization>> stereotype (the "Symbol" group):
defaultShapeSize : int [2]
The first value is width (x) in pixels. Value= 0 is used if default MD width should remain, but height should be changed. The second value is height (y) in pixels.

Default size will be used everywhere when new symbol is created - drag'n'drop, diagram toolbar button, diagram wizards, etc.

Rules of stereotypes that cannot be allowed to apply


When applying stereotype to DSL element, the list of available to apply stereotypes is filtered according to the following rules:
There is not allowed to apply two DSL customized stereotypes (with hideMetatype=true) to the same element. For example, it shall not show <<Requirement>> stereotype in Block shortcut menu (if <<Block>> is already applied). If stereotype should be changed, the current should be unapplied first. (e.g. when changing from <<Requirement>> to <<businessRequirement>>)

45

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S P E C I F I C C U S T O MI Z A T I O N S


DSL Customization engine

DSL ownership rules are checked and there is not allowed to apply stereotype, which is not allowed in this parent element. DSL Relationship rules are checked and there is not allowed to apply some stereotype which source or target element is violating DSL rules for this DSL relationship (the same checking is used while drawing).

Type restriction for custom table in specification dialog


DSL allows creating new node in specification dialog and showing values of some UML property in the table form. Since MagicDraw 16.5 version, it is possible to filter elements according type:
New tag was added into <<PropertyGroup>> stereotype used for DSL filter : Type [*] - types could be UML metaclasses and custom

stereotypes.
DSL engine checks this value and displays only elements of these types in the table.
The "Create" button allows creating a new elements of these restricted types only.

Rules for subtypes


If type is stereotype, all subtypes (sub stereotypes) are accepted also (e.g. if type is Requirement, BusinessRequirement is accepted also). If type is abstract metaclass, all subclasses are accepted (e.g. if type is Classifier - Class, Component and other is accepted). Stereotyped elements are accepted also.

Hiding DSL elements in the type selection dialog


A new property has been added in the DSL Customization dialog that allows you to exclude elements from being suggested as a type in the list dialogs. Select the doNotSuggestAsType : Boolean property in the Customization dialog, under the General group to exclude an element (Figure 3 on page 47).

46

Copyright 1998-2009 No Magic, Inc.

PROFILING AND DOMAIN S PECIF IC CUSTOMIZATIONS


DSL Customization engine

Figure 3 -- The Customization Specification Dialog, Tags branch

47

Copyright 1998-2009 No Magic, Inc.

You might also like