Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » second mapping steals first one
second mapping steals first one [message #1043373] Wed, 17 April 2013 16:12 Go to next message
Rudolf Weber is currently offline Rudolf WeberFriend
Messages: 11
Registered: February 2013
Junior Member
Hello,

I want to transform a UML-Statechart into a Class diagramm:

modeltype UML uses "http://www.eclipse.org/uml2/4.0.0/UML";
transformation state2class(in stateM:UML,out classM:UML);

property curmainclass : UML::Class = null;

main()
{
stateM.objectsOfType(StateMachine)->map toPackage();
}

mapping StateMachine::toPackage() : UML::Package
{
name := self.name;
nestedPackage := self.region.map toPackage();
}

mapping Region::toPackage() : UML::Package
{
name := self.name;
var oberklasse = object Class {};
oberklasse.name := "State";
/*!1!*/
oberklasse.ownedOperation := self.transition.map transToOp();

ownedType += oberklasse;
curmainclass := oberklasse;
ownedType += self.subvertex.map toClass();
}

/* jeder Knoten wird in eine Klasse umgewandelt */
mapping Vertex::toClass() : UML::Class
{
name := self.name;
result.superClass += curmainclass;
/*!2!*/
result.ownedOperation += self.container.transition->select(t | t.target = self).map transToOp();

}

mapping Transition::transToOp() : UML::Operation
{
name := self.name;
}

In the output without /*!2!*/ the Class "State" has all the transitions as Operations.

Now /*!2!*/ generates Operations in the concrete State-classes, but there the operations in the Class "State" are missing.

Why ?
May a Mapping has a implicit relation and QVTo can generate only 1:1-Mappings ?
Problem with forEach / Re: second mapping steals first one / Resolve with new objects [message #1043381 is a reply to message #1043373] Wed, 17 April 2013 16:24 Go to previous messageGo to next message
Rudolf Weber is currently offline Rudolf WeberFriend
Messages: 11
Registered: February 2013
Junior Member
Ok, only 1:1-Mapping is allowed.

Thus, I have to generate a new Object:

/*...*/
/* jeder Knoten wird in eine Klasse umgewandelt */
mapping Vertex::toClass() : UML::Class
{
name := self.name;
result.superClass += curmainclass;
//result.ownedOperation += self.container.transition->select(t | t.target = self).map transToOp();
var opset : Set(Operation);
self.container.transition->forEach(t | t.target = self)
{
var op = object Operation { name := t.name; }
result.ownedOperation += op; //!Syntaxerror
}
}

The problem is:
in the {}-Block after forEach the "result" is unknown.
An declared variable is not known in the {}-Block

How to write a new operation-Object forEach Transition in the concrete State-Class ?

(or may this an implementation-Problem ?)

Greetings from Ravensburg/Germany
Rudolf Weber
Re: second mapping steals first one [message #1043822 is a reply to message #1043373] Thu, 18 April 2013 06:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4150
Registered: July 2009
Senior Member
HI

QVTo generates on mapping for each distinct tuple of matching input
objects, so if your input tuple is a single object, you indeed get 1:1.
If you want 1:N you need to introduce an additional disambiguator to the
tuple so that QVTo understands that you do not want the 'multiple'
mappings unified. For instance you might add a count variable to the
mapping.

Regards

Ed Willink


On 17/04/2013 17:12, Rudolf Weber wrote:
> Hello,
>
> I want to transform a UML-Statechart into a Class diagramm:
>
> modeltype UML uses "http://www.eclipse.org/uml2/4.0.0/UML";
> transformation state2class(in stateM:UML,out classM:UML);
>
> property curmainclass : UML::Class = null;
>
> main()
> {
> stateM.objectsOfType(StateMachine)->map toPackage();
> }
>
> mapping StateMachine::toPackage() : UML::Package {
> name := self.name;
> nestedPackage := self.region.map toPackage();
> }
>
> mapping Region::toPackage() : UML::Package
> {
> name := self.name;
> var oberklasse = object Class {};
> oberklasse.name := "State";
> /*!1!*/
> oberklasse.ownedOperation := self.transition.map transToOp();
> ownedType += oberklasse;
> curmainclass := oberklasse;
> ownedType += self.subvertex.map toClass();
> }
>
> /* jeder Knoten wird in eine Klasse umgewandelt */
> mapping Vertex::toClass() : UML::Class
> {
> name := self.name;
> result.superClass += curmainclass;
> /*!2!*/
> result.ownedOperation += self.container.transition->select(t |
> t.target = self).map transToOp();
>
> }
>
> mapping Transition::transToOp() : UML::Operation
> {
> name := self.name;
> }
>
> In the output without /*!2!*/ the Class "State" has all the
> transitions as Operations.
>
> Now /*!2!*/ generates Operations in the concrete State-classes, but
> there the operations in the Class "State" are missing.
>
> Why ? May a Mapping has a implicit relation and QVTo can generate only
> 1:1-Mappings ?
Re: second mapping steals first one [message #1043902 is a reply to message #1043822] Thu, 18 April 2013 08:42 Go to previous messageGo to next message
Rudolf Weber is currently offline Rudolf WeberFriend
Messages: 11
Registered: February 2013
Junior Member
Quote:

If you want 1:N you need to introduce an additional disambiguator to the
tuple so that QVTo understands that you do not want the 'multiple'
mappings unified. For instance you might add a count variable to the
mapping.


Is a "tuple" (source,result,parameter)-tuple in the internal mapping of a QVTo-Run ?

I have added a parameter and it works as expected:
modeltype UML uses "http://www.eclipse.org/uml2/4.0.0/UML";
transformation state2class(in stateM:UML,out classM:UML);

property curmainclass : UML::Class = null;

main()
{
   stateM.objectsOfType(StateMachine)->map toPackage();
}

mapping StateMachine::toPackage() : UML::Package 
{
	name := self.name;
	nestedPackage := self.region.map toPackage();
}

mapping Region::toPackage() : UML::Package
{
   name := self.name;
   var oberklasse = object Class {};
   oberklasse.name := "State";
   oberklasse.ownedOperation := self.transition.map transToOp(1);
   
   ownedType += oberklasse;
   curmainclass := oberklasse;
   ownedType += self.subvertex.map toClass();
}

/* jeder Knoten wird in eine Klasse umgewandelt */
mapping Vertex::toClass() : UML::Class
{
	name := self.name;
	result.superClass += curmainclass;
	result.ownedOperation += self.container.transition->select(t | t.target = self).map transToOp(2);
}

/* called twice, so a parameter is needed */
mapping Transition::transToOp(in dis : Integer ) : UML::Operation
{
	name := self.name;
} 


General question for QvTo:
Ok, I have now transformed a statechart-model to a classmodel.
But the UML-Classmodel doesn't have the semantic to specify the operations.
(I can't see it in the UML2.4.1 Infrastructure/Superstructure)
(May in future an operation have a Action-Sequence as implementation)
Generate code from the generated classes lacks information.

QVto M2T like Acceleo
So Statechart -------> Classmodell ---> Code
seems not the practical way ?

M2T
Statechart -------------> Code

seems simpler and better.

Regards
Rudolf Weber
RE: Statecharts (was Re: second mapping steals first one) [message #1044065 is a reply to message #1043902] Thu, 18 April 2013 13:02 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4150
Registered: July 2009
Senior Member
Hi

Direct M2T is easier when it's easier, but increasingly hard as the
problem gets more complex. Often difficult to re-use.

Since neither Java nor C++ has any StateMachine concepts, you will have
to realize them using Classes and operations, so you could consider

An M2M from: OO-with-states to OO-without-states

so that you can re-use an existing M2T for OO-without-states to code.
The M2M can be OO implementation language neutral and so re-useable.

If your target code is Java, then EMF code gen is viable for the
structure and OCL code gen for the behaviour.

Regards

Ed Willink

On 18/04/2013 09:42, Rudolf Weber wrote:
> General question for QvTo:
> Ok, I have now transformed a statechart-model to a classmodel.
> But the UML-Classmodel doesn't have the semantic to specify the
> operations.
> (I can't see it in the UML2.4.1 Infrastructure/Superstructure)
> (May in future an operation have a Action-Sequence as implementation)
> Generate code from the generated classes lacks information.
>
> QVto M2T like Acceleo
> So Statechart -------> Classmodell ---> Code seems not the practical
> way ?
>
> M2T
> Statechart -------------> Code
>
> seems simpler and better.
>
> Regards Rudolf Weber
Previous Topic:Re: Mapping in/output programmatically
Next Topic:How I get the order of events covered on UML lifeline?
Goto Forum:
  


Current Time: Sun Nov 23 00:15:48 GMT 2014

Powered by FUDForum. Page generated in 0.01674 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software