NEW statement
SYNTAX:
new_stmt = NEW [ PERSISTENT ] [ coercion ] assignment_receiver { coercion_qualifier } ?;? .
Conceptually, the NEW statement is similar to a constructor in the C++ language. The NEW statement is used to create an entity instance or an aggregate instance. The statement begins with the keyword NEW optionally followed by the keyword PERSISTENT. Then the specification of the receiver of the created instance or aggregate follows. The reference path of the receiver can be specified using any necessary qualification, i.e. attribute, group, or index qualification.
The entity instance type or the aggregate instance type to be created, is specified by the domain type of the actual attribute or local variable that receives the created instance. Coercion can be used in the NEW statement to specify the exact instance type to create in case the type is not uniquely defined by the domain of the attribute. (See. Coercion in Assignment Statement).
Coercion must always be used when a local identifier of type GENERIC is the receiver of the created instance. Coercion in a NEW statement can only be used when creating a new entity instance, not when creating an aggregate instance.
When the created instance is connected to an attribute of a persistent instance, then the created instance will be persistent in the target model. When the instance is stored in a local variable or in an attribute of a volatile instance, the created instance will be volatile, i.e. it will be located in the temporary working storage of the EDMmodelConverter. The optional keyword PERSISTENT can be used to make the created instance persistent in any case.
A volatile instance will be made persistent when it is stored in (connected to) an attribute of a persistent instance.
The keyword PERSISTENT has no effect when the NEW statement is used to create an aggregate.
The NEW statement will implicitly create new instances for unset attributes in a reference path in the same way as the Assignment statement does. Coercion can be used in all chains of a reference path down to the receiver of the created instance.
The NEW statement cannot create any instances nor aggregates in the source model , only in the target model and in the EDMmodelConverter working space.
Example 1:
NEW p.{subtype1}attr1.attr2.{subtype2}attr3.attr4;
This statement will create an instance and connect it to the attr4 attribute of the instance specified by the reference path in the NEW statement. The actual instance type to create is specified by the domain definition of the actual attr4 attribute. In case any of the attributes attr1, attr2, or attr3 is unset then entity instances will be implicitly created and connected to the actual attributes. For attr1 and attr2 Coercion is used in order to specify exactly the type of the instance to be created.
Example 2:
(*
More examples of using the NEW statement:
*)
LOCAL
aProperty : target::property;
anInstance : GENERIC;
anAggr : SET OF INTEGER;
END_LOCAL;
. . .
(* Create a volatile instance of type target::property *)
NEW aProperty;
(* Create a persistent instance of type person *)
NEW PERSITENT {person}anInstance;
(* Create a volatile aggregate of type SET OF INTEGER *)
NEW anAggr;