integrating alf editor with eclipse uml editors

11

Click here to load reader

Upload: lcodrutlucian

Post on 29-Nov-2015

22 views

Category:

Documents


0 download

DESCRIPTION

Integrating Alf Editor with Eclipse UML Editors

TRANSCRIPT

Page 1: Integrating Alf Editor with Eclipse UML Editors

KNOWLEDGE ENGINEERING: PRINCIPLES AND TECHNIQUESProceedings of the International Conference on Knowledge Engineering,Principles and Techniques, KEPT2011Cluj-Napoca (Romania), July 4–6, 2011, pp. 1–??

INTEGRATING ALF EDITOR WITH ECLIPSE UML

EDITORS

CODRUT-LUCIAN LAZAR

Abstract. In this paper we present an approach for integrating graphicaland textual editors for UML models in Eclipse workbench. In our concreteexample, we are integrating an Eclipse Xtext based textual editor for OMGAlf language, with the Eclipse UML2 tree editor for UML models. Thisintegration enables the user to view and edit the operation behavior ofUML classes from a big UML model using a textual editor with OMG Alflanguage.

The integration will also benefit the ComDeValCo framework, where weneed to model the functionality of the components created with a graphicaleditor.

1. Introduction

The Executable Foundational UML (fUML [9]) is a computationally com-plete and compact subset of UML [7], designed to simplify the creation ofexecutable UML models. The semantics of UML operations can be specifiedas programs written in fUML.

Currently, there is a standardized concrete textual syntax for a fUMLbased action language. The concrete syntax is standardized by Object Man-agement Group (OMG) and it is called Action Language for FoundationalUML (Alf) [8]. A few other action languages exist, some of them being pro-prietary. None of these action languages are based strictly on fUML, so ourresearch will focus on using the Alf language.

We also introduced an action language based on fUML [4], with a concretetextual syntax similar to the concrete syntax of the structured programminglanguages (e.g. Java, C++). As Alf does not restrict the way the concretetextual constructs are mapped to the fUML structures of elements, we will

Received by the editors: 31.07.2011.2010 Mathematics Subject Classification. Software, Programming languages.1998 CR Categories and Descriptors. D.2.2 [Software]: SOFTWARE ENGINEERING:

Design Tools and Techniques – Computer-aided software engineering (CASE); .Key words and phrases. Eclipse, EMF, Xtext, fUML, UML, Alf, Action Language.

c⃝2011 Babes-Bolyai University, Cluj-Napoca

1

Page 2: Integrating Alf Editor with Eclipse UML Editors

2 CODRUT-LUCIAN LAZAR

use our previous experience in order to define these mappings and implementa textual editor in Eclipse.

In order to be able to use an Alf textual editor in a real environment, itis needed to integrate the textual editor for Alf language with existing UMLgraphical editors. We have chosen Eclipse as the modeling environment inwhich to try to develop our modeling tools. The UML graphical editors areimplemented using Eclipse tools: tree editors, or diagram editors based onEclipse Graphical Modeling Framework (GMF) tool. For the Alf language, wecan use the Eclipse Xtext utility [2], on top of which we can implement oureditor. Xtext offers a simple way to define the textual grammar and generatesa textual editor that can serve for us as a starting point.

The main problem is that these Eclipse editors work with resources thatcannot be nested, and we need to be able to view and edit only parts of thebigger UML model with our Alf editor.

This paper is a technical paper that will describe how we achieved theintegration of the graphical UML editor (tree based, in this example) and thetextual Alf editor.

The remainder of the paper is organized as follows: section 2 presents thegeneral context and section 3 presents the research problem. Then, section 4describes the integration approach we propose. Section 5 presents the existingwork related to ours and section 6 gives the conclusions of this paper.

2. Background

