Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » ATL Refining Using the API
ATL Refining Using the API [message #986439] Tue, 20 November 2012 12:30 Go to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
After getting my ATL refiner working using the @2006 compiler I now want to get it running using just the ATL API i.e. Not via ANT

Just to repeat the use-case. I want to perform a HOT on an ATL transform. So I will inject the ATL to XMI then run a modified ATLCopy.atl transfrom. I will then extract the XMI back to ATL.

I got this working in ANT, see http://www.eclipse.org/forums/index.php/t/440241/.

I tried to follow the ANT approach in my code to perform the injection but I'm failing somewhere along the way.

//get the ATL injector. This bit works Smile
IInjector injectorInstance = null;
injectorInstance = CoreService.getInjector("ATL");

//Set some model options. NOTE:There are hardcodes here while we test the API
Map<String, Object> modelOptions = new HashMap<String, Object>();
modelOptions.put("modelName", "myATL");
modelOptions.put("path", "file:/home/xx/Desktop/FileToBeHotted.atl");
modelOptions.put("newModel", false);

//Not sure what i'm doing here Sad
ModelFactory modelFactory = new EMFModelFactory();
IModel sourceModel = modelFactory.newReferenceModel(modelOptions);

//This runs but fails
injectorInstance.inject(sourceModel, "file:/home/xx/Desktop/FileToBeHotted.atl");

The error I get is java.lang.NullPointerException
at org.eclipse.m2m.atl.core.emf.EMFModel.newElement(Unknown Source)
at org.eclipse.m2m.atl.dsls.core.EMFTCSInjector$EMFInjectorAdapter.createElement(Unknown Source)
at org.eclipse.m2m.atl.dsls.tcs.injector.TCSRuntime.create(Unknown Source)

I'm clearly setting things up incorrectly for the injector. Any tips?

Thanks!
Ronan
Re: ATL Refining Using the API [message #987842 is a reply to message #986439] Wed, 28 November 2012 11:07 Go to previous messageGo to next message
Greg L is currently offline Greg LFriend
Messages: 9
Registered: November 2012
Junior Member
Hi Ronan,

I am trying to do exactly the same thing as you do. To run atl hot transformation using java api in a standalone application. Did you manage to get this working?

Instead of using:
IInjector injectorInstance = null;
injectorInstance = CoreService.getInjector("ATL");


and then:
injectorInstance.inject(sourceModel, "file:/home/xx/Desktop/FileToBeHotted.atl");


I have tried to use the following class: org.eclipse.m2m.atl.engine.parser.AtlParser
(getByteArrayFromFile is my private method that returns byte array for a given file of path inModelPath.)

byte[] array = getByteArrayFromFile(inModelPath);
InputStream is =  new ByteArrayInputStream( array );
inModel = AtlParser.getDefault().parseToModel(is);


but I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.eclipse.m2m.atl.dsls.tcs.injector.wrappers.antlr3.ParserWrapper.parse(ParserWrapper.java:106)
at org.eclipse.m2m.atl.dsls.tcs.injector.ParserLauncher.parse(ParserLauncher.java:79)
at org.eclipse.m2m.atl.dsls.core.EMFTCSInjector.inject(EMFTCSInjector.java:88)
at org.eclipse.m2m.atl.engine.parser.AtlParser.inject(AtlParser.java:145)
at org.eclipse.m2m.atl.engine.parser.AtlParser.inject(AtlParser.java:125)
at org.eclipse.m2m.atl.engine.parser.AtlParser.parseToModelWithProblems(AtlParser.java:271)
at org.eclipse.m2m.atl.engine.parser.AtlParser.parseToModel(AtlParser.java:258)
at myproject.EModelCopy.loadModels(EModelCopy.java:132)
at myproject.EModelCopy.main(EModelCopy.java:83)
Caused by: java.lang.NoSuchFieldError: ruleMemo
at org.eclipse.m2m.atl.dsls.tcs.injector.ATL_ANTLR3Parser.<init>(ATL_ANTLR3Parser.java:68)
... 13 more

Any ideas why this line of code: AtlParser.getDefault().parseToModel(is); gives the error shown above?

Thank you in advance for any tip or suggestion.
Greg
Re: ATL Refining Using the API [message #988303 is a reply to message #987842] Thu, 29 November 2012 10:35 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi Greg,
Yep I'm still trying to get this one to work. I think i'm pretty close but lets see. I get the same error as you when I just the ATL injector.

The problem is in EMFTCSInjector where EMFModel problems shows an error in the inject method. I'm just working on getting the error out of it now. The EObject root seems to be null. In the ANT version it is EDynamicEObjectImpl.

I'll report back with any progress. Please do the same Smile

Thanks,
Ronan
Re: ATL Refining Using the API [message #988356 is a reply to message #988303] Thu, 29 November 2012 14:59 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
I'm pretty sure I see the problem now. Inside EMFTCSInjector the model.getReferenceModel() contains a model which has a resource=null. In the ANT version I can see a resource with ATL/OCL/ATL-PrimitiveTypes MetaModels. It looks like when we try to do the inject the ATL MetaModel(and associated MMs) is not available.

Could it be that the order of MetaModel loading screws up the injection. Perhaps the ATL launch API isn't loading the models needed in the right order?

Any ideas?

Regards,
Ronan
Re: ATL Refining Using the API [message #988361 is a reply to message #988303] Thu, 29 November 2012 15:22 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi (again)!
The problem is certainly with the loading of the ATL MM. With ANT the LoadModelTask injects the ATL MM and the sourceModel then has a resource. The equivalent in the getModel method of LauncherService shows a resource=null after the injector.inject call.

Any suggestions has to load this correctly?

Regards,
Ronan
Re: ATL Refining Using the API [message #988387 is a reply to message #988361] Thu, 29 November 2012 17:16 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
Finally, I have figured it out! There is a really hard to find bug in the LauncherService.java getModel method. There is a bad assumption that the IN model and its associated MetaModel will have the same injector. This is not the case when doing ATL HOTs.

The ATL MM should use an EMF injector while the ATL model should use an ATL injector. Today in the code they always use the same one.

Replace the line injector.inject(referenceModel, referenceModelPath); with CoreService.getInjector("EMF").inject(referenceModel, referenceModelPath); and all will work beautifully!

I'll raise a bug in Bugzilla for this next week and submit a patch. To the ATL guys, can we get this into the next ATL release? This is a very important fix for me.

Regards,
Ronan

[Updated on: Thu, 29 November 2012 20:21]

Report message to a moderator

Re: ATL Refining Using the API [message #988607 is a reply to message #988387] Fri, 30 November 2012 16:55 Go to previous messageGo to next message
Greg L is currently offline Greg LFriend
Messages: 9
Registered: November 2012
Junior Member
Hi Ronan!

Thank you for sharing here the knowledge from your last attempts of executing HOTs.

Unfortunately, I still didn't manage to run the hot transformation (given atl file as input and obtaining atl file as output) on a standalone java application.

However, I have solved the issue with the following error:

Caused by: java.lang.NoSuchFieldError: ruleMemo
at org.eclipse.m2m.atl.dsls.tcs.injector.ATL_ANTLR3Parser.<init>(ATL_ANTLR3Parser.java:68)

by importing the "correct" antlr_runtime library (compatible with the org.eclipse.m2m.atl.dsls_3.2.1). After changing the antlr_runtime jar from 3.2.0 to 3.0.0, the error I indicate above disappeared.

Now, parsing the atl files looks to work fine, however I get the following exception when running the actual transformation:

org.eclipse.m2m.atl.engine.emfvm.VMException: Cannot create MM_ATL!Query


It looks like a problem with the ATL metamodel loading, any ideas??

BR,
Greg
Re: ATL Refining Using the API [message #989454 is a reply to message #988387] Thu, 06 December 2012 09:53 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
Bug and patch are ready, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395900

Not sure about your other issue Greg. It sounds like an ATL related MM isn't available in your run-time.

Regards,
Ronan
Re: ATL Refining Using the API [message #1007322 is a reply to message #989454] Tue, 05 February 2013 14:16 Go to previous messageGo to next message
Greg L is currently offline Greg LFriend
Messages: 9
Registered: November 2012
Junior Member
Hi Ronan,

One question about the ATL HOT execution. While performing xmi to atl conversion, have you ever faced a problem with the PrettyPrinter class?

Exception in thread "main" java.lang.RuntimeException: Property operationName has not been set in org.eclipse.emf.ecore.impl.DynamicEObjectImpl@e0bbd78 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@7be8c2a2 (name: OperatorCallExp) (instanceClassName: null) (abstract: false, interface: false)) (org.eclipse.emf.ecore.impl.EClassImpl@7be8c2a2 (name: OperatorCallExp) (instanceClassName: null) (abstract: false, interface: false))
	at org.eclipse.m2m.atl.dsls.tcs.extractor.PrettyPrinter.serialize(PrettyPrinter.java:271)
	at org.eclipse.m2m.atl.dsls.tcs.extractor.PrettyPrinter.serializeProperty(PrettyPrinter.java:597)


Thank you in advance for your reply.
Greg L
Re: ATL Refining Using the API [message #1007349 is a reply to message #1007322] Tue, 05 February 2013 15:33 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
It means that you have an OperatorCallExp without operationName which probably comes from a problem in your HOT.
Re: ATL Refining Using the API [message #1007531 is a reply to message #1007349] Wed, 06 February 2013 10:45 Go to previous message
Greg L is currently offline Greg LFriend
Messages: 9
Registered: November 2012
Junior Member
Hi Sylvain,

Thank you for you suggestion. However, the problem has to be different.

My xmi file looks like this: (this is a fragment of it)

        <elements xsi:type="atl:SimpleOutPatternElement" location="277:3-281:4" varName="connected_Output_Param" variableExp="/0/@elements.4/@outPattern/@elements.29/@bindings.2/@value">
          <commentsBefore>--- connect value</commentsBefore>
          <type xsi:type="ocl:OclModelElement" location="277:27-277:50" name="ConnectedElement" model="/63"/>
          <bindings location="279:4-279:83" propertyName="connectionEnd">
            <value xsi:type="ocl:IteratorExp" location="279:19-279:83" name="any">
              <source xsi:type="ocl:NavigationOrAttributeCallExp" location="279:19-279:56" name="ownedParameter">
                <source xsi:type="ocl:VariableExp" location="279:19-279:41" referredVariable="/0/@elements.4/@variables.6"/>
              </source>
              <body xsi:type="ocl:OperatorCallExp" location="279:66-279:82" operationName="=">
                <source xsi:type="ocl:NavigationOrAttributeCallExp" location="279:66-279:72" name="name">
                  <source xsi:type="ocl:VariableExp" location="279:66-279:67" referredVariable="/0/@elements.4/@outPattern/@elements.27/@bindings.0/@value/@iterators.0"/>
                </source>
                <arguments xsi:type="ocl:StringExp" location="279:75-279:82" stringSymbol="value"/>
              </body>
              <iterators location="279:62-279:63" varName="e" variableExp="/0/@elements.4/@outPattern/@elements.27/@bindings.0/@value/@body/@source/@source"/>
            </value>
          </bindings>
          <bindings location="280:4-280:25" propertyName="context">
            <value xsi:type="ocl:VariableExp" location="280:13-280:25" referredVariable="/0/@elements.4/@outPattern/@elements.13"/>
          </bindings>
        </elements>


As you can see, the OperatorCallExp has operationName attribute present. This applies to the entire file.
The problem is that I am trying to run the XMI to ATL conversion from a standalone java application. This conversion, however, works fine from an atl plugin.

To make the tcs.extractor work I first register the needed MetaModels in the following way:
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
			getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());

URI ecoreURITCS = URI.createFileURI("Meta/TCS.ecore"); 
Resource resourcePackageTCS = resourceSet.getResource(ecoreURITCS, true); 
EPackage ePackageTCS = (EPackage)resourcePackageTCS.getContents().get(0); 
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gmt/tcs/2007/TCS", ePackageTCS);

URI ecoreURIat = URI.createFileURI("Meta/ATL-TCS.xmi"); 
Resource resourcePackageTCSat = resourceSet.getResource(ecoreURIat, true); 
EObject ePackageAT = resourcePackageTCSat.getContents().get(0); 
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gmt/tcs/2007/TCS", ePackageAT);
			
URI ecoreURIATL = URI.createFileURI("Meta/ATL.ecore"); 
Resource resourcePackage = resourceSet.getResource(ecoreURIATL, true); 
EPackage ePackageOCL = (EPackage)resourcePackage.getContents().get(1); 
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gmt/2005/OCL", ePackageOCL);

EPackage ePackageATL = (EPackage)resourcePackage.getContents().get(0); 
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gmt/2005/ATL", ePackageATL);

			
EPackage ePackagePT = (EPackage)resourcePackage.getContents().get(2); 
EPackage.Registry.INSTANCE.put("http://www.eclipse.org/gmt/2005/PrimitiveTypes", ePackagePT);
			
getResourceSet().getPackageRegistry().put("http://www.omg.org/XMI", EcorePackage.eINSTANCE);
getResourceSet().getPackageRegistry().put("http://www.w3.org/2001/XMLSchema-instance", EcorePackage.eINSTANCE);


So, the extractor gets the correct MetaModels injected, and the XMI file is also correct. Any ideas, why it fails?

Thank you in advance for any tip or suggestion!
Greg L
Previous Topic:Replace input ecore model by code
Next Topic:I need some help in ATL transformation when use KDM
Goto Forum:
  


Current Time: Fri Mar 29 14:53:15 GMT 2024

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

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

Back to the top