Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] how to extends ATL language with own library ?
[ATL] how to extends ATL language with own library ? [message #535527] Mon, 24 May 2010 09:25 Go to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Hello,

I need to make a special encryption of a string using an external java library while transforming on model to another.
Is this possible with ATL ?

Thanks

SeB
Re: [ATL] how to extends ATL language with own library ? [message #535660 is a reply to message #535527] Tue, 25 May 2010 08:13 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You can call Java but only if the method is coded on your meta-model using EMF.

Let's say you want a random number generator. You can add an eOperation on an EClass of your meta-model called random(), then generate with EMF, hand-code the java method generated and then call that function in ATL by invoking it on an instance of the EClass concerned.
Re: [ATL] how to extends ATL language with own library ? [message #535678 is a reply to message #535660] Tue, 25 May 2010 08:56 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Ha, ok, I thought ATL was using dynamic EMF, that is base only on the .ecore definition.
And that seems to be the case because I am only working with ecore.
So you say that if I generate the code the ATL engine will use the generated code instead of dynamic EMF ?
That would be nice.
I'll try that later.
Thanks.
Re: [ATL] how to extends ATL language with own library ? [message #535684 is a reply to message #535678] Tue, 25 May 2010 09:09 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
seb.fr wrote on Tue, 25 May 2010 04:56
Ha, ok, I thought ATL was using dynamic EMF, that is base only on the .ecore definition.
And that seems to be the case because I am only working with ecore.
So you say that if I generate the code the ATL engine will use the generated code instead of dynamic EMF ?
That would be nice.
I'll try that later.
Thanks.


yep, if you use the URI.
Re: [ATL] how to extends ATL language with own library ? [message #535688 is a reply to message #535684] Tue, 25 May 2010 09:30 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
So Ideally,
I could create an ecore metamodel for my migration that coud define one Migration class with all the necessary methods for conversion and other things not possible with plain ATL.
I like this idea.

Hummm, can I use more than one metamodel in ATL ?

SeB.
Re: [ATL] how to extends ATL language with own library ? [message #535700 is a reply to message #535527] Tue, 25 May 2010 10:34 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
I think you can add as input an empty model conforming to your "Utils" meta-model.
I think you can invoke methods like that : MM!eclass.method() directly.

If it doesn't work, then just add an instance of the EClass in your input model and use it in the transformation.
Re: [ATL] how to extends ATL language with own library ? [message #536312 is a reply to message #535527] Thu, 27 May 2010 15:36 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
I can't make it work.
I have create an migration.ecore model with one class and one operation.
Then generated the code
and tried it using the ATL launcher or the java code generated when creating a ATL plugin without success.
I use the nsURI to define the migation metamodel in both the ATL launch and the java code, but I have the following error.

org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: MIG!<unnamed>:MIGMODEL!MigrationMetadata400to410.convertIntToLong(java.lang.Long)
	at __applyMetadataColumn(TosMetadata400to410.atl[137:22-137:72])
		local variables: self=thisModule, link=org.eclipse.m2m.atl.engine.emfvm.lib.TransientLink@1a6725c, s=IN!<unnamed>:INMODEL!MetadataColumn, t=OUT!<unnamed>:OUTMODEL!MetadataColumn, newInitialValue=OUT!<unnamed>:OUTMODEL!Expression
	at __exec__(TosMetadata400to410.atl)
		local variables: self=thisModule, e=org.eclipse.m2m.atl.engine.emfvm.lib.TransientLink@1a6725c
	at main(TosMetadata400to410.atl)
		local variables: self=thisModule



I am really stuck with this Sad
Re: [ATL] how to extends ATL language with own library ? [message #536323 is a reply to message #535527] Thu, 27 May 2010 16:20 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Have you tried to instatiate the class to call the method with the instance ?
Re: [ATL] how to extends ATL language with own library ? [message #536328 is a reply to message #536323] Thu, 27 May 2010 16:31 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Yes I just did it to be sure without any problem.
As you can see the method is quiet simple

    public long convertIntToLong(int value) {
        return value;
    }

and the test case
    @Test
    public void TestMigrationConversionCall() {
        MigrationMetadata400to410 metadata400to410 = MigrationFactory.eINSTANCE.createMigrationMetadata400to410();
        int theInt = 12;
        long theLong = metadata400to410.convertIntToLong(theInt);
        Assert.assertEquals(theInt, theLong);
    }


Sylvain EVEILLARD wrote on Thu, 27 May 2010 18:20
Have you tried to instatiate the class to call the method with the instance ?

Re: [ATL] how to extends ATL language with own library ? [message #536329 is a reply to message #535527] Thu, 27 May 2010 16:39 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
I mean, in the ATL transformation by creating an instance of that class in the input model and by retrieving it in the transformation to call the method.

Or maybe, this is related to the long type not supported by ATL.
Re: [ATL] how to extends ATL language with own library ? [message #536331 is a reply to message #536329] Thu, 27 May 2010 16:48 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Actually, the instance of this class is correctly created in the ATL or I would have another king of error before.

create OUT : OUTMODEL, MIG : MIGMODEL from IN : INMODEL;

helper def : Migration : MIGMODEL!"migration::MigrationMetadata400to410" = OclUndefined;

entrypoint rule initialization() {
	to mig : MIGMODEL!"migration::MigrationMetadata400to410"
	do {
		thisModule.Migration <- mig;
	}
}

As you can see I have defined the migration model to be an output model, that I intend never to persist as it is only used for the sake of the transformation.
Re: [ATL] how to extends ATL language with own library ? [message #536338 is a reply to message #536331] Thu, 27 May 2010 16:59 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
I have tried with another method returning a String and it works, it seems to be a problem with longs arggggggg
Re: [ATL] how to extends ATL language with own library ? [message #536339 is a reply to message #535527] Thu, 27 May 2010 17:04 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Well you still have the possibility to post-process the transformed model to finalize it with the things not doable in ATL.
Re: [ATL] how to extends ATL language with own library ? [message #536421 is a reply to message #536339] Fri, 28 May 2010 07:26 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Sylvain EVEILLARD wrote on Thu, 27 May 2010 19:04
Well you still have the possibility to post-process the transformed model to finalize it with the things not doable in ATL.


I don't know exactly how this would be possible because you end up with one model with as not relation with the input model.
I do not forsee anyway to match the instances of the ouput model with the ones in the input model.

Anyway merci Sylvain.

[Updated on: Fri, 28 May 2010 07:27]

Report message to a moderator

Re: [ATL] how to extends ATL language with own library ? [message #536438 is a reply to message #536421] Fri, 28 May 2010 09:11 Go to previous message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Ok,
After a good night sleep I decided to keep on testing this conversion process.
And guess what I managed to make it work.
That was due to a change that I made previously in the input metamodel to work around this problem.

But the conclusion is that, if you have a input field of type int and an output field of type long, you can create an operation to convert on type to the other. It worked.

Another conclusion is that if you hold a copy of the input metamodel you can change the input field type from int to long and the problem is resolved without any conversion Wink
But I just realized that I tried that before and it did not work, I now know why, the ATL Regular VM fails but the EMF VM succeed in using Long-Long. Don't ask me why.

Thanks any way because i'll use the delagate technique for some other processings anyway.

[Updated on: Fri, 28 May 2010 09:26]

Report message to a moderator

Previous Topic:create UML association using ownedEnd, ownedMEmber
Next Topic:[ATL] How to extend in KM3 to two classes
Goto Forum:
  


Current Time: Fri Apr 26 01:14:29 GMT 2024

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

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

Back to the top