Creating executable UML models is difficult, because the UML primitivesintended for execution (from the UML Action Semantics package) are too lowlevel, making the process of creating reasonable sized executable UML modelsclose to impossible. In order to speed up the process of writing the behavior,different approaches have been used. One approach was to replace the behaviorwith opaque expressions expressed in the destination programming language(Java, C++) and add them directly in the UML model. Another approachwas to fill in the behavior after code generation, in the special marked places.These types of models do not react well to changes in the target programminglanguages or frameworks. Also, simulating the execution of these types ofmodels and testing them is not easy.

The fUML standard provides a simplified subset of UML Action Seman-tics package (abstract syntax) for creating executable UML models. It alsosimplifies the context to which the actions need to apply. For instance, thestructure of the model will consist of packages, classes, properties, operationsand associations, while the interfaces and association classes are not included.

Page 3: Integrating Alf Editor with Eclipse UML Editors

INTEGRATING ALF EDITOR WITH ECLIPSE UML EDITORS 3

Creating fUML models is still a hard thing to do, so it is required to usea concrete textual syntax for this.

A concrete textual syntax is in process of being standardized by OMG - Alflanguage. With this easy-to-use concrete syntax, the creation of executableUML models will become an easy task. A textual syntax enforces a certainway of constructing models, which means that a lot of elements that need tobe created explicitly in the graphical UML Activity Diagram can be implicitlyderived from the syntax and created automatically. The control flow betweenthe statements is implicit in structured programming languages. Accessingthe parameters and variables is done with a simple name reference in text,while the model will contain all the object flow edges and fork nodes neededto represent them. And the examples can continue.

What is required at this point is to create editors based on this Alf languageand to integrate them with the existing UML graphical editors and other toolsthat process UML models.

The action language is also useful for our framework: ComDeValCo (Frame-work for Software Component Definition, Validation, and Composition) [10,6, 3]. We want to use it to model the functionality of the components, tosimulate the execution of the models and to test the models [5]. The mainadvantage is to be able to test our models without having to generate code.

3. Research problem

The research problem is to find a way to integrate the textual editor forthe Alf language with other graphical editors for UML models in the Eclipseenvironment.

We have chosen to integrate our textual editor based on Alf language withthe tree based editor for UML from Eclipse. This tree based editor will playthe role of the graphical editor. We wanted to make the integration processin such a way that it does not affect the tree based editor, so that we will beable to integrate our textual editor with any other graphical editor for UMLmodels from Eclipse (UML diagram editors based on Eclipse GMF tool, forinstance).

4. Integrating Eclipse editors

We chose to allow the user to open distinct editors for the resources theyare working with, instead of using a popup. This means that the user canperform changes in parallel, and will expect the undo-redo command stacks(kept in the editor’s EditingDomain) to be distinct for each editor. As such,the integration will be performed at Save points (when the user saves theresource), instead of integrating the editors at every change made by the user.

Page 4: Integrating Alf Editor with Eclipse UML Editors

4 CODRUT-LUCIAN LAZAR

Below, we will explain why this integration approach was chosen and how itis achieved.

4.1. Eclipse Editors and Resources. Similar to any other editor from theEclipse workbench, the UML tree editor from Eclipse loads the model insidea Resource (UMLResource, by default). Our Xtext based textual editor alsoloads the model inside a Resource (XtextResource). Each editor will load andsave the contents inside the Resource it is working with (by delegating the loadand save actions to the Resource, or to the editor’s Document). More, theeditors need the main resource they are working with to be the first resourcein the ResourceSet, and the Xtext editors need the specialized XtextResourceto be used.

A strong argument for choosing to perform the integration at Save pointsis that the Xtext editor’s parser will re-parse, discard and refresh the whole (orpart) of its model at a frequent rate. It is also not feasible to have the textualeditor work on the whole UML model and simply not show the parts on whichwe are not interested (packages, classes, ...), inferring this information behindthe scene.

Fig. 1 shows that an Editor has an EditingDomain, which has, besidesthe command stack (used to support undo-redo operations), the ResourceSetwith the resources accessible to the Editor. The Editor is supposed to applychanges to the main resource, while the resource set may have other resourcesloaded as needed.

