Download openArchitectureWare User Guide

Transcript
Chapter 2. Xtext Tutorial
This tutorial shows how easy it is to define an external DSL .
2.1. Installing the pre-built tutorial
The tutorial is based on the Xtext framework as it is contained in oAW 4.2. Make sure that you have installed oAW
4.2 into an Eclipse 3.3 workbench running on Java >=5. The easiest way to get a working IDE is to download
the Eclipse 3.3 distribution for RCP/Plug-in developers from eclipse.org and the oAW all-in-one release from
oAW's website.
2.2. Tutorial overview
The purpose of this tutorial is to illustrate definition of external DSLs using Xtext. The process we're going to go
through will start by defining an Xtext grammar for our DSL, generate a parser, a meta model and a corresponding
text editor out of it. Afterwards we will see how to refine the DSL and it's editor using provided facilities. In the
end we will see how one can generate code out of textual models.
The actual content of this example is rather trivial – we will generate Java classes following the Java Beans
conventions. The model will contain entities (such as Person or Address ) including some attributes and
relationships among them – a rather typical data model. From these entities in the model we want to generate the
Beans for implementation in Java. In a real setting, we might also want to generate persistence mappings, etc.
We will not do this for this simple introduction.
2.3. Defining the DSL
We'll define a DSL for simple domain models following some concepts of Domain-Driven Design.
We don't want to define too much semantic for each of these concepts here because this tutorial is about how
to develope a DSL not why. In addition, most of the semantics of a DSL's concept is usually implemented in a
generator or an interpreter, which is not the focus of this turorial.
We use this example because the concepts are well known (even if the meaning is not formally defined). So we
don't need to explain them or motivate the example but can focus on other things.
The following UML diagram shows the abstract syntax of the DSL we're going to define:
oAW Version 4.2
29