• Keine Ergebnisse gefunden

Eclipse and Associated Technologies

A Quality Model for UML and its Instantiation

5.1 Eclipse and Associated Technologies

This section focuses on Eclipse and associated technologies used in the implemen-tation. The overview of these technologies serves as a base for the understanding of the reader, that how the approach is implemented and how the different parts collaborate.

5.1.1 The Eclipse Modeling Project (EMP)

Eclipse provides a whole range of modeling tools and frameworks, as a part of the Eclipse Modeling Project (EMP). The collection of tools was formed to coordinate and focus on Model Driven Development (MDD) technologies. EMPis a top level project which is logically organized into sub-projects that provide abstract syntax definitions, concrete syntax development, Model-to-Model (M2M) transformation, and Model-to-Text (M2T) transformation.

5.1.2 The Eclipse Modeling Framework (EMF)

Eclipse Modeling Framework (EMF) is a modeling framework and code generation facility for the building of tools and other applications. XMI is used to describe models and the EMF provides tools and runtime support to produce a set of Java classes for the model, a set of adapter classes that enable viewing and command-based editing of the model, and a basic editor. Models can be specified

57

using annotated Java, UML, XML documents, or modeling tools. Additionally, EMFprovides the foundation for interoperability between EMF-based tools and applications [92]. Figure 2.2 [page 8] shows both graphical as well as an EMF representation of aUMLmodel, in which eachUMLnotation is described inXMI.

5.1.3 The XPand Project

The Xpand project focuses on the generation of textual artifacts from models and consists of various languages and components. Xpand is a Model-to-Text (M2T) transformation language featuring polymorphic template invocation, functional ex-tension, model validation and model transformation based on the Xtend language.

The implementation of our prototype tool is based on M2Tthe transformation with Xpand andM2Mtransformation with Xtend. In the following both languages are discussed in detail.

5.1.3.1 The Xpand Code Generation Language

Xpand is a modern template-based code generation language (i.e., Model-to-Text (M2T)) which has become popular in a very short time. Xpand language was originally developed as part of openArchitectureWare (oAW) [65] project before it became part of the EMP. Xpand language provides a powerful mechanism with its limited vocabulary.

In a single M2Ttransformation project, one or more than one Xpand language template can be defined. Each Xpand language template is defined using DE-FINE and ENDDEFINE blocks. The Listing 5.1 shows a simple DEFINE block, where simpleTemplate is the name of the block, and Type is the type of the element, on which this block should be executed. Inside the block statements can be defined.

1 «DEFINEsimpleTemplateFORType»

2

3 some statements...

4

5 «ENDDEFINE»

Listing 5.1: Simple Xpand Template

Xpand language provides multiple features to enable code generation in a smooth way. The following is a set of the important statements in Xpand language.

5.1. ECLIPSE AND ASSOCIATED TECHNOLOGIES 59

5.1.3.1.1 The IMPORT Statement

TheIMPORTstatement enables importing namespace and using the unqualified names contained in the imported namespace. Listing5.2 imports the name spaces of UMLmetamodel for the current template.

1 «IMPORTuml»

Listing 5.2: Import Statement 5.1.3.1.2 The EXTENSION Statement

Extensions provide a flexible and convenient way of defining additional features of metaclasses. In Listing 5.3 An EXTENSION import points to the Xtend language file containing the required extensions.

1 «EXTENSIONmy::ExtensionFile»

Listing 5.3: Extension Statement 5.1.3.1.3 The FOREACH and EXPAND Statements

These statements enable the retrieval of a specific collection and its manipulation inside the body. FOREACHis used in Xpand language templates for retrieving a specific collection of model elements, as described in Listing5.4, whereasrule1 is the name of the DEFINEblock that should be expanded for each use case. The EXPAND statement expands anotherDEFINEblock (in a separate context), inserts its output at the current location and continues with the next statement.

This is similar in concept to a subroutine call.

1 «EXPANDrule1FOREACHeAllContents.typeSelect(UseCase)»

Listing 5.4: The FOREACH and EXPAND Statements 5.1.3.1.4 IF Statement

The IF statement supports conditional expansion. Any number of ELSEIF statements are allowed. TheELSE block is optional. Every IF statement must be closed with an ENDIF. The body of an IF block can contain any other statement, specifically, IF statements may be nested. Listing5.5shows a simple example of an IFblock.

1 «IFexpression»

Listing 5.5: IF Statement

5.1.3.1.5 REM Statement

TheREM statement is used for comments. Listing 5.6showsREM statement, the comments are written inside the block.

1 «REM»

2 This is a sampleREMblock in Xpand template.

3 «ENDREM»

Listing 5.6: REM Statement

5.1.3.2 The Xtend Model-to-Model (M2M) Transformation Language The Model-to-Model (M2M) language Xtend is a part of the Xpand project. Xtend language can also help in formulating readable Xpand language templates by defining reusable operations that access the source model and retrieve data from it. In the prototype Xtend is used for two purposes: with OCL used in Xpand language templates to generate reports, and for refactoring of the UMLmodels.

Listing5.7 shows a sample Xpand language template used to generate a HTML report for violated rules, which callsmyXtendFunction()from the Xtend language file.

1 «DEFINEruleNumberFORuml::Element»

2 «IFmyXtendFunction()===false»

3 <TR>

4 <TD>”Description of rule”</TD>

5 <TD>«qualifiedName»</TD>

6 </TR>

7 «ENDIF»

8 «ENDDEFINE»

Listing 5.7: XPand Language Example for M2T Transformation

Listing 5.8shows, the definition of the renameElement()function in the Xtend, which sets new name for theUMLelement.

1 Boolean renameElement(uml::Element elem):

2 elem.setName(”NewName”)−>true;

Listing 5.8: Xtend Language Example for M2M Transformation

5.1.4 Modeling Workflow Engine (MWE)

The Modeling Workflow Engine (MWE) is a generator engine, which can be configured to run independently or within Eclipse. MWE uses an XML based configuration language to setup a generator workflow, which may consist of one or more workflows. The workflow engine is used to execute transformations of models, i.e. M2T and M2M transformations. In Listing 5.9, Line 1 shows that Xtensible Mark-up Language (XML) version for the wokflow generator and encoding for windows operating system. Line 4 shows how to read a UMLmodel.

The name attribute is used to provide a name for the slot on which model should