Figure 1. Eclipse Editors and associated Resources

4.2. Cross-resource Containment Relations. Suppose the UML model isloaded by the UML graphical editor inside an UML Resource. We want to

Page 5: Integrating Alf Editor with Eclipse UML Editors

INTEGRATING ALF EDITOR WITH ECLIPSE UML EDITORS 5

open a textual editor (which needs a Resource to work with) that will editonly a part of the bigger UML model, more specifically, an Activity.

The general approach is that the contents (model elements) of each Re-source will be saved by that Resource. Each Resource has a root element, andthe elements in that element’s contents tree are supposed to be contained bythe same Resource, and not by another Resource. A model element can haveonly one model element owner or no owner (if it is the root model element).

The Resources cannot be nested, so we cannot have an editor that workson a Resource that represents a partial model from a different Resource. Wecannot have a Resource that is contained by the Activity’s owner, for instance.

At the same time, the whole UML Activity that is generated by the tex-tual editor based on the Alf code will need to be placed at runtime inside thebig UML model, so that it can be validated. The Activity associated with aClassifier’s Operation (as its behavior) needs to be owned by the same Classi-fier. The problem that arises is that the Activity will be created by the Xtexteditor inside its own Resource and it will be contained by this Resource, whichmeans that, under the usual approach from Eclipse, the Activity cannot becontained at the same time by the Classifier from the big UML model, whichis contained by the UML graphical editor’s Resource.

These being said, we need to make use of a certain feature from EMFwhich does not follow the general rules mentioned above and which allows usto use cross-resource containment relations (containment reference proxies) forcertain elements. This feature enables an element to be owned by an elementthat belongs to a resource, and to be saved by a different resource, along withits contained hierarchy of elements. We use this feature in order to persist theActivity with the textual resource, while its Classifier owner will be saved bythe UMLResource (Fig. 2).

Figure 2. Cross-resource containment relation for Activity

This feature can be used only for the meta-models for which it was acti-vated, and it can be used for UML. A certain protocol needs to be used to set

Page 6: Integrating Alf Editor with Eclipse UML Editors

6 CODRUT-LUCIAN LAZAR

an element to be saved by a different resource: first, the model owner needsto be set, then the element’s resource is set to the new resource.

The Xtext parser will discard the model every time a change is made thatrequires a full re-parse operation, and it will not establish the previous cross-resource containment relation for the new root element. This means that themain UML model will now own the previous element created with Xtext (theActivity), and the Xtext editor will work with a different element (anotherActivity). So, we must register a listener to the XtextResource and react tothe add/remove changes in order to maintain this cross-resource containmentrelation.

4.3. Storage for the Textual Representation. Alf standard recommendsto save the textual representation of the operation’s behavior (which is anActivity) inside a stereotyped Comment attached to the Activity inside theUML model. So, we need to make the Xtext editor load and save the tex-tual representation from that Comment. The Xtext parser will create thewhole UML model elements (actions, nodes, edges, ...) that represent the ac-tual Activity functionality represented by the textual representation from theComment’s body. This approach is in contrast with the usual approach fromEclipse, where one Resource is associated with one file. Since we cannot placethe Comment (the source for XtextResource) in an element that is supposedto be generated from the body of that Comment, we’ve considered a differentplace in the model (at this point, the root Model element).

4.4. Usage of Integrated Editors.

4.4.1. Initializing the Textual Resource. The user will start modeling by creat-ing the model structure using the graphical (tree-based) editor. To representthe behavior, empty Activity objects are created (Fig. 3).

Figure 3. Model with an empty Activity

Then, with an action bound to a key, for instance, a special resource iscreated for the Activity (Fig. 4). A Comment will be created to hold the

Page 7: Integrating Alf Editor with Eclipse UML Editors

INTEGRATING ALF EDITOR WITH ECLIPSE UML EDITORS 7

Figure 4. Cross-resource relation established for Activity

textual representation for the Activity. The new custom resource is created(related to the the Comment) and the Activity’s resource is changed to thenew textual resource (the cross-resource containment relation is set). Finally,the initial representation is obtained, by serializing the empty Activity elementinside the Comment’s body.

Figure 5. UML model’s XMI with an empty Activity

Figure 6. Xtext editor for the Activity

Page 8: Integrating Alf Editor with Eclipse UML Editors

8 CODRUT-LUCIAN LAZAR

In our case, the textual language is called EAlf, so we used a special URIfor the resource representing the Activity: ”ealf:/resource/”+<path-to-uml-file>+<comment-id>. It can be noticed that the Activity is represented inXMI with a reference to the resource where it is persisted instead of havingthe usual properties, and that its reference contains the ID of the Comment(Fig. 5). The properties and children of the Activity are obtained by parsingthe Comment’s body.

4.4.2. Edit Model in the Tree-based Editor. The user can edit the Activityand its children directly in the graphical (tree-based) editor (Fig. 7) and thechanges will be visible in the textual editor also (Fig. 8), as the model will beserialized in its textual representation.

The Comment that holds the Activity’s textual representation can also beedited directly, and, on Save operation, the textual resource will be re-loaded,resulting in a re-parse operation of the new text. The changes will also bevisible in the textual editor.

Figure 7. Activity being edited using the tree-based Editor

Figure 8. Xtext editor for the updated Activity

Page 9: Integrating Alf Editor with Eclipse UML Editors

INTEGRATING ALF EDITOR WITH ECLIPSE UML EDITORS 9

4.4.3. Edit Model in the Textual Editor. Finally, the user can edit the Activityby using the textual editor built using Xtext (Fig. 9) and, on Save operations,the changes will be visible in the graphical (tree-based) editor (Fig. 10).

The textual editor’s resource set will need to load the UML resource alsoand resolve the containment proxy relation to the Activity, so that the Activitypasses the validation constraints.

Figure 9. Activity being edited using the Xtext Editor

Figure 10. Changes are visible in the main UML model

4.4.4. UML Model as a Single Resource. As it can be observed from above,the UML model will consist of a main UMLResource, which represents thestructure, and several custom textual resources persisted in Comments, whichrepresent the behavior of the model. If we want to execute such a model,the tool will simply load the main UMLResource, and the system will auto-matically resolve all the references to the textual resources. The system willload the resources, at the same time creating the Activity elements and theirchildren and establishing the containment relations.

From a usage point of view, this approach has no issues. The size of theXMI file will also be smaller if the behavior is stored as text, compared tohaving all the UML elements persisted in XMI.

The main problem is that a larger model would have many Activities,thus resulting in too many extra classes needed to load and parse the textualrepresentations (resource objects, parsers, linkers, ...).

Page 10: Integrating Alf Editor with Eclipse UML Editors

10 CODRUT-LUCIAN LAZAR

If we only want to pass the model that we have constructed to a tool thatexecutes it, for instance, we can execute a task that loads the UMLResourceand the references textual resources, then iterate over the tree of contentsand set the resource of all the elements to be the UMLResource. At last, weneed to save the UMLResource and will obtain an XMI file with all the UMLelements and no reference to the textual resources. Such a file will need lessmemory when loaded. However, if we need to re-edit it, we need the previousfile.

4.4.5. Some Technical Details about the Implementation. The textual editoris loaded for a custom IEditorInput, which represents the custom resource weare using (the Comment). A custom factory for the editor input (IElement-Factory) is also needed, and we need to register it in the Eclipse environment,so that the editor state can be persisted and re-loaded if the Eclipse Work-bench is restarted. A custom factory that creates resources from the customIEditorInput instances is also needed.

To handle the new protocol for the textual resource, a custom EMF Re-source.Factory and a custom URIHandler are configured and used.

5. Related Work

Being able to integrate different editors is a natural requirement for everydevelopment environment. However, what we present in this paper is strictlydependent on the Eclipse IDE.

