setassignment statement, it is possible to create objects of base types like strings, integers, booleans, etc. whereas objects of complex types need to be instantiated (created) first with the
If you define an output object node having a complex type (opposed to base types like String, Integer, etc.), it needs to be created first. In object-oriented terminology: class objects need to be instantiated (that is creating an instance of the corresponding class). Once the instance of the class (the object) has been created, it can store data in its attributes.
Creating Base Types with the set Assignment Statement
The following examples shows how to use the set assignment statement to create base type objects.
|Semantics||Assigns a value to |
|Substitutables||Can be an object node, an attribute, or an association end.|
|Can be a literal, a base type object node, or an EAL operation or expression returning a base type.|
The example in the figure below shows how to create base type objects like strings, integers, etc. Base type objects need not to be instantiated, they are created by using the
set assignment statement to directly assign a value to the variable.
All variables are drawn as object nodes with all objects being of base type (see also Base Types).
Figure: Creating Base Type Objects
Attributes of an object are also assigned values by using the
set assignment statement as shown in the figure below.
Figure: Setting Attribute Values
Creating Arrays by Appending Items
You can create arrays using the However, most of the time the E2E Runtime will create the array implicitly on appending the first item. There is one exception to this rule, though: Arrays that contain array elements having a complex type with multiplicity. What you can do, if The reference What you can't do, if In this case (get statement on the right side of a statement), the Runtime will throw a get error for
create statement (see action script example below):
Let's assume you have an array of complex type ArrayElement and this complex type has a property
subArray with multiplicity 0..*.
subArray is changed to point to
You can create arrays using the
However, most of the time the E2E Runtime will create the array implicitly on appending the first item. There is one exception to this rule, though: Arrays that contain array elements having a complex type with multiplicity.
What you can do, if
What you can't do, if
In this case (get statement on the right side of a statement), the Runtime will throw a get error for
Creating Objects of Complex Type
The following example shows how to use the
create statement to create objects of complex type.
|Semantics||Creates an object of complex type. The object reference is stored in |
|Substitutables||Can be any valid object name.|
In the following cases, objects need to be created with the create statement:
- Creating an object (creating an instance of a class).
- Result objects of an iteration over an action script need to be created (compare section Iterate Over Action Scripts).
In the following cases, the
create statement is not necessary:
- Adapters may create objects of any type. Those objects need not to be created explicitly (for instance, an object that is created after an SQL query executed by the SQL adapter).
When having related classes, the instantiation of intermediate objects is not mandatory. In the example below, class A has an attribute b, which is of type B (see association). This class in turn has a string attribute named aString.
Figure: Creating Instances of Related Classes
In order to instantiate all classes and setting the string aString, not all class instances need to be created. Only the top-level class needs to instantiated as shown in the following action script: