Pages

February 7, 2013

Model decoration

When you model a system, you use a specific language (meta-model) to represent information. So, you use a particular language fitted to your business needs. It may be required to specialize this model giving a precise semantics on each object, but also to rise above it through other business concepts to read, understand, exploit it better or enhance it from different viewpoints. So, you can imagine to manage a requirements model which decorates/references/plugs in a design model allowing to check that this last one is conform to the specifications.

In the example below, I focus on the decoration of a UML model with a DSL (Domain Specific Language). The need was to configure a UML model (design of communicating components) and to test these configurations against code generation. Each configuration defines a combination of different and particular communication protocols to use on the connectors between components. And, of course, each protocol brings its own parameters which may be quite difficult to model directly on the UML model (with profile/stereotypes for e.g.) and which may involve structural impacts.

To define the DSL, I have chosen to create a generic language to address any model decorations or configurations. The aim is to base on a generic behavior in order to create easily new decoration concepts and to benefit from a set of wired facilities (At the level of meta-model implementation, decoration instantiation with its life-cycle management and code generation). I inspired from the principles of Architectural Description/Styles Language that I extremely simplified, defining two main concepts: a Configuration and a Parameter, a Configuration being able to own a set of parameters. For me, a Configuration or a Parameter are a kind of Decoration.

Then I extended this meta-model to define my own decoration in order to configure the UML model with the Ethernet protocol (use case presented below). So, I described an Ethernet Configuration which is a kind of Configuration and which applies on UML connectors. As Parameter of this Configuration, I defined the concept of Container which will be intended to federate the components communicating from each side of the connectors configured with this protocol. An IP address and port number have to be set on each Container.

What is presented below can be downloaded from the TopCased project: "UML to real time Java with RTSJ".

At the end of the video, I introduce how it is possible to strengthen the understanding of his configuration/architecture, approaching model decoration through graphical viewpoints (out of scope of TopCased project). For that, I rely on the free UML Designer, based on the Viewpoint technology of Obeo Designer, which can be installed from the Eclipse Marketplace and whose the configuration is Open Source. The interest of this designer is that it is easily integrable with other designers based on the same technology and easily extensible.

The use case can be watched here:


french version here

This puts in relief other benefits of model decoration.
Indeed, it enables to distinct the applicative preoccupations from the architectural ones and to make evolving the last ones easily without impacting the decorated model.
Then, it allows to apply, on the same model, different configurations, and so to be modular.
Besides, the readability of information is improved through a fit language, some wizards and suitable viewpoints.
At last, the UML model is not dependent from some configuration, and so it is more inter-operable. In the same way, the concepts of the decoration may evolve without impacts on the UML model.

December 11, 2007

Validation of Models with Acceleo (Part 2)

The second one (Part 2) consists in creating Acceleo services.

This solution provides additionnal functionalities in relation to the first one. Indeed, as the rules are written in Java language, you can decide that a specific rule won't overload a generic one for example...

I've created a "ValidatorServices" class which implements a mechanism to validate a model and get the report from templates, thanks to the services that it provides. The end-user has just to extend this one and to implement the "checkRules" abstract protected method in order to define his own rules.
He can use "validate", "isErrorChecking" or "isWarningChecking" services to validate his model.

But the main new feature consists in giving the possibility to use the result of the validation report and to act on the generation or not. Let's interest by this feature:

The "isErrorChecking" and "isWarningChecking" are able to notify if an error/warning at least has been detected. So, "isErrorChecking" may be used for example to forbid the generation if it returns true.

The "ValidatorServices" class manages a "singleton" behaviour in order to have only one validation launch per generation and to optimize the process.
Moreover, it manages a workaround about Acceleo architecture limitation on the instanciating of custom services between templates...

Indeed, the services don't share the same context between each template. So, let's take an example with two templates where each of them generates a file. We knows that the generation depends on the "file" parameter. Consequently, it's in this place that you have to use "isExistingError" if you want to control the generation. Not to have as many validation launches as templates which generate files, it is required to keep report in memory. To do that, the "ValidatorServices" retrieve data from a temporary file, in the temporary directory of the OS (Java environment variable). You can use a custom action to delete this file (clean data context) at the end of the generation process.
IsXXXChecking use temporary file only if it is called in different templates which generate files.


The main benefit of this way is to be able to cancel the generation if the validation process has thrown errors or warnings... according to your rules.
Then, it provides a flexibility for the use of the validation mechanism (priority of rules, control generation...) thanks to the Java language. So, applying a rule on a "super" meta-class and an other one on a "child" meta-class, you can decide to display the both respective messages if these rules are not checked (and not only the "child" one).

The concern is the technical heaviness of the solution which might be managed, in a more transparent way, by the acceleo core.
Then, the use of Java language involves a loss of the Acceleo features (debugging, traceability...).

December 10, 2007

Validation of Models with Acceleo (Part 1)

With Acceleo, you can define your own functional validation rules on a model and log messages according to them, during code generation.

I suggest different ways to define the validation rules.

The first one (Part 1) consists in creating a simple Acceleo template where each script defines a set of rules to check on a particular meta-class of the meta-model.

I've created basic java services to log messages with different severities. These messages take as parameter the condition to check (a boolean) and the text to display if this one is false.

We knows that a script may be called if the « file » parameter is setted or if an other script calls it. We also knows that this parameter is used to decide to generate or not the code and to specify where it has to be generated.
In our specific case, we want to activate rules sets without generating code. So, each script owns a « file » parameter which is a call script returning nothing and which gets the particularity to call back the right script to run the rules to apply.

You can see a demo with an example of a template in order to validate a State Machine UML2 model:

The benefit of this way is really the easiness to define the rules thanks to Acceleo Language.
The generic rules (in this example, on the « Named Elements ») apply only on the objects not concerned by a specific rule (inheriting concept).

The only concern is about using the result of the validation to decide to generate or not, for example. Here, it's not simple to do that because, in a chain, every templates which are called are not able to directly communicate between them.