Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Applying Profiles and stereotypes(Custom and Standard Profile)
Applying Profiles and stereotypes [message #1849491] Fri, 21 January 2022 14:55 Go to next message
Yves BERNARD is currently offline Yves BERNARDFriend
Messages: 152
Registered: July 2014
Senior Member
Hello,

I do not succeed in applying profiles and stereotypes with an ATL transformation. I had a look on an example form Dennis (UML2Accessors.atl) and I tried to apply the same approach.

My example uses a custom profile and the UML "Standard Profile" that is registered.

Before trying to apply any stereotype I have to apply the profile. I tried them individually first, but I get a runtime error in both cases:

* With the Standard Profile, because it cannot be found
* With the custom profile, because an "ArrayStoreException" is generated

Here is the code.
-- @atlcompiler emftvm
-- @nsURI UML=http://www.eclipse.org/uml2/5.0.0/UML
module TestTransfo;

create OUT: UML from IN: UML, CUST: UML, STD: UML;

rule FromPackage {
	
	from src: UML!Package (not src.oclIsKindOf(UML!Model))
	
	to tgt: UML!Package (
		name <- src.name
		,packagedElement <- src.packagedElement
		,ownedComment <- src.ownedComment
		,profileApplication <- Set{
			thisModule.getCUSTProfile.debug()
--			, 
--			thisModule.getSTDProfile.debug()
			})

}

rule FromComment {
	
	from src: UML!Comment
	
	to tgt: UML!Comment ()
	
	
}

rule FromClass {
	
	from src: UML!Class 
	
	to tgt: UML!Class (		
		name <- src.name)
}

helper def: getCUSTProfile: UML!Profile = UML!Profile.allInstances()->any(p | p.name = 'CustomProfile');
helper def: getSTDProfile: UML!Profile = UML!Profile.allInstances()->any(p | p.name = 'Standard Profile');


The full sample is provided in the attached zip file

What do I do wrong?


Yves
Re: Applying Profiles and stereotypes [message #1849500 is a reply to message #1849491] Fri, 21 January 2022 20:21 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Unfortunately, applying profiles and stereotypes in a structural way tends to break with every update of the UML2 plug-in. UML2 does not support this way of working with profiles and stereotypes. Instead, UML2 requires that you use the applyProfile() and applyStereotype() API methods.

The latest version of the UML2Accessors.atl transformation uses this approach:

rule PublicPropertySingle extends PublicProperty {
	from s : UML2!"uml::Property" in IN (
		s.isSingle)
	using {
		setterName : String = 'set' + s.accessorBaseNameS; }
    to t : UML2!"uml::Property" (
        name <- s.name.debug('PublicPropertySingle')),
	-- Set --
	   setOp : UML2!"uml::Operation" (
	   	name <- setterName,
		class <- s.class,
		visibility <- s.visibility,
		isStatic <- s.isStatic,
		isAbstract <- false,
		ownedParameter <- Sequence{setPar},
		concurrency <- #sequential),
	   setPar : UML2!"uml::Parameter" (
	   	name <- s.name,
		type <- s.type,
		effect <- #update,
		direction <- #"in"),
	   setBehavior : UML2!"uml::OpaqueBehavior" (
	   	specification <- setOp,
	   	ownedParameter <- Sequence{setBPar},
		name <- setterName + 'Behavior',
		language <- Sequence{thisModule.language},
		body <- Sequence{s.setter()}),
	   setBPar : UML2!"uml::Parameter" (
	   	name <- s.name,
		type <- s.type,
		effect <- #update,
		direction <- #"in"),
	   setDep : UML2!"uml::Dependency" (
	   	name <- 'accessor ' + setterName + '()',
		client <- Sequence{setOp},
		supplier <- Sequence{s})
	do {
		setDep.applyStereotype(thisModule.accessor);
		setDep.setValue(thisModule.accessor, 'kind', 'set');
	}
}


Note that the order in which you do things is important for UML2. UML2 won't let you apply a stereotype from a profile that has not yet been applied to the containing Model. Because ATL abstracts from execution order within a single transformation execution, the UML2CaseStudies transformations are organised as a chain of multiple transformation executions: UML2Profiles.atl is executed before UML2Accessors.atl, and ensures that the required profile has been applied before use:

rule ModelProfile extends Model {
    from s : UML2!"uml::Model" in IN (
    	not s.includesProfile(thisModule.accessorsProfile))
    to t : UML2!"uml::Model" (
		name <- s.name.debug('ModelProfile'))
	do {
		t.applyProfile(thisModule.accessorsProfile);
	}
}


The code above even checks whether the profile has already beem applied, so the transformation won't fail if the user has already manually applied the profile to the model.


Cheers,
Dennis
Re: Applying Profiles and stereotypes [message #1849655 is a reply to message #1849500] Fri, 28 January 2022 07:38 Go to previous message
Yves BERNARD is currently offline Yves BERNARDFriend
Messages: 152
Registered: July 2014
Senior Member
Hello Dennis,

Thank you for your help again.
Yves


Yves
Previous Topic:Wrong Uris in the target model
Next Topic:how to generate emftvm file
Goto Forum:
  


Current Time: Sat Apr 27 01:41:32 GMT 2024

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

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

Back to the top