|
Re: Transformation of UML models with stereotypes (profiles) [message #1723857 is a reply to message #1723849] |
Thu, 18 February 2016 09:00   |
Eclipse User |
|
|
|
Hi,
UML Elements have a #getStereotypeApplication method, returning instances of the required stereotypes. You can manipulate with two distinct approaches:
- Explicitly: you need to specify the profile URI in your transformation, then you can use oclAsType() to cast the stereotype application to your specific stereotype. Once this is done, you can access the stereotype properties directly
- With the generic API: using #getValue(Stereotype, Name) and #setValue(Stereotype, Name, Value)
modeltype uml "strict" uses 'http://www.eclipse.org/uml2/5.0.0/UML';
modeltype sysml "strict" uses 'http://www.eclipse.org/papyrus/0.7.0/SysML';
modeltype sysmlBlocks "strict" uses 'http://www.eclipse.org/papyrus/0.7.0/SysML/Blocks';
transformation StereotypesTransform(inout model : uml);
main() {
model.objectsOfType(Class).map blockToEncapsulated();
model.objectsOfType(Class).map blockToEncapsulatedGeneric();
}
mapping inout Class::blockToEncapsulated() when { /* Using the SysML API: modeltypes need to be declared for each sub-profile */
self.getAppliedStereotype("SysML::Blocks::Block") <> null
}{
var blockStereotype : Stereotype := self.getAppliedStereotype("SysML::Blocks::Block");
var block : Block := self.getStereotypeApplication(blockStereotype).oclAsType(Block);
block.isEncapsulated := true;
}
mapping inout Class::blockToEncapsulatedGeneric() when { /* Using the UML Reflexive API: you don't need the modeltypes, but you're manipulating Strings and Objects... Very error-prone */
self.getAppliedStereotype("SysML::Blocks::Block") <> null
}{
var blockStereotype : Stereotype := self.getAppliedStereotype("SysML::Blocks::Block");
self.setValue(blockStereotype, "isEncapsulated", true);
var isEncapsulated : Boolean := self.getValue(blockStereotype, "isEncapsulated").oclAsType(Boolean);
}
|
|
|
Re: Transformation of UML models with stereotypes (profiles) [message #1723858 is a reply to message #1723849] |
Thu, 18 February 2016 09:02   |
Eclipse User |
|
|
|
Hi
It's not very exciting code but the following extract from
http://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/qvto/UML2EcoreSynthesizer.qvto
accesses the Ecore::EDataType:instanceClassName stereotype field.
mapping inout Ecore::EClassifier::installInstanceClassName(in types :
Set(UML::Type), stereotypeName : String)
{
var stereotypedTypes : Set(UML::Type) :=
types->select(getAppliedStereotype(stereotypeName) <> null)->asSet();
var stereotypedType : UML::Type := stereotypedTypes->any(true);
-- var stereotypes : Set(UML::Stereotype) :=
createType.oldTypes.oclAsType(UML::DataType).getAppliedStereotype('Ecore::EDataType')->asSet();
-- log('stereotypedType', stereotypedType);
var instanceClassName : String :=
stereotypedType.getValue(stereotypedType.getAppliedStereotype(stereotypeName),
'instanceClassName').oclAsType(String);
-- log('instanceClassName', instanceClassName);
self.instanceClassName := instanceClassName;
-- result.defaultValue := instanceClassName;
}
Regards
Ed Willink
On 18/02/2016 13:31, Supernova S. wrote:
> Hi,
>
> How is it possible to transform a UML model which has applied
> stereotypes from a profile, e.g., EAST-ADL ? How can stereotypes be
> read and accessed in model transformation code?
>
> Basically, I am looking for an example transformation code (in QVTo or
> ATL) that transforms a Papyrus UML model which has stereotypes.
>
> Can anyone provide or point me to such an example?
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.06688 seconds