Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL]: Value from Stereotype's Property
[ATL]: Value from Stereotype's Property [message #82559] Wed, 28 May 2008 13:17 Go to next message
Eclipse UserFriend
Originally posted by: amehmood.sophia.inria.fr

Hi All,

I m trying to access the property value of a stereotype applied to a
class. for this i use the getValue function of the uml::Element :

java.lang.Object getValue(Stereotype stereotype, java.lang.String
propertyName)

Retrieves the value of the property with the specified name in the
specified stereotype for this element.

Parameters:
stereotype - The stereotype for which to retrieve the value.
propertyName - The name of the property whose value to retrieve.

The output I am getting is in the form of java Object. How can i convert
it to a string? How can i use it. I have tried to write the following
helper to get its value using the toString() function but in vain.

helper context UML2!"uml::Element" def : getTagValue(sName : String, pName
: String ) : String =
self.getValue(self.getAppliedStereotype(sName),pName).toStri ng();

Can anyone kindly solve this mystery... This will also help many others in
the future.

Regards,
-aamir-
Re: [ATL]: Value from Stereotype's Property [message #82589 is a reply to message #82559] Wed, 28 May 2008 15:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amehmood.sophia.inria.fr

Well I tried this coding also:

helper context UML2!"uml::Element" def : getTagValue(sName : String, pName
: String ) : String =

self.getValue(self.getAppliedStereotypes() -> select(e | e.name =
sName).first(), pName).name;


In this, the way to get the stereotype is changed. its implemented by
Ivano for the ports, but for my case of Classes, its not working.!!!

Aamir
Re: [ATL]: Value from Stereotype's Property [message #82636 is a reply to message #82589] Thu, 29 May 2008 08:19 Go to previous messageGo to next message
Guillaume Doux is currently offline Guillaume DouxFriend
Messages: 56
Registered: July 2009
Member
Hello Aamir,

Last week, I have done the same thing, the helper I use is :

helper context UML!Element def: getVal(stname : String, pname : String)
: String =
self.getValue(self.getAppliedStereotype(stname), pname);

And It works fine, I did not have to put any ".toString".


Hope it helps.

Guillaume

Aamir a écrit :
> Well I tried this coding also:
>
> helper context UML2!"uml::Element" def : getTagValue(sName : String,
> pName : String ) : String =
>
> self.getValue(self.getAppliedStereotypes() -> select(e | e.name =
> sName).first(), pName).name;
>
>
> In this, the way to get the stereotype is changed. its implemented by
> Ivano for the ports, but for my case of Classes, its not working.!!!
>
> Aamir
>
>
Re: [ATL]: Value from Stereotype's Property [message #82713 is a reply to message #82636] Thu, 29 May 2008 20:21 Go to previous messageGo to next message
Rasha is currently offline RashaFriend
Messages: 61
Registered: July 2009
Member
Hi Guillaume,

I used this helper in a simple example as followed

module SampleUMLProfile2Problem_2; -- Module Template
create OUT : UML2 from IN : UML2, IN_profile : UML2;

helper context UML2!Element def: getVal(stname : String, pname : String) :
String =
self.getValue(self.getAppliedStereotype(stname), pname);

rule Copyclass{
from
s : UML2!Class (s.getVal('MyStereotype','myProperty')= 'value1')
to
t : UML2!Class(
name <- s.name
)
}
It gives me an error, whether I specify the compiler or not. The inputs
are uml files produced by Papyrus. Do you use the same UML tool?

java.lang.NullPointerException
at
org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.real Invoke(ASMUMLModelElement.java:624)
at
org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.invo ke(ASMUMLModelElement.java:581)
at
org.eclipse.m2m.atl.engine.vm.ASMOperation.realExec(ASMOpera tion.java:240)
at org.eclipse.m2m.atl.engine.vm.ASMOperation.exec(ASMOperation .java:171)
at
org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke(ASM OclAny.java:143)
at org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke

Any hint is greatly appreciated,

Rasha
Re: [ATL]: Value from Stereotype's Property [message #82818 is a reply to message #82713] Fri, 30 May 2008 08:22 Go to previous messageGo to next message
Guillaume Doux is currently offline Guillaume DouxFriend
Messages: 56
Registered: July 2009
Member
Hi Rasha,

I use Papyrus too.

In my sample transformation I don't have the IN_profile parameter, it
seems not to be usefull, in my case it works with something like :

" create OUT : UML2 from IN : UML2; "

but I think it is not very important :)

I think your problems comme from the way you specify the name of your
stereotype. You must use the full name of it. So you must have something
like :

" s.getVal('YourTestProfileName::MyStereotype', 'myProperty') "

