EMF-IncQuery

Inc-Query is a models query-language. It is based on graph patterns. EMF-incQuery is its implementation for EMF. Its purpose is to query EMF models declaratively. EMF-IncQuery is an alternative to OCL.

EMF-IncQuery allows:

•To declaratively define patterns on model elements.
•To detect and track change on models.
•To navigate models efficiently and use meta-classes in the patterns definition:

PhysicalComponent.deployingPhysicalComponents.ownedPhysicalComponents.name

•Some advanced features are provided like queries on the transitive closure of a pattern.
•It has some advanced features like negation of a pattern, counting of pattern matches, patterns defined by multiple alternative sub-patterns (patternP = patternA OR patternB)
•Pattern are composable. They may be registered in a patterns registry (library) and reused.
•Matching elements types can be unspecified in design time. They are inferred in run-time.
Here are some features of the language shown throw example:
1- Example A :
This example shows:
  • InstanceOf-like filters/patterns.
  • Meta-model navigation.

This pattern returns all logical function couples such that logical function LFA contains LFB. If we suppress LFB from the signature, the result would be “all composite logical functions”:

pattern CompositeLogicalFunctions(LFA, LFB) {

  LogicalFunction(LFA);

LogicalFunction(LFB);

LogicalFunction.containedLogicalFunctions(LFA, LFB);

}

2- Example B:

This example shows:

  • Patterns composition(find), reuse.
  • Negation of patterns (neg).
  • In the first pattern ObjB can be mapped to anything; An “exists” pattern.
  • ObjA’s type is inferred as being an AbstractNamedElement from the call of NamedElementNameIsSet, then “cast” to LogicalFunction.

The patterns returns all Logical Function that are not composite. Notice that NamedElementNameIsSet returns AbstractNamedelements which is an super class of LogicalFunction.

pattern NotCompositeLogicalFunctionsPattern(ObjA) {

LogicalFunction(ObjA);

neg find CompositeLogicalFunctions(ObjA, ObjB);

find NamedElementNameIsSet(ObjA);

}

pattern NamedElementNameIsSet(Obj){

AbstractNamedElement.name(Obj, Name);

}

3- Example C:

This example shows:

  • Patterns can be defined by different alternatives (OR)

It returns all AbstractNamedElements which name or id are set:

pattern AbstractNamedElementNameOrIdAreSet(Obj)

{

AbstractNamedElement.name(Obj, Name);

}

or

{

AbstractNamedElement.id(Obj, Id);

}

4- Example D:

This example shows:

  • ObjA and ObjB can be matched to the same object
  • We add the « != » constraint to exclude those cases.

pattern CrossProduct(ObjA, ObjB){

LogicalFunction(ObjA);

PhysicalComponent(ObjB);

}

A second illustration of the cross-product:

pattern CrossProductLogicalFunctions(ObjA, ObjB){

LogicalFunction(ObjA);

LogicalFunction(ObjB);

ObjA != ObjB;

}

5- Example E:

This example shows:

  • Count is the only aggregation operator currently available.
  • Getting the opposite doesn’t work by simply negating the matching of the composite rule NamedElementNameIsSet  this way:

N == count neg find NamedElementNameIsSet(Obj).

It looks like a limitation in the current implementation.

This pattern “calculates” how many AbstractNamedElements have their names set

pattern CountNameNotSetInAbstractNamedElements(N)

{

N == count find NamedElementNameIsSet(Obj);

}

Instead, in the current implementation, we need to separate the aggregation from the negation in two patterns like in the following solution:

pattern NameNotSetInAbstractNamedElements(Obj)

{

AbstractNamedElement(Obj);

neg find NamedElementNameIsSet(Obj);

}

// How many AbstractNamedElements don’t have their names set

pattern UnsetNamescount(N){

N == count find NameNotSetInAbstractNamedElements(Obj);

}

6- Example F:

This example shows:

  • can also add constraints on values

pattern OwnedComponents(ObjA, ObjB) {

PhysicalComponent(ObjA);

PhysicalComponent.ownedPhysicalComponents(ObjA, ObjB);

}

