Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to call an EOperation in atl program?
How to call an EOperation in atl program? [message #899963] Fri, 03 August 2012 04:59 Go to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Hi,

I defined an hexToInt(string) EOperation in the ecore diagram(within the Module class). Then I call that operation in an ATL rule.

lazy rule rule_getModule{
from
b:source!ModuleItem

to
d:target!Module(
s7ModuleReference <- b.ModuleReference,
isSelectedWithinStep7<-b.IsSelected
)
do{
d.deviceID<-d.hexToInt(b.getIdentNumber());
}
}

I did debug the atl program. It seems to me that ATL VM cannot find the hexToInt() operation.

This gives an error at hexToInt() operation call,

org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: OUT!<unnamed>.hexToInt(java.lang.String)
at rule_getModule#40(TPF2PSSu2.atl[85:15-85:45])


I set source.ecore, target.ecore, input.xml and output.xml at run configuration.

Can someone help me to fix this error?

Thanks in advance.
K
Re: How to call an EOperation in atl program? [message #900004 is a reply to message #899963] Fri, 03 August 2012 08:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25752
Registered: July 2009
Senior Member
Kosala,

I'm not sure who they implement operation invocation. It might rely on
the generated model itself supported EObject.eInvoke. You have to
enable that by setting the GenModel's Operation Invocation property to true.


On 03/08/2012 10:59 AM, Kosala Yapa wrote:
> Hi,
>
> I defined an hexToInt(string) EOperation in the ecore diagram(within
> the Module class). Then I call that operation in an ATL rule.
>
> lazy rule rule_getModule{
> from
> b:source!ModuleItem
>
> to
> d:target!Module(
> s7ModuleReference <- b.ModuleReference,
> isSelectedWithinStep7<-b.IsSelected
> )
> do{
> d.deviceID<-d.hexToInt(b.getIdentNumber());
> }
> }
>
> I did debug the atl program. It seems to me that ATL VM cannot find
> the hexToInt() operation.
>
> This gives an error at hexToInt() operation call,
>
> org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found:
> OUT!<unnamed>.hexToInt(java.lang.String)
> at rule_getModule#40(TPF2PSSu2.atl[85:15-85:45])
>
>
> I set source.ecore, target.ecore, input.xml and output.xml at run
> configuration.
>
> Can someone help me to fix this error?
>
> Thanks in advance.
> K
Re: How to call an EOperation in atl program? [message #900015 is a reply to message #900004] Fri, 03 August 2012 09:06 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Ed,

Thanks a mil for your advice. How to set the Operation Invocation property of GenModel?
I can see Operation Reflection property in the property view of the GenModel. I cannot find a property called Operation Invocation.

Regards,
Kosala
Re: How to call an EOperation in atl program? [message #900057 is a reply to message #900015] Fri, 03 August 2012 13:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25752
Registered: July 2009
Senior Member
Kosola,

Sorry, that's the one I meant.

On 03/08/2012 3:06 PM, Kosala Yapa wrote:
> Ed,
>
> Thanks a mil for your advice. How to set the Operation Invocation
> property of GenModel?
> I can see Operation Reflection property in the property view of the
> GenModel. I cannot find a property called Operation Invocation.
>
> Regards,
> Kosala
Re: How to call an EOperation in atl program? [message #900478 is a reply to message #900057] Tue, 07 August 2012 05:08 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Ed,

Thanks for your advice, but I still have the same error.


At run configuration,
I tried to set up nsURI of the model (nsURI="model") instead of file path to model.ecore.


<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model"
nsURI="model" nsPrefix="">
---
</ecore:EPackage>

now i get an error:
Error loading platform:/resourcensURI="model": java.net.MalformedURLException: Invalid URL "platform:/resourcensURI="model"".

do u have any clue to solve this error?

Thanks
Kosala
Re: How to call an EOperation in atl program? [message #900501 is a reply to message #900478] Tue, 07 August 2012 06:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25752
Registered: July 2009
Senior Member
Kosala,

Comments below.

On 07/08/2012 11:08 AM, Kosala Yapa wrote:
> Ed,
>
> Thanks for your advice, but I still have the same error.
>
>
> At run configuration,
> I tried to set up nsURI of the model (nsURI="model") instead of file
> path to model.ecore.
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model"
> nsURI="model" nsPrefix="">
It's not generally a good idea to use the empty string as an
nsPrefix... Also the nsURI should be something that's globally unique
in an application, so an actual URI of something like a qualified
package name would be better.
> ---
> </ecore:EPackage>
>
> now i get an error:
> Error loading platform:/resourcensURI="model":
> java.net.MalformedURLException: Invalid URL
> "platform:/resourcensURI="model"".
I can't comment on something like this without context. If this is an
ATL question, best you ask there.
>
> do u have any clue to solve this error?
You've not provided enough clues about what the error is. No stack
trace or anything like that...
>
> Thanks
> Kosala
Re: How to call an EOperation in atl program? [message #900511 is a reply to message #900478] Tue, 07 August 2012 06:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3849
Registered: July 2009
Senior Member
Hi

> now i get an error:
> Error loading platform:/resourcensURI="model":
> java.net.MalformedURLException: Invalid URL
> "platform:/resourcensURI="model"".
>
It is very very unusual to have " in a URI, and platform:/resource is
invariably followed by a "/".

You have clearly made a mess of some string concatenation processing.

Once you fix that you will almost certainly find that you have not
registered platform: functionality correctly.

> do u have any clue to solve this error?
Find a working ATL example and use that as a reference for your debugging.

Regards

Ed Willink
Re: How to call an EOperation in atl program? [message #900575 is a reply to message #900511] Tue, 07 August 2012 11:37 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Thanks.

My problem is, yes I defined EOperation (hexToInt(String)) signature at target.ecore diagram, however the EOperation is implemented at the code base, which is generated from the target.genmodel.

How to call this hexToInt() in my ATL module? This is my problem.

Can I use run configuration settings to call this operation? I do not think so, because run configuration is not linked with generated code. (is there any way to make that link?)

As the other option,
I created an ATL plugin, and trying to run as a java application.

Properties file:
# Metamodels paths or nsUris
TPF2PSSu2.metamodels.source = file:/C:/..../source.ecore
TPF2PSSu2.metamodels.target = file:/C:/.../target.ecore


loading models:

/**
* Load the input and input/output models, initialize output models.
* @generated
*/
public void loadModels(String inModelPath) throws ATLCoreException {
ModelFactory factory = new EMFModelFactory();
IInjector injector = new EMFInjector();
IReferenceModel sourceMetamodel = factory.newReferenceModel();
injector.inject(sourceMetamodel, getMetamodelUri("source"));
IReferenceModel targetMetamodel = factory.newReferenceModel();


injector.inject(targetMetamodel, getMetamodelUri("target"));
this.inModel = factory.newModel(sourceMetamodel);
injector.inject(inModel, inModelPath);
this.outModel = factory.newModel(targetMetamodel);
}


I still get the error:

org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: OUT!<unnamed>.hexToInt(java.lang.String)
at rule_getModule#40(TPF2PSSu2.atl[87:15-87:45])

Yes, I can understand, this launcher is not yet connected with the generated code.


Is there any approach to load the target meta model from the generated code?

It looks to me some modification is needed at
injector.inject(targetMetamodel, getMetamodelUri("target"));
this.inModel = factory.newModel(sourceMetamodel);


I really appriciate any help to solve this problem.

Thanks
Kosala

[Updated on: Tue, 07 August 2012 11:41]

Report message to a moderator

Re: How to call an EOperation in atl program? [message #900669 is a reply to message #900575] Wed, 08 August 2012 02:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25752
Registered: July 2009
Senior Member
Kosala,

Comments below.

On 07/08/2012 5:37 PM, Kosala Yapa wrote:
> Thanks.
>
> but my problem is, yes I defined EOperation at target.ecore, but the
> EOperation (hexToInt(String)) defined at the code base, which is
> generated from the target.genmodel.
So you have a generated model and it compiles okay?
>
> How call this hexToInt() in my ATL module? This is my problem.
This is an ATL question. I don't know the answer.
>
> Can I use run configuration settings to call this operation? I do not
> think so, because run configuration is not linked with generated code.
> (is there any way to make that link?)
I think this is an ATL question as well.
>
> As the other option,
> I created an ATL plugin, and trying to run as a java application.
>
> Properties file:
> # Metamodels paths or nsUris
> TPF2PSSu2.metamodels.source = file:/C:/..../source.ecore
> TPF2PSSu2.metamodels.target = file:/C:/.../target.ecore
>
>
> loading models:
>
> /**
> * Load the input and input/output models, initialize output models.
> * @generated
> */
> public void loadModels(String inModelPath) throws ATLCoreException {
> ModelFactory factory = new EMFModelFactory();
> IInjector injector = new EMFInjector();
> IReferenceModel sourceMetamodel = factory.newReferenceModel();
> injector.inject(sourceMetamodel, getMetamodelUri("source"));
> IReferenceModel targetMetamodel = factory.newReferenceModel();
>
>
> injector.inject(targetMetamodel, getMetamodelUri("target"));
> this.inModel = factory.newModel(sourceMetamodel);
> injector.inject(inModel, inModelPath);
> this.outModel = factory.newModel(targetMetamodel);
> }
>
>
> I still get the error:
>
> org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found:
> OUT!<unnamed>.hexToInt(java.lang.String)
> at rule_getModule#40(TPF2PSSu2.atl[87:15-87:45])
>
> Yes, I can understand, this launcher is not yet connected with the
> target model generated code.
In a launcher for an Eclipse application you can specify which bundles
should be part of the application.
>
>
> Is there any approach to load the target meta model from the generated
> code?
>
> It looks to me some modification is needed at
> injector.inject(targetMetamodel, getMetamodelUri("target"));
> this.inModel = factory.newModel(sourceMetamodel);
>
>
> I really appriciate any help to solve this problem.
Best you ask on the ATL newsgroup questions that are specific to ATL.
>
> Thanks
> Kosala
>
Re: How to call an EOperation in atl program? [message #900703 is a reply to message #900669] Wed, 08 August 2012 04:37 Go to previous message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Thanks for all. I got it working.


Hope this info is useful.

I defined EOperations in the target model and load them using its URI.

code example:

public void loadModels(String inputModelPath) throws ATLCoreException{

ResourceSet resourceSet = getResourceSet();

EMFModelFactory factory = new EMFModelFactory();
IInjector injector = new EMFInjector();

//inject path of the source meta model to IReferenceModel instance
IReferenceModel sourceMetamodel = factory.newReferenceModel();
injector.inject(sourceMetamodel, this.getSourceMetamodelPath());

//inject path of the target meta model from URI to IReferenceModel instance
IReferenceModel targetMetamodel = factory.newReferenceModel();
injector.inject(targetMetamodel, getPackage_eNS_URI());

//create new model instance and inject source model
this.inModel = factory.newModel(sourceMetamodel);
injector.inject(inModel, inputModelPath);

//create new model instance for target model
this.outModel = factory.newModel(targetMetamodel);
}


In order to load the target model, I am using "getPackage_eNS_URI()", which gives the URI of the target model. I defined Eoperations in the target model.

Kosala




Kosala

[Updated on: Thu, 09 August 2012 04:49]

Report message to a moderator

Previous Topic:[CDO/Hibernate] Defining not-nullable EReferences
Next Topic:Limit validation to current resource or EObject
Goto Forum:
  


Current Time: Thu Apr 24 14:51:03 EDT 2014

Powered by FUDForum. Page generated in 0.01793 seconds