There have been Eclipse projects where the textual and graphical editorshave been mixed. TEF [1] provides a textual editor integrated as a popupinside the graphical editor, using custom concrete and abstract syntaxes.

The Xtext framework also has two integration examples. In one examplethe graphical and textual editors both work on the whole model, which is notan acceptable approach, as the UML models may become large models and theXtext parser is refreshing the whole model quite frequently. Also, it requiresa textual grammar that covers the whole model. And in the other examplethe textual editor in integrated as a popup inside the graphical editor. Thepopup is still in an experimental phase and it cannot be used as a fully fledgedtextual editor.

6. Conclusions and Further Work

Creating reasonable sized executable UML models is hard, because theUML primitives from the UML Action Semantics package are too low level.The fUML standard provides a simplified subset of UML Action Semanticspackage and it also simplifies the context to which the actions need to be

Page 11: Integrating Alf Editor with Eclipse UML Editors

INTEGRATING ALF EDITOR WITH ECLIPSE UML EDITORS 11

applied. However, an easy-to-use concrete textual syntax is still needed inorder to speed up the process of creating executable models.

In this article, we have presented a way to integrate a textual action lan-guage editor with the existing UML graphical editors in the Eclipse IDE. Theaction language for which we want to create a textual editor is Alf and it isstandardized by OMG. Alf is based on fUML and it follows the structuredprogramming principles, with a concrete textual syntax similar to the mostpopular object-oriented programming languages (e.g. Java, C++).

In the future, we plan to create a fully functional editor based on Alfaction language and also to integrate it into our ComDeValCo framework. Wealready have a prototype textual editor that uses fUML for the abstract syntaxand is implemented as an Eclipse plug-in using Xtext.

References

[1] Textual Editing Framework (TEF), 2008. [Online]. Available: http://www2.informatik.hu-berlin.de/sam/meta-tools/tef/tool.html

[2] Xtext - Language Development Framework, Eclipse Foundation, 2011. [Online].Available: http://www.eclipse.org/Xtext/

[3] C.-L. Lazar and I. Lazar, “On Simplifying the Construction of Executable UML Struc-tured Activities,” Studia Universitatis Babes-Bolyai, Informatica, vol. LIII, no. 2, pp.147–160, 2008.

[4] C.-L. Lazar, I. Lazar, B. Parv, S. Motogna, and I.-G. Czibula, “Using a fUML ActionLanguage to construct UML models,” 11th International Symposium on Symbolic andNumeric Algorithms for Scientific Computing, pp. 93–101, 2009.

[5] ——, “Tool Support for fUML Models,” International Journal of Computers, Commu-nications & Control, no. 2, pp. 775–782, 2010.

[6] I. Lazar, B. Parv, S. Motogna, I.-G. Czibula, and C.-L. Lazar, “An Agile MDA Ap-proach for Executable UML Structured Activities,” Studia Universitatis Babes-Bolyai,Informatica, vol. LII, no. 2, pp. 101–114, 2007.

[7] UML Superstructure Specification, Object Management Group Standard, Rev. 2.1.2,2007. [Online]. Available: http://www.omg.org/docs/formal/07-11-02.pdf

[8] Concrete Syntax For UML Action Language (Action Language For Foundational UML- ALF), Object Management Group Standard, Rev. 1.0, Beta 1, 2010. [Online].Available: http://www.omg.org/spec/ALF/

[9] Semantics of a Foundational Subset for Executable UML Models (FUML),Object Management Group Standard, Rev. 1.0, 2011. [Online]. Available: http://www.omg.org/spec/FUML/

[10] B. Parv, S. Motogna, I. Lazar, I.-G. Czibula, and C.-L. Lazar, “ComDeValCo - a Frame-work for Software Component Definition, Validation, and Composition,” Studia Uni-versitatis Babes-Bolyai, Informatica, vol. LII, no. 2, pp. 59–68, 2007.

Department of Computer Science, Babes-Bolyai University, Cluj-Napoca,Romania

E-mail address: [email protected]