pattern CheckMaximumOwnedComponents(Obj, N){

PhysicalComponent(Obj);

N == count find OwnedComponents(Obj, ObjB);

check((N as Integer) > 5 );

}

  • The second pattern returns all physical components that contain more than 5 sub-components.
  • If we need to get all functions whose name doesn’t end with « Function »:

pattern FunctionsNamesPattern(Func) {

LogicalFunction.name(Func, Name);

check(!(Name as String).endsWith(“Function”));

}

 

Conclusion:

EMF-IncQuery is a great querying tool that needs a little adaptation in the beginning because of its pattern matching logic. For those who are used to imperative programming it may take some time and practice. But it is quite powerful and straightforward. The authors also claim that it is highly scalable as it is based on esatblished incremental matching algorithms. They demonstrate their claim in different scientific publications.

I only hope that this tool will be well maintained and improved. For example by adding more aggregation features and set manipulation operators like what we can find in OCL.

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

A first prototype of a WS-BPEL editor with XText

In this post I wanted to quickly give an overview of the power of XText and what you can do with it in two days starting from scratch without any prior knowledge of it.

The first step with XText is to create your grammar, here is a first draft:

The second step is to let XText automatically generate the eclipse editor for you, which is not really a step just a nice thing brough by model-driven development. Here is the editor with an example of the code that conforms to the previously defined grammar:

The automatically generated editor already has syntax verification according to your grammar with syntax errors highlighting and the appropriate error messages, code completion and code coloring.

Now you’re done, but there is more you can do. After the step of syntax verification, for any language you have a step of static semantics verification that needs to take place. XText offers an abstract class in which you can implement all the verification you want. Let’s consider the following example of a static semantics rule:” a web Service should have a unique name inside the model”, this cannot be expressed by the grammar as it is not related to syntax but to the higher level of static semantics. XText generates for you the necessary EMF API to access your model and execute wathever treatment you need. Here is an example:

The final result, is an editor that will show error messages whenever your static semantics rule is not respected:

Conclusion:

Isn’t this great, whenever you need to model a domain, you can create a language that models it and then generate your editor and extend it with any additional computation you want like additional constraints, code and documentation generation, model-to-model transformation and so on.

The END

Posted in Uncategorized | 1 Comment

Using State Machines to Program Lego NXT Robots’ Behavior

Problem: 

We want to model the behavior of an NXT robot using Finite State Machines. Then Translate the FSM to an NXC program semi-automatically. This case study will be the starting point for a model-driven robots programming platform based of finite state machines.

Example: An NXT robot is supposed to have the following behavior:

1-    The robot is idle until the central button is pressed.

2-    When the button is pressed the robot starts moving at 75% of its maximum speed during one second maximum.

3-    During this movement, if it detects an object at a distance < 100cm, it continues moving at only 50% of its speed.

4-    If the one second elapses, it starts moving at 100% of its speed. Then if it detects an object at a distance < 100cm, it continues moving at only 50% of its speed.

5-    If it detects an object at a distance < 20cm, it turns left.

6-    After turning left, it restarts moving at 75% of its speed. Return to point 3.

See Case Study FSM file for the State Machine and the NXC manually “generated” code.

Posted in Uncategorized | Leave a comment

SQL Server 2012 Tutorial

SQL Server Databases Tutorial

Introduction:

This tutorial will help the students apply the theory they learn in the lectures using one of the most spread RDBMS which is Microsoft’s SQLServer. I’m using the 2012 RC0 version of SQLServer.

Prerequisites:

You need to install SQL Server 2012 Express edition which is the database engine (The most important part) and also SQL server management studio which is the graphical interface that facilitates the database creation and query development and execution. They are available under these links:

Under this link you have to select “express with tools” from the “select a product” drop down list and download it. Then go to same link and this time choose “SQL Server management studio” and download it.

http://www.microsoft.com/betaexperience/pd/SQLEXPCTAV2/enus/default.aspx

