Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » (no subject)
(no subject) [message #694595] Fri, 08 July 2011 22:50 Go to next message
Philipp Zech is currently offline Philipp Zech
Messages: 96
Registered: July 2009
Member
Hi,

in one of my transformations I create a target model in normal execution
mode. If applying stereotypes inside a called rule via

rule sample {
from
A : A!A

to
B : B!B,
stereotype : B!Stereotype (
base_B <- B
)
}

everything works fine and the stereotype is applied in the target model
afterwards. Yet, if trying the same inside a lazy rule, the new model
elements are created, however, the stereotype is not applied. Besides,
during the transformation no errors are thrown. Interestingly, I use the
same stereotype from the target model twice by applying it to package
elements in the target model, the first time inside a called rule and
the second time inside a lazy rule. Again, as already described above,
the stereotype is applied inside the called rule but not inside the lazy
one, and besides, no exceptions are thrown and the transformation
succeeds. Is it actually not possible to apply stereotypes inside lazy
rules?

Thanks for any help!

Cheers,

Philipp
Re: (no subject) [message #695200 is a reply to message #694595] Mon, 11 July 2011 09:17 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 523
Registered: July 2009
Senior Member
There's a strange behavior when using stereotypes in ATL.
I'll try to explain what happens :

When you apply a stereotype, you create an instance of this stereotype.
This instance will be at the root of the model (resource in EMF terms) containing the element that is stereotyped.
The thing is : if your element doesn't belong to a resource, then it doesn't know in which model/resource the instance of the stereotype is to be placed. Therefore in the end, even if the model element is moved afterwards, the result is just as if the stereotype wasn't applied.

If you use a lazy rule like :
packagedElement <- thisModule.myLazyRule()

lazy rule myLazyRule(){
from s
to t, stereotype (base_XX <- s)
}

Then, it will first call the lazy rule which will create an element t and stereotype it. But at this point, t belongs to nothing. So we're in the case described here and the stereotype will be lost. The t element is "attached" to a model/resource after the call to the lazy rule in the statement packagedElement <- thisModule.myLazyRule().

What you can do for example is :
using{
myTElement : OclAny = thisModule.myLazyRule();
}

and then :
packagedElement <- myTElement

And apply the stereotype in the main rule, once the packagedElement statement has been executed :
stereotype (
base_XX <- myTElement
)

I don't know if I was clear so if you still don't understand, don't hesitate to post additional questions.
Re: (no subject) [message #695646 is a reply to message #695200] Tue, 12 July 2011 08:27 Go to previous messageGo to next message
Philipp Zech is currently offline Philipp Zech
Messages: 96
Registered: July 2009
Member
On 07/11/2011 11:17 AM, Sylvain EVEILLARD wrote:
> There's a strange behavior when using stereotypes in ATL.
> I'll try to explain what happens :
>
> When you apply a stereotype, you create an instance of this stereotype.
> This instance will be at the root of the model (resource in EMF terms)
> containing the element that is stereotyped.
> The thing is : if your element doesn't belong to a resource, then it
> doesn't know in which model/resource the instance of the stereotype is
> to be placed. Therefore in the end, even if the model element is moved
> afterwards, the result is just as if the stereotype wasn't applied.
>
> If you use a lazy rule like :
> packagedElement <- thisModule.myLazyRule()
>
> lazy rule myLazyRule(){
> from s
> to t, stereotype (base_XX <- s)
> }
> Then, it will first call the lazy rule which will create an element t
> and stereotype it. But at this point, t belongs to nothing. So we're in
> the case described here and the stereotype will be lost. The t element
> is "attached" to a model/resource after the call to the lazy rule in the
> statement packagedElement <- thisModule.myLazyRule().
>
> What you can do for example is :
> using{
> myTElement : OclAny = thisModule.myLazyRule();
> }
>
> and then :
> packagedElement <- myTElement
>
> And apply the stereotype in the main rule, once the packagedElement
> statement has been executed :
> stereotype (
> base_XX <- myTElement
> )
>
> I don't know if I was clear so if you still don't understand, don't
> hesitate to post additional questions.

Hi Sylvain,

thanks for your replay. I'm getting was not properly working and hinders
my stereotype being applied. Also thanks for your suggestion on how to
apply the stereotypes, however, it somehow does not work for me, as the
lazy rule is called inside a statement like the following:

packagedElement <- elements -> collect(e | thisModule.lazyRule(e))

and the lazy rule is the same as then one in the initial messages. Yet,
I k ow how to apply your suggestion if only creating one element, yet if
creating a set of elements, assigned to the packagedElement feature,
applying the stereotype after this packaedElement assignment won't work.
Are there any other possibilities allowing me to apply the stereotypes?

Cheers,

Philipp
Re: (no subject) [message #695680 is a reply to message #695646] Tue, 12 July 2011 10:02 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 523
Registered: July 2009
Senior Member
Well in the imperative do section you can call a lazy rule that only applies the stereotype like :
t.packagedElement.collect(e | thisModule.stereotype(e))

lazy rule stereotype {
from s
to stereotype (base_XX <- s)
}
Re: (no subject) [message #695704 is a reply to message #695680] Tue, 12 July 2011 11:27 Go to previous messageGo to next message
Philipp Zech is currently offline Philipp Zech
Messages: 96
Registered: July 2009
Member
On 07/12/2011 12:02 PM, Sylvain EVEILLARD wrote:
> Well in the imperative do section you can call a lazy rule that only
> applies the stereotype like :
> t.packagedElement.collect(e | thisModule.stereotype(e))
>
> lazy rule stereotype {
> from s
> to stereotype (base_XX <- s)
> }
Hi Sylvain,

maybe I'm getting you wrong, but I tried your suggestion, leading to the
following code (for the sake of calrity, I inlcude everything):


rule createPackages {
from
interface : RM!VulnerableInterface
using {
operations : Sequence(RM!Operation) =
interface.base_Interface.ownedOperation;
}
to
package : MCM!Package (
name <- interface.base_Interface.name,
packagedElement <- interface.base_Interface.ownedOperation
-> collect(o |
thisModule.createTestSet(o))
),
st_package : MCM!TestSet (
base_Package <- package
),
st_interface : MCM!VulnerableInterface (
base_Package <- package
)
}


lazy rule createTestSet {
from
operation : RM!Operation
using {
exploits : Sequence(RM!Exploit) = operation.
getRMStereotypeVal('RM::ThreatProfile', 'exploit');
}
to
package : MCM!Package (
name <- operation.name,
packagedElement <- exploits -> collect(e |
thisModule.createTestCaseSet(e))
)
do {
package.packagedElement <- package.packagedElement -> collect(p
| thisModule.applyStereotypes2TestSet(p));
}
}


lazy rule applyStereotypes2TestSet {
from
package : MCM!Package
to
st_package : MCM!TestSet (
base_Package <- package
),
st_operation : MCM!VulnerableOperation (
base_Package <- package
)
}

lazy rule createTestCaseSet {
from
exploit : RM!Exploit
to
testcase : MCM!Package (
name <- exploit.name,
packagedElement <-
thisModule.getAttackTreeAsActivity('XML_INJECTION') ->
asSet() -> collect(at | thisModule.createTestCase(at))
),
st_activity : MCM!TestCaseSet (
base_Package <- testcase
)
}


lazy rule createTestCase {
from
attacktree : AT!Activity
to
testcase : MCM!Activity (
name <- 'testcase'
),
st_activity : MCM!TestCase (
base_Activity <- testcase
)
}

The stereotypes applied in the called rule, as already mentioned, remain
applied. Yet, the lazy rules are the problem. As suggested by you, I
changed the applciation in rule "createTestSet" to be inside the do
{...} block. Yet, again, nothing happens. The other lazy rules are
unchanged, i.e.: "createTestCaseSet" applies the stereotypes in a way,
also the "createTestSet" rule did before. Maybe I got your suggestion wrong?

Thanks!

Cheers,

Philipp
Re: (no subject) [message #695732 is a reply to message #695704] Tue, 12 July 2011 12:28 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 523
Registered: July 2009
Senior Member
The do block should be in the main rule that is createPackages
Re: (no subject) [message #695738 is a reply to message #695732] Tue, 12 July 2011 12:44 Go to previous message
Philipp Zech is currently offline Philipp Zech
Messages: 96
Registered: July 2009
Member
On 07/12/2011 02:28 PM, Sylvain EVEILLARD wrote:
> The do block should be in the main rule that is createPackages
Hi Sylvain,

thanks, now I got it and it works!

Cheers,

Philipp
Previous Topic:[ATL] getValue on ATL Map returns OclUndefined
Next Topic:Use Instance Type of EDataType
Goto Forum:
  


Current Time: Wed Oct 22 13:52:08 GMT 2014

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

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