apply stereotype on element Problem! [message #1115515] |
Tue, 24 September 2013 07:48 |
BaiChuan Nie 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 #1226838 is a reply to message #1118075] |
Thu, 02 January 2014 21:39 |
Ed Seidewitz 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 #1758611 is a reply to message #1238302] |
Thu, 30 March 2017 14:30 |
Siegfried Nolte 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
|
|
|
Powered by
FUDForum. Page generated in 0.04537 seconds