Skip to content
BluAge Documentation

BAGS Language

This page explains the mechanism of the BAGS language, used by BluAge products to provide an abstraction of the targets languages specifications by providing a unique language in the UML layer which will then be translated into the appropriate syntax depending on your BluAge Forward stack.

Introduction & Use Cases

The "BAGS" language is a Domain Specific Language (DSL).

The aim of this DSL is to ease the modeling on several levels. For instance, it aims to avoid the getters/setters modeling and can be used to manage a simple allocation. BAGS is closed to languages such as Java or C#.

The BAGS language can be applied on opaque actions and control flows' guards.

Opaque Action

To create an opaque action using BAGS language :

  1. Select the Opaque Action entry from the Action menu of the MagicDraw activity diagram panel and add it to your Activity Diagram;


  2. Double-click on the newly created opaque action and specify bags in the Language field. The properties dropdown must at least be set to Expert in order to have access to the Language field;


  3. You can then fill the body of this opaque action with a BAGS expression.

Control Flow Guard

To create a flow action guard using BAGS language :

  1. Select the Control Flow menu of the MagicDraw activity diagram panel, click on the flow source element in the Activity Diagram and then to the flow target element;


  2. Double-click on the newly created control flow, then click on the Edit element of the Guard field;


  3. Edit the Language input of the Guard window to enter bags, as shown below :


  4. In BluAge products 5.5, the input has been replaced by a dropdown menu. If you don't have access to the bags entry in this dropdown menu, the following steps must be followed :

    • Click on the Environment entry of the Options menu;
    • In the Editing entry of the General menu, you can add a bags dropdown entry in the Opaque Expression Default Language dropdown;


    • You can now select the bags language in every guard edition window of your MagicDraw environment.

  5. You can now fill the body of the guard with a BAGS expression.

BAGS Syntax

The BAGS syntax is based on dotted syntax. It is basically used as follows:

[instance[.property]] = [instance[.property]|[value];

The ending semi column is optional if you write a single BAGS expression, and mandatory if you want to use the same opaque action


Setting of a property is done by using the assignment operator =.

If the attribute to read is an attribute of a class, the BAGS will be automatically converted to the appropriate call to the getter operation of this attribute. If the target attribute is an attribute of a class, the BAGS will be automatically converted to the appropriate call to the setter operation of this attribute. Some examples of BAGS assignments with their corresponding generated code are demonstrated below :

BAGS Generated Java Generated C#
targetValue = 2 targetValue = 2; targetValue = 2;
targetValue =
targetValue =
targetValue =
TargetClass.targetAttribute =
instanceTargetClass.TargetAttribute =

A few notes about the BAGS assignment syntax :

  • The BAGS syntax for assignments removes the needs to explicitly declare getters and setters operations in your classes, since the BluAge Forward process will create those operations independently of their presence in the model;
  • You still have to manually declare variables and class instances before using this syntax, this is not covered implicitly. Those declarations are made by the means of Central Buffer Nodes.

NOTE : For more information about attributes declarations, please refer to the Elements Modeling page.

Basic Operations

Relational Operators

The relational operators; equal, not equal, less than, less than or equal, greater than, and greater than or equal are supported using standard operator notation. Some examples of BAGS syntax are demonstrated below :

BAGS Generated Java Generated C#
3 == 2 3 == 2 3 == 2
TargetClass.targetAttribute == "value" "value".equals(instanceTargetClass.getTargetAttribute()) "value".Equals(instanceTargetClass.TargetAttribute)
testValue > "value" testValue.compareTo("value") > 0 testValue.CompareTo("value") > 0
TargetClass.targetAttribute = 6 != 3 instanceTargetClass.setTargetAttribute(6 != 3); instanceTargetClass.TargetAttribute = 6 != 3;
ClassOne == ClassTwo instanceClassOne.equals(instanceClassTwo); instanceClassOne.Equals(instanceClassTwo);

Type conversion is automatically computed and is covered in the Type Conversion section.

Logical Operators

BAGS can also deal with a wide range of logic operators: ! || && ^ >> <<. Priority between operators is kept and you can use the parenthesis system to encapsulate operands of your expression, as demonstrated below :

BAGS Generated Java Generated C#
!(Class.attribute == "value") !("value".equals(instanceClass.getAttribute())) !("value".Equals(instanceClass.Attribute))

Mathematical Operators

Finally, BAGS can also deal standard mathematical operations : addition (+), subtraction (-), multiplication (*), division (\) and modulus (%).

Method Calls

Utils Methods

All the Blu Age Common Utils classes can be referenced in a BAGS expression using the following syntax: @ClassName.methodName.

The matching method in the utils class following the "@" will then be referenced in the generated code.

For instance, if you want to call the isInteger method of the utils class StringUtils, the proper BAGS syntax is : @StringUtils.isInteger("23").


Class & Service Methods

Other classes and services methods can be referenced in a BAGS expression using the following syntax: @$instanceClassName.methodName.

The matching method following the "@$" will then be referenced in the generated code. You still are responsible for the class instanciation / service injection before being able to use this syntax, otherwise the generated code won't compile.


Constants use is also supported. When needing a constant in a BAGS opaque action, create a central buffer node representing the constants class to import.

Then in the expression, use the following syntax: ConstantsClass#constantName (instead of ConstantsClass.constantName).

The correct expression will be generated, and the instanciation of the central buffer node will be accordingly dismissed.


Lists Access

You can access lists values by two ways :

  • Using the get standard method of the ListUtils service, passing the list and the index as parameters and using the @ListUtils.get() syntax;
  • Using the [] syntax directly on the list.

Lists Containment

in and not in are supported as well to check whether or not the value of an element is contained in a list of values.

The following syntax is to be used (works when the list of values contains at least two elements): x in {1, 2, 3, ...} and !(x in {1, 2, 3, ...})

The priority of operators is defined as follows: the && and || operators are prioritised ("x in {...} && y in {...}" will be correctly translated). in and !in will then be prioritised over remainder of the operators ("x + y in {...}" will search for x+y in the list of values).

Type Conversions

The "Left" types are compared to the "Right" types of the expression. If the "right" type is different of the "left" one, a cast is generated in the corresponding generated code. The following cast rules apply to all BAGS expressions in your UML model :

  • Casts for primitive objects:
    • BigDecimal = new BigDecimal([value]) ;
    • Long = Long.valueOf([value]) ;
    • Integer = Integer.valueOf([value]) ;
    • Float = Float.valueOf([value]) ;
    • Double = Double.valueOf([value]) ;
  • The untagged values are detected either in "int" or in "String".
  • In other cases, the classic casts are generated: (Type) value.


Comments are supported in a BAGS expression, through the syntaxes // for single-line comments and /* ... */ for multi-line comments.

However, please note that a BAGS expression must contain at least one non-commented expression in order to be correctly parsed.

Parsing Errors

If, during the generation, a BAGS expression cannot be parsed by the generator, an error message will be printed in the BluAge generation console, containing the target method in error.

In the generated file, the original content will be placed instead of the parsed one, and an error comment with a TODO is added in order to easily target the BAGS expressions in error.