Hope this helps,


Guillaume.


> Hi Guillaume,
>
> I used this helper in a simple example as followed
> module SampleUMLProfile2Problem_2; -- Module Template
> create OUT : UML2 from IN : UML2, IN_profile : UML2;
>
> helper context UML2!Element def: getVal(stname : String, pname : String)
> : String =
> self.getValue(self.getAppliedStereotype(stname), pname);
>
> rule Copyclass{
> from
> s : UML2!Class (s.getVal('MyStereotype','myProperty')= 'value1')
> to t : UML2!Class( name <- s.name
> )
> }
> It gives me an error, whether I specify the compiler or not. The inputs
> are uml files produced by Papyrus. Do you use the same UML tool?
>
> java.lang.NullPointerException
> at
> org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.real Invoke(ASMUMLModelElement.java:624)
>
> at
> org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.invo ke(ASMUMLModelElement.java:581)
>
> at
> org.eclipse.m2m.atl.engine.vm.ASMOperation.realExec(ASMOpera tion.java:240)
> at
> org.eclipse.m2m.atl.engine.vm.ASMOperation.exec(ASMOperation .java:171)
> at
> org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke(ASM OclAny.java:143)
>
> at org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke
>
> Any hint is greatly appreciated,
>
> Rasha
>
Re: [ATL]: Value from Stereotype's Property [message #83073 is a reply to message #82818] Sat, 31 May 2008 01:06 Go to previous message
Eclipse UserFriend
Originally posted by: amehmood.sophia.inria.fr

Thanks Guillaume & Rasha,

I solved the issue that was bothering me. Actually what i have noitced
important is that the getValue function to get the value of an attribute
on the stereotype returns an 'Object':

-- Get the value from the Property of the Stereotype.
helper context UML2!"uml::Element" def : getTagValue(sName : String,
pName : String ) : String =
self.getValue(self.getAppliedStereotypes() -> select(e | e.name =
sName).first(), pName);

so, if the attribute in the stereotype is of type string, u can directly
retrieve it with the above code, hence the java object placeholder is
string in this case. but, as i have seen in an example by Ivano, if the
stereotype's attribute has the enumeration type then he uses .name at
the end to get the value. This was what Rasha once used in one of her
codes, and from there my confusions started.

anyways, if anyone thinks i m wrong plz do inform me. It will be really
appreciating.

Have a Nice day,

-aamir jadoon-
INRIA, France.





Guillaume Doux wrote:
> Hi Rasha,
>
> I use Papyrus too.
>
> In my sample transformation I don't have the IN_profile parameter, it
> seems not to be usefull, in my case it works with something like :
>
> " create OUT : UML2 from IN : UML2; "
>
> but I think it is not very important :)
>
> I think your problems comme from the way you specify the name of your
> stereotype. You must use the full name of it. So you must have something
> like :
>
> " s.getVal('YourTestProfileName::MyStereotype', 'myProperty') "
>
> Hope this helps,
>
>
> Guillaume.
>
>
>> Hi Guillaume,
>>
>> I used this helper in a simple example as followed
>> module SampleUMLProfile2Problem_2; -- Module Template
>> create OUT : UML2 from IN : UML2, IN_profile : UML2;
>>
>> helper context UML2!Element def: getVal(stname : String, pname :
>> String) : String =
>> self.getValue(self.getAppliedStereotype(stname), pname);
>>
>> rule Copyclass{
>> from
>> s : UML2!Class (s.getVal('MyStereotype','myProperty')= 'value1')
>> to t : UML2!Class( name <- s.name
>> )
>> }
>> It gives me an error, whether I specify the compiler or not. The
>> inputs are uml files produced by Papyrus. Do you use the same UML tool?
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.real Invoke(ASMUMLModelElement.java:624)
>>
>> at
>> org.eclipse.m2m.atl.drivers.uml24atl.ASMUMLModelElement.invo ke(ASMUMLModelElement.java:581)
>>
>> at
>> org.eclipse.m2m.atl.engine.vm.ASMOperation.realExec(ASMOpera tion.java:240)
>>
>> at
>> org.eclipse.m2m.atl.engine.vm.ASMOperation.exec(ASMOperation .java:171)
>> at
>> org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke(ASM OclAny.java:143)
>>
>> at org.eclipse.m2m.atl.engine.vm.nativelib.ASMOclAny.invoke
>>
>> Any hint is greatly appreciated,
>>
>> Rasha
>>
Previous Topic:[QVTO] Iteration over collection
Next Topic:[ATL] Adding elements to collections
Goto Forum:
  


Current Time: Fri Apr 19 20:04:10 GMT 2024

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

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

Back to the top