Date: Thu, 28 Mar 2024 23:28:24 +0100 (CET) Message-ID: <800698071.1197.1711664904150@nm-docs> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1196_651296202.1711664904150" ------=_Part_1196_651296202.1711664904150 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Mapping is the process of generating a UML activity model from = the abstract syntax representation of some Alf code. If this mapping is suc= cessful, then the Alf compiler updates the context element using the genera= ted elements. How this update is done depends on what the context element i= s:
In addition, there may be some generated elements that cannot be stored = in conjunction with the context element. In particular, generated Instance = Specifications are stored in the nearest Package containing the context ele= ment, and generated template instantations are stored in the $$Template Bindings package.
If you have successfully parsed some Alf code text, then you can map tha= t code by calling the map method. (If the parse was not successful= , then calling map has no effect.) Normally, unless there is a sys= tem error, mapping should always complete successfully. Since mapping resul= ts in an update to the UML model, the map method should be called = within a MagicDraw session. This can be done conveniently using the Alf= ActionUtil.executeSession method, which also ensures that any automati= c Alf compilation is turned off during the session, so new compilations are= not accidentally triggered by updates from the mapping process.
AlfCompi= ler compiler =3D new AlfCompiler(); compiler.setContextElement(element); compiler.parse(text); if (compiler.isSuccessful()) { =09AlfActionUtil.executeSession("Map Alf", new Runnable() { =09=09public void run() { =09=09=09compiler.map(); =09=09=09AlfActionUtil.registerDependencies(compiler); =09=09} =09}); }
Rather than separately parsing and mapping some Alf text, y= ou can attempt to do both with one call to the compile method. Thi= s method first parses some text for a given context element and, if that is= successful, maps it and updates the UML model appropriately with the resul= ts of the mapping. If the parse is not successful, then compilation errors = are available using the getCompilerErrors method, as after a call = to the parse method. As for the map method, the compi= le method should be called within a MagicDraw session, since it may po= tentially update the UML model if a mapping is carried out.
Compiler= compiler =3D new AlfCompiler(); AlfActionUtil.executeSession("Compile Alf", new Runnable() { =09public void run() { =09=09compiler.compile(element, text);=20 =09=09AlfActionUtil.registerDependencies(compiler); =09} });