Install both packages. Notice that you need to give a name to your server, choose any one-word name and choose windows authentification so that you will not need to choose a password, when you are connected to windows, sql server considers you are the right user. This makes things much simpler for the beginner.

….Download the PDF file to get the tutorial: Human Resources Database Tutorial

Posted in Uncategorized | Leave a comment

RDAL: Requirements Definition and Analysis Language for AADL

The requirements language is used to express through a graphical model the functions that should be accomplished by the system and the quality of service under which these functions should be accomplished. These requirements are organized by groups. All the groups are contained in a requirements specification.

When requirements are being elicited by discussing with the client/user, requirements diagrams can be used as a means of communication between both parties. It will also help in keeping track of the requirements analysis process activities. They will also constitute a contract between both parties.

RDAL is meant to be used with AADL (Architechture Analysis and Design Language). Its metamodel is shown in the following figure:

 

RDALTE (RDAL Tool Environment) is integrated into eclipse and allows the edition of RDAL models. Requirements can be created, elicited using refinement,decomposition, derivation, etc. Then each requirement can reference AADL model elements. And OCL (or any other formal constraints description language) constraints can be verified against the AADL model. This figure shows a snapshot of RDALTE:

The RDAL language is beeing standardized by SAE, and the AADL commitee is being discussing the metamodel until a satifying version will be obtained.

Posted in Uncategorized | 2 Comments

First Graphical modeling tool with GMF

GMF, the graphical modeling framework, is a model-driven development framework that builds graphical modeling tools only by defining models. GMF is just awesome, it’a a little hard to start with as the documentation is a bit old (like any opensource tool that respects this label). But when you start understanding the different metamodels it is built upon, you will develop very beautiful graphical modeling tools from scratch in a few hours.

Graphical Modeling Editor for SysML

To obtain such a result, you need to define the metamodel of your DSL (domain-specific language) using EMF. Then you generate the genmodel (model used to generate code to manipulate a model that conforms to your EMF model). Then you need to describe a model of the graphical elements that will appear in your diagram. After that, you define the model of the tool, this model defines the elements of your palette. Then you need to depict the mapping model, which is the most important one. In this model you will tell GMF how elements of the previous three models bind to each other. Now you only clic on a button to generate the model of your tool. Finally you generate the code of your tool.

The great thing with GMF is that you can change anything in your initial models and regenerate the code. You can draw any thing in your diagram, not only boxes and arrows. Like the little circle with a cross that i used to depict a SysML-decomposition just like the SysML specification.

Model-driven develoment is the future, and GMF is the first tool i used that really proves that the model-driven approach is not only a dream. It really works, you need more effort to build the model-driven development framework but much less efforts to use this framework to develop applications. So in the future we may have a hierarchy of two populations of developers. The first population is the developers that model the business domains and build the generative modeling frameworks, and the second, low level population made of the “mouse-clickers” developers, so don’t let yourself behind.

Posted in Uncategorized | Leave a comment

XText : First lessons learned

XText is really a great tool to build language tooling (parser, IDE, metamodel, Java EMF based API, etc). I started by a BNF written C GRAMMAR found on (YACC C). Then i assigned each rule element to a EObject element using the XText assignement :
direct_declarator
: identifier=ID
| ‘(‘ declarator=declarator ‘)’ …

This step eliminates all the XText errors i noticed in the beginning as in XText you need to tell what you want your parser to do with each element of the rule. In the example above, for each direct_declarator EObject, an identifier member or a declarator member will be created to host the ID and the declarator produced elements.

This was the first step to do. Then, You can use the EBNF advantages to factorize your rules using the (*, ?, +) language description artefacts so that to have a more compact grammar definition.

Next step, and this where i am working now, i launched the code generation facility to try to generate my C language tooling from my grammar, but i noticed that errors were triggered due to the fact that XText is based upon ANTLR which doesn’t accept left recursion in the rules (A ->Ab). So, i isolated the problematic rules and i am eliminating left recursion using advices given in the ANTLR wiki

I will tell more about all this after i finish eliminating Left recursion from these 25 rules.

Posted in Uncategorized | Leave a comment