Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » rule with multiple objects for one target pattern
rule with multiple objects for one target pattern [message #1062096] Wed, 05 June 2013 23:26 Go to next message
Stefan L is currently offline Stefan LFriend
Messages: 13
Registered: July 2012
Junior Member
Hi,

I'm curious if there is a way to create multiple objects for the same target pattern. Given the example:
rule someRule {
  from s : someType
  to   t : someType (
    attr <- Sequence(objs)
  ), 
  objs : anotherType (
    name <- 'someName'
    ...
  )   
}

This provides me only one attr instance, whereas i would like to generate x "attr" instances. In fact, a Sequence of objects with type of "anotherType" already exists. The other requirement is, that it is possible to declare the attributes I want to assign in the "objs"-target pattern. I really can't think of a way how to achieve this for multiplicity and therefore could use some help.

If this dummy rule is too confusing I could come up with a more concrete example.

Thanks.
Stefan


Re: rule with multiple objects for one target pattern [message #1062143 is a reply to message #1062096] Thu, 06 June 2013 08:38 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

Indeed it is a bit difficult to understand your actual problem based on the provided example.

If your purpose is to create multiple target elements from a given rule, the good way to implement this in ATL is to do a multiple call over a lazy rule.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: rule with multiple objects for one target pattern [message #1062148 is a reply to message #1062143] Thu, 06 June 2013 08:51 Go to previous messageGo to next message
Stefan L is currently offline Stefan LFriend
Messages: 13
Registered: July 2012
Junior Member
Thanks for your quick respond. So let me explain my problem in more detail.

I don't have the source code with me now at university, I might post it later the day.

Nevertheless, I actually have a sequence of uml class pairs and want to generate associations from it. So I do not have any rule to apply to, because there is no source pattern for the generation of associations. Therefore I have to generate the uml associations from the sequence of class pairs and then append them in my top model rule for the packagedElement attribute. The latter is just working fine for other transformed objects, but not for the associations, which I have to generate somehow in the first place.

I already tried a lazy rule, but I couldn't come up with a fitting source in the uml metamodel, as I just want to generate things and not transform it.

Stefan

[Updated on: Thu, 06 June 2013 08:53]

Report message to a moderator

Re: rule with multiple objects for one target pattern [message #1062154 is a reply to message #1062148] Thu, 06 June 2013 09:53 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
In case you really need to produce output model elements "from scratch", you can use imperative called rules (entrypoint or not).
However, the recommended programming style in ATL is the declarative one. So we strongly encourage users to write matched rules (regular or lazy) as much as possible.

In your specific case I have the impression that, as you have a sequence of input UML Class pairs, you could actually make a call to a lazy rule on each elements of this collection.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: rule with multiple objects for one target pattern [message #1062170 is a reply to message #1062154] Thu, 06 June 2013 11:40 Go to previous messageGo to next message
Stefan L is currently offline Stefan LFriend
Messages: 13
Registered: July 2012
Junior Member
Hi again,

when I try something like this:
lazy rule getAssociations {
  from s : TupleType(rcv : UML2!"uml::Class", snd : UML2!"uml::Class")
  to t : UML2!"uml::Association" (
    name <- '<combined_class_name>'
    ...		
  )
}

the compiler reports a casting error:
Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl cannot be cast to org.eclipse.emf.ecore.EClass

I think that I'm not calling the lazy rule yet. I've read something about, that such "custom" (although it is a Tuple) types are not supported as source patterns in EMFTVM yet, but then looked up the Bugzilla link where it was mentioned as fixed. Although I'm not that certain if this was actually a bug or just a misunderstanding from my side.

Basically I just would like to feed the (unique) lazy rule with any Data Type which supports two UML Classes. Then I should be able to build the association in the target pattern UML2!"uml::Association" with all the corresponding UML attributes for Association.

Stefan
Re: rule with multiple objects for one target pattern [message #1062174 is a reply to message #1062170] Thu, 06 June 2013 11:55 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
You can only put model elements in the input pattern of matched rules. Thus, your rule could be standard and look like:
rule getAssociations {
  from 
     rcv : UML2!"uml::Class", snd : UML2!"uml::Class"
     (
          rcv.name = snd.name -- Example condition to determine on which pairs the rule actually needs to be triggered by ATL
     )
  to 
     t : UML2!"uml::Association" (
          name <- '<combined_class_name>'
          ...		
     )
}


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: rule with multiple objects for one target pattern [message #1062176 is a reply to message #1062174] Thu, 06 June 2013 11:58 Go to previous message
Stefan L is currently offline Stefan LFriend
Messages: 13
Registered: July 2012
Junior Member
It compiles, I can see the difference now, thanks a lot, Hugo!

Stefan
Previous Topic:Using helper as attribute/variable brings exception
Next Topic:Convert UML to security policies
Goto Forum:
  


Current Time: Sat Apr 20 02:39:10 GMT 2024

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

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

Back to the top