Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Hexa decimal to integer conversion
Hexa decimal to integer conversion [message #899508] Wed, 01 August 2012 08:39 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi,

I have an hexa decimal(Value="0x00000C00") as a string, which i need to convert to integer(decimal) in an atl program.

any poinion is appriciated.

Thanks
K

[Updated on: Wed, 01 August 2012 08:54]

Report message to a moderator

Re: Hexa decimal to integer conversion [message #899510 is a reply to message #899508] Wed, 01 August 2012 08:55 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
I'd recommend create an EOperation in your metamodel and implement it in Java. You can then use it in your ATL program.
Re: Hexa decimal to integer conversion [message #899594 is a reply to message #899510] Wed, 01 August 2012 14:26 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
rule rule_getHeadModule{
from
b:source!ModuleItem

to
d:target!HeadModule(
deviceID<-b.IdentNumber,
s7ModuleReference <- b.ModuleReference,
isSelectedWithinStep7<-b.IsSelected
)

}

IdentNumber is string which has hex value. deviceID is int. if i have hex2Int(String str) at target!HeadModule, how can i call that to above rule?

thanks
K
Re: Hexa decimal to integer conversion [message #899608 is a reply to message #899594] Wed, 01 August 2012 14:50 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
deviceID <- d.hext2Int(b.IdentNumber)
Re: Hexa decimal to integer conversion [message #899649 is a reply to message #899608] Wed, 01 August 2012 16:43 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
lazy rule rule_getModule{
from
b:source!ModuleItem

to
d:target!Module(
deviceID<- d.hexToInt(b.IdentNumber),
s7ModuleReference <- b.ModuleReference,
isSelectedWithinStep7<-b.IsSelected
)

}

I get an error:
org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: IN!<unnamed>.hexToInt(java.lang.String)
at rule_getHeadModule#28(TPF2PSSu2.atl[95:16-95:46])

any solution?

Thanks.
Re: Hexa decimal to integer conversion [message #899746 is a reply to message #899508] Thu, 02 August 2012 07:50 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
here is the issue:

helper context source!ModuleItem def : getIdentNumber():
String = self.ParameterList.ParameterItem->select(pi |
pi.Name='IdentNumber')->collect(e|e.Value)->first();




lazy rule rule_getModule{
from
b:source!ModuleItem

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

}



Error comes at the deviceID line as:

org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: OUT!<unnamed>.hexToInt(java.lang.String)
at rule_getModule#28(TPF2PSSu2.atl[81:16-81:46])
local variables: self=TPF2PSSu2 : ASMModule, b=IN!<unnamed>, d=OUT!<unnamed>

any help is appriciated.

Thanks
K
Re: Hexa decimal to integer conversion [message #899765 is a reply to message #899746] Thu, 02 August 2012 09:30 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
are you using the EMF version as the meta-model instead of the ecore file ?
Re: Hexa decimal to integer conversion [message #899767 is a reply to message #899765] Thu, 02 August 2012 09:33 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Or this might be because d is not already a target!Module in which case you could try to do the line in the "do" section :
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());
}
}
Re: Hexa decimal to integer conversion [message #899770 is a reply to message #899765] Thu, 02 August 2012 09:48 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi Sylvain,

Thanks a mil for ur help.

I have set ecore files at the run configuration.

How to set the EMF version as the meta-model instead of the ecore file?


Thanks in advance
K
Re: Hexa decimal to integer conversion [message #899800 is a reply to message #899765] Thu, 02 August 2012 11:53 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
//are you using the EMF version as the meta-model instead of the ecore file ?


what do u mean?

At run configuration, I have set source.ecore and target.ecore files. How can i set EMF version as the meta-model instead of the ecore file ?

Thanks.
K

[Updated on: Thu, 02 August 2012 14:10]

Report message to a moderator

Re: Hexa decimal to integer conversion [message #900254 is a reply to message #899800] Mon, 06 August 2012 08:13 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Use the URI of the meta-model and not the physical .ecore file.
Re: Hexa decimal to integer conversion [message #900448 is a reply to message #900254] Tue, 07 August 2012 07:18 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi Sylvain,

metamodel is model.ecore,which is saved in c:\temp\ .


<?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>

how to get the URI of this meta model, which I need to set up at run configuration?

Thanks a million.
Kosala

[Updated on: Tue, 07 August 2012 07:19]

Report message to a moderator

Re: Hexa decimal to integer conversion [message #900452 is a reply to message #900448] Tue, 07 August 2012 07:31 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
nsURI="model"
Re: Hexa decimal to integer conversion [message #900462 is a reply to message #900452] Tue, 07 August 2012 08:03 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
I setup target meta model as nsURI="model".
Now i get an error:

Error loading platform:/resourcensURI="model": java.net.MalformedURLException: Invalid URL "platform:/resourcensURI="model"".

any clue on this?

Thanks.
K
Re: Hexa decimal to integer conversion [message #900464 is a reply to message #900452] Tue, 07 August 2012 08:16 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
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 15:45]

Report message to a moderator

Re: Hexa decimal to integer conversion [message #900702 is a reply to message #900464] Wed, 08 August 2012 08:36 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi all,

Thanks mates. I got it working.
Re: Hexa decimal to integer conversion [message #900991 is a reply to message #900702] Thu, 09 August 2012 10:55 Go to previous message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member

check the link "How to call an EOperation in atl program?" for more information.
Previous Topic:EMF version as the meta-model
Next Topic:EOperation defined at ecore need to be called at atl ?
Goto Forum:
  


Current Time: Tue Apr 16 10:37:48 GMT 2024

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

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

Back to the top