Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL]How to get the element type by the element's attribute?
[ATL]How to get the element type by the element's attribute? [message #87797] Thu, 07 August 2008 21:44 Go to next message
Eclipse UserFriend
Originally posted by: zhuangguotao.hotmail.com

Hello, experts,

I want to ask to how to get the element type by the element's attribute?

for example,

<ElementA name="a1">


How to write a helper to get the element type which is ElementA by the
value of the name attribute.

Even, how to write a helper to execute the ElementA's helper based on the
value of the name attribute?

Best regards.

Zhuang
Re: [ATL]How to get the element type by the element's attribute? [message #87858 is a reply to message #87797] Fri, 08 August 2008 08:57 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 71
Registered: July 2009
Member
..oclType()?

Regards,

Alfons

"Zhuang" <zhuangguotao@hotmail.com> schreef in bericht
news:5aff3ff2c5d90550ac88a74f448deb90$1@www.eclipse.org...
> Hello, experts,
>
> I want to ask to how to get the element type by the element's attribute?
>
> for example,
>
> <ElementA name="a1">
>
>
> How to write a helper to get the element type which is ElementA by the
> value of the name attribute.
>
> Even, how to write a helper to execute the ElementA's helper based on the
> value of the name attribute?
>
> Best regards.
>
> Zhuang
>
Re: [ATL]How to get the element type by the element's attribute? [message #87931 is a reply to message #87858] Sat, 09 August 2008 10:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhuangguotao.hotmail.com

the oclType() only returns the oclType of self.

I want to know the how to return the element's oclType by the attribute
value of the element.

Anybody can help me?

Best regards.

Zhuang
Re: [ATL]How to get the element type by the element's attribute? [message #87946 is a reply to message #87931] Sat, 09 August 2008 10:41 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 71
Registered: July 2009
Member
The value of the name attribute is just a String, without any properties.
You cannot do anything with it, ie not navigate the model.
Maybe you need to tell us more about what you are trying to do.


Regards,

Alfons


"Zhuang" <zhuangguotao@hotmail.com> schreef in bericht
news:09adf4ab93eef44ac8bbe1ec98e6255f$1@www.eclipse.org...
> the oclType() only returns the oclType of self.
>
> I want to know the how to return the element's oclType by the attribute
> value of the element.
>
> Anybody can help me?
>
> Best regards.
>
> Zhuang
>
Re: [ATL]How to get the element type by the element's attribute? [message #87960 is a reply to message #87946] Sat, 09 August 2008 13:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhuangguotao.hotmail.com

Thanks a lot for your attention. :)

some element relates other elements with attribute, like name.

I want to get the element instance by the attribute value string of the
element, and then execute the heleper of the getted element.

If is it possible? It seems like reflect in the java.

Now, I only know one simple way which traversals all the element to find
the element by the attribute value. Its efficent is very slow. I want to
try the better and more correct method.

thanks.

best regards.

Zhuang
Re: [ATL]How to get the element type by the element's attribute? [message #88099 is a reply to message #87960] Mon, 11 August 2008 16:32 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 71
Registered: July 2009
Member
The followong finds all classes in a UML model with the name "aClass":
UML!Class->allInstances()->select(c | c.name='aClass')

You can even reference the properties in a reflective way with (using EMF):
features : "%EMF"!EStructuralFeature <-
c.oclType().eStructuralFeatures->union(t.eSuperTypes->collect(st |
thisModule.allFeatures(st))->flatten()->asSet());

c.getRefValue( features->select(f|f.name='anAttribute') );

"Zhuang" <zhuangguotao@hotmail.com> schreef in bericht
news:ebe061938bceab825f158b9efb1ddacd$1@www.eclipse.org...
> Thanks a lot for your attention. :)
>
> some element relates other elements with attribute, like name.
>
> I want to get the element instance by the attribute value string of the
> element, and then execute the heleper of the getted element.
>
> If is it possible? It seems like reflect in the java.
>
> Now, I only know one simple way which traversals all the element to find
> the element by the attribute value. Its efficent is very slow. I want to
> try the better and more correct method.
>
> thanks.
>
> best regards.
>
> Zhuang
>
Re: [ATL]How to get the element type by the element's attribute? [message #88824 is a reply to message #88099] Sat, 23 August 2008 09:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhuangguotao.hotmail.com

Thanks a lot for your atttention.

I want to ask two questions:

1. is the getRefValue the function of ATL? if can I directly use it in ATL?

2. Can you tell me the theory about this sentence?

features : "%EMF"!EStructuralFeature <-
c.oclType().eStructuralFeatures->union(t.eSuperTypes->collect(st |
thisModule.allFeatures(st))->flatten()->asSet());


what mean is the %EMF, c, t?

Could you give me a sample about the usage about the reflection like your
description. Thanks a lot.
Re: [ATL]How to get the element type by the element's attribute? [message #88927 is a reply to message #88824] Mon, 25 August 2008 14:34 Go to previous message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 71
Registered: July 2009
Member
"Zhuang" <zhuangguotao@hotmail.com> schreef in bericht
news:37b9cfe239a5f3ecd4e770d356aaa1e6$1@www.eclipse.org...
> Thanks a lot for your atttention.
>
> I want to ask two questions:
>
> 1. is the getRefValue the function of ATL? if can I directly use it in
> ATL?

it's called refGetValue, sorry.
You can call it on any model element to get the property with the name you
supply as argument.

> 2. Can you tell me the theory about this sentence?
> features : "%EMF"!EStructuralFeature <-
> c.oclType().eStructuralFeatures->union(t.eSuperTypes->collect(st |
> thisModule.allFeatures(st))->flatten()->asSet());
> what mean is the %EMF, c, t?

This is just a reference to the EMOF metamodel

> Could you give me a sample about the usage about the reflection like your
> description.

self.oclType().eStructuralFeatures->union(t.eSuperTypes->collect(st |
thisModule.allFeatures(st))->flatten()->asSet()) -> iterate(f ; res : String
= ' -> ' |
let val : OclAny = self.refGetValue(f.name) in
val.debug('The value of '+ f.oclType().toString() +' '+ f.name +' from
model element "'+ self.toString() +'" is');

This will print:
The value of %EMF!EAttribute name from model element UML!Class is:
SomeClassName
The value of %EMF!EReference parents from model element UML!Class is:
%EMF!Class

I hope thats clear,
regards,

Alfons
Previous Topic:Looking for a sample recursive hepler?
Next Topic:helper produces execution error:java.lang.RuntimeException.Can you help me,pleas
Goto Forum:
  


Current Time: Sat Apr 27 02:49:19 GMT 2024

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

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

Back to the top