Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » apply stereotype on element Problem!(I use applySereotype(),but there's no corresponding element.)
icon5.gif  apply stereotype on element Problem! [message #1115515] Tue, 24 September 2013 07:48 Go to next message
BaiChuan Nie is currently offline BaiChuan NieFriend
Messages: 5
Registered: September 2013
Junior Member
I wrote QVTo like this:

transformation CIM_To_PIM(in cim : UML,in profile : UML, out pim : UML);
property web_prof = profile.objectsOfType(UML::Profile)->asOrderedSet()->first();
property web_stereo = profile.objectsOfType(UML::Stereotype);
property web_model:UML::Model = null;
main() {
cim.rootObjects()[UML::Model]->map model2WebModel();
}
mapping UML::Model::model2WebModel() : UML::Model {
... ...
this.web_model := result;
packagedElement += self.nestedPackage->select(p|p.getAppliedStereotypes()->exists(name='CIM'))->asOrderedSet()->first().nestedPackage->map function2package();
}

mapping UML::Package::function2package() : UML::Package
when{self.getAppliedStereotypes()->exists(s|s.name='functionSet')}
{
... ...
packagedElement += self.map endFunction2Controller();
}
mapping UML::Package::endFunction2Controller() : UML::Class
when{
not self.nestedPackage->collect(p|p.getAppliedStereotypes())->exists(s|s.name='functionSet') and
not self.ownedElement[UML::Class]->isEmpty()
}
{
... ...
this.web_model.ownedType += result;
result.getApplicableStereotypes()-> forEach(stereotype){
log("applicable stereotype:", stereotype.name);
};
result.applyStereotype(web_stereo->any(name='controller'));
result.getAppliedStereotypes()-> forEach(stereotype){
log("applied stereotype:", stereotype.name);
};
}

Strange, the log output like below:
applicable stereotype:, data: validator
applicable stereotype:, data: controller
applicable stereotype:, data: logger
applicable stereotype:, data: exception
applied stereotype:, data: controller

but,in XMI,there is no element such as <controller:controller ... base_Class=""/>。
why the stereotype applied isn't sierialized into XMI???
Re: apply stereotype on element Problem! [message #1116692 is a reply to message #1115515] Wed, 25 September 2013 18:56 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi BaiChuan,

You have to apply profile to model first. For example you can place a call to "result.applyProfile(profile)" in 'model2WebModel()' mapping.

Regards,
Sergey.

Re: apply stereotype on element Problem! [message #1116705 is a reply to message #1116692] Wed, 25 September 2013 19:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Sergey

Any change we can add this to a Wiki FAQ and/or a simple how to use UML
stereotypes example?

Regards

Ed Willink

On 25/09/2013 14:56, Sergey Boyko wrote:
> Hi BaiChuan,
>
> You have to apply profile to model first. For example you can place a
> call to "result.applyProfile(profile)" in 'model2WebModel()' mapping.
>
> Regards,
> Sergey.
>
>
Re: apply stereotype on element Problem! [message #1118075 is a reply to message #1116692] Fri, 27 September 2013 03:37 Go to previous messageGo to next message
BaiChuan Nie is currently offline BaiChuan NieFriend
Messages: 5
Registered: September 2013
Junior Member
I have apply the profile on the model, It is in the mapping model2WebModel,I forgot to paste:
mapping UML::Model::model2WebModel() : UML::Model {
name := self.name+'_Web_PIM';
result.applyProfile(web_prof);
this.web_model := result;
packagedElement += self.nestedPackage->any(p|p.isAppliedStereotype('CIM')).nestedPackage->map function2package();
}

But It is no use!


Now I want to use EAnnotation to replace Stereotype!
But there is still a little problem.

By the way,can I get your MSN or Email?Expecting for you help...
Re: apply stereotype on element Problem! [message #1226838 is a reply to message #1118075] Thu, 02 January 2014 21:39 Go to previous messageGo to next message
Ed Seidewitz is currently offline Ed SeidewitzFriend
Messages: 9
Registered: July 2011
Junior Member
I just came across this, because I was having some similar problems. In case no one has addressed your issue since September, I believe the problem is that you are trying to apply the stereotypes during the mapping process, which is before the result of the mapping gets added to the package to which the profile is applied.

When you try to apply a stereotype to an element, Eclipse UML2 checks to see if there is a profile with that stereotype applied to any package in which the element is contained (directly or indirectly). If there is not, then the stereotype is not applied. Since you are trying to apply the stereotype before the element is put in the package with the applied profile, the stereotype does not get applied.

In order to get it to work, you have to do the function2package mapping without applying the stereotypes, add the results to the top-level Web Model, and then go back through and apply the stereotypes where appropriate.

[Updated on: Fri, 03 January 2014 23:27]

Report message to a moderator

Re: apply stereotype on element Problem! [message #1238302 is a reply to message #1226838] Sat, 01 February 2014 00:00 Go to previous messageGo to next message
Naif Mokhayesh is currently offline Naif MokhayeshFriend
Messages: 31
Registered: November 2011
Member
Hi Ed Seidewitz,

could you please elaborate more on your suggested solution with simple example. In fact, I tried to follow it, but getAppliedStereotypes() shows the correct results during transformation execution verification and nothing added to output xmi file.

More detailes in http://www.eclipse.org/forums/index.php/t/642760/

thanks
Re: apply stereotype on element Problem! [message #1758611 is a reply to message #1238302] Thu, 30 March 2017 14:30 Go to previous message
Siegfried Nolte is currently offline Siegfried NolteFriend
Messages: 48
Registered: August 2009
Member
Some time has gone by and I don't know whether this case has been solved by now.

Yet I think, Ed is right. I came to a solution by dividing model transformation and applying stereotypes to some model elements. I do this in two steps following each other.

First the Transformation:

modeltype UML uses 'http://www.eclipse.org/uml2/5.0.0/UML';
/* CIM2PIM */
transformation CIM2PSM ( in businessmodel : UML, out fachkonzept : UML );
...

Second the applying job:

modeltype UML uses "http://www.eclipse.org/uml2/5.0.0/UML";

transformation ApplyStereotypes2Model (inout model : UML, in profile : UML );

main () 
{
  log ('Beginn ApplyStereotypes2Model');
  var prof  : Profile := profile.objects()![Profile];
  model.objects()[Model]->stereotypeModel(prof);
  log ('Ende ApplyStereotypes2Model');
}

helper Model::stereotypeModel(prof:Profile) 
{
  var packages : Set(Package) := null;
  self.applyProfile(prof);
  model.objectsOfType(Package)->forEach ( idx ) { idx.stereotypePackage(prof); }; 
}

helper Package::stereotypePackage(p : Profile)
{
-- 	self.applyProfile(p);
  
    if (not self.isProfileApplied(p))
	then log ( self.name + ' has not applied profile  ' + p.name)
	endif;
	  
	if ( self.name = 'UI' or  self.name = 'DB' )
	then 
	{
		var stname:String := null;
		var st:Stereotype := null;
		
		if (self.name = 'UI') then stname := 'presentation' 
		else stname := 'persistent'	endif;
		
		st := p.ownedStereotype->select(name = stname)->any(true);

		if (st = null)
		then log ( stname + ' not found for ' + self.name)
		endif;

		if (not self.isStereotypeApplicable(st))
		then log ( st.name + ' is not applicable to package ' + self.name)
		endif;
	  
		self.applyStereotype(st);
	
		if (not self.isStereotypeApplied(st))
		then log ( '<' + st.name + '>' + ' is not applied to package '   + self.name)
		else log ( '<' + st.name + '>' + ' has been applied to package ' + self.name)
		endif;
	
		self.ownedMember->forEach(idx) 
		{
			if (idx.oclIsTypeOf(Class))	then idx.stereotypeClass(p, self.name) endif;
		}
  }
  endif; 
} 

helper NamedElement::stereotypeClass(p : Profile, type : String)
{
	var stname:String := null;
	var st:Stereotype := null;
		
	if (type = 'UI') then stname := 'mvc' else stname := 'entity' endif;
		
	st := p.ownedStereotype->select(name = stname)->any(true);

   if (not self.isStereotypeApplicable(st))
   then log ( self.name + ' has not applicable stereotype ' + st.name)
   endif;

   self.applyStereotype(st);

   if (not self.isStereotypeApplied(st))
	then log ( '<' + st.name + '>' + ' is not applied to package '   + self.name)
	else log ( '<' + st.name + '>' + ' has been applied to package ' + self.name)
   endif;
} 

helper printStereotypes( el : Set(Stereotype) )  
{
   el->forEach ( idx ) { var s : Stereotype := idx; log ( "   <" + s.name + ">" );  }; 
   log (''); 
}


This transformation takes an existing model (inout) and applies stereotypes of a given Profile to its packages and classes.

It works with me.

Regards,
Siegfried

[Updated on: Thu, 30 March 2017 14:34]

Report message to a moderator

Previous Topic:Semantics of xmap on a null value
Next Topic:EMF to EMF Transformation
Goto Forum:
  


Current Time: Thu Apr 18 23:14:46 GMT 2024

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

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

Back to the top