Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » run successive ATL transformations with java
run successive ATL transformations with java [message #1160684] Tue, 29 October 2013 09:31 Go to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Dear All,
I have these two transformations:


fiModel --
|- Ins2Lk.atl -> lkModel
fInsModel--



fiModel --
|- Lk2Tpn.atl -> tpnModel
lkModel --

I define a java program to launch them automatically.
However, I have an error when I try to inject the lkModel generated by the first transformation in the second transformation Sad

this is my java program
public class Toolchain2 {

public static void main(String[] args) throws IOException {
	
/*
 * The first transformation 
 */
	try {
		
			// in order to generate models with relatifs inter-model references
			System.setProperty("user.dir","/Users/f/Modeling/workspace25/org.eclipse.toolchain/models");

			
			// in order to make allow inter model references = true
			// we define MyEMFVMLauncher which  is the same as EMFVMLauncher! just one modification in
			// internalLaunch where we make 
			// modelAdapter.setAllowInterModelReferences(LauncherService.getBooleanOption(options.get("allowInterModelReferences"), true));
			ILauncher transformationLauncher = new MyEMFVMLauncher();
			
			
			transformationLauncher.initialize(new HashMap<String,Object>()) ;
			ModelFactory modelFactory = new EMFModelFactory();
			IInjector injector = new EMFInjector();
			IExtractor extractor = new EMFExtractor();
			/*
			* Load metamodels
			*/

			IReferenceModel fInsMetamodel = modelFactory.newReferenceModel();
			injector.inject(fInsMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/FInst.ecore");
				
			IReferenceModel fiMetamodel =modelFactory.newReferenceModel() ;
			injector.inject(fiMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/FI.ecore");
			    
			IReferenceModel LkMetamodel = modelFactory.newReferenceModel();
			injector.inject(LkMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/LK.ecore");
	
			
			IModel fInsModel = modelFactory.newModel(fInsMetamodel);
			injector.inject(fInsModel, "model.fins");
			
	        IModel fiModel = modelFactory.newModel(fiMetamodel) ;
	        injector.inject(fiModel, "model.f");
	        
	        IModel lkModel = modelFactory.newModel(LkMetamodel) ;
	       
			
			transformationLauncher.addInModel(fInsModel, "InsModel", "InsMetaModel");
			transformationLauncher.addInModel(fiModel, "FModel", "FMetaModel");
			transformationLauncher.addOutModel(lkModel, "LKModel", "LKMetaModel");
			transformationLauncher.addLibrary("library_links", (ASM) transformationLauncher.loadModule(new FileInputStream("/Users/f/Modeling/workspace25/org.eclipse.toolchain/library_links.asm")));
			transformationLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), new HashMap<String,Object>(),
			new FileInputStream("/Users/f/Modeling/workspace25/org.eclipse.toolchain/Ins2Lk.asm"));

			extractor.extract(lkModel, "model.flk");
			
			EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
            emfModelFactory.unload((EMFModel) lkModel);
            emfModelFactory.unload((EMFModel) fiModel);
            emfModelFactory.unload((EMFModel) fInsModel);
            emfModelFactory.unload((EMFReferenceModel) fiMetamodel);
            emfModelFactory.unload((EMFReferenceModel) fInsMetamodel);
            emfModelFactory.unload((EMFReferenceModel) LkMetamodel);
           
			}catch (Exception e) {
				e.printStackTrace();
			}
		
	/*
	 * The second transformation 
	 */
	try {
			ILauncher transformationLauncher1 = new MyEMFVMLauncher();
			transformationLauncher1.initialize(new HashMap<String,Object>()) ;
			ModelFactory modelFactory1 = new EMFModelFactory();
			IInjector injector1 = new EMFInjector();
			IExtractor extractor1 = new EMFExtractor();
	
		
			IReferenceModel LkMetamodel = modelFactory1.newReferenceModel();
			injector1.inject(LkMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/LK.ecore");
			
			IReferenceModel fiMetamodel =modelFactory1.newReferenceModel() ;
			injector1.inject(fiMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/FI.ecore");
		    
			IReferenceModel tpnMetamodel = modelFactory1.newReferenceModel();
		    injector1.inject(tpnMetamodel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/metamodels/TPN.ecore");

		    IModel fkModel = modelFactory1.newModel(LkMetamodel);
		    injector1.inject(fkModel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/models/model.flk");
		
		    IModel fModel = modelFactory1.newModel(fiMetamodel) ;
		    injector1.inject(fModel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/models/model.f");
		    
		    IModel tpnModel = modelFactory1.newModel(tpnMetamodel) ;
       
		
		    transformationLauncher1.addInOutModel(fkModel, "LkModel", "LkMetaModel");
		    transformationLauncher1.addInOutModel(fModel, "FModel", "FMetaModel");
		    transformationLauncher1.addInOutModel(tpnModel, "TpnModel", "TpnMetaModel");
		    transformationLauncher1.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), new HashMap<String,Object>(),
		    		new FileInputStream("/Users/f/Modeling/workspace25/org.eclipse.toolchain/Lk2Tpn.asm"));

		    extractor1.extract(tpnModel, "/Users/f/Modeling/workspace25/org.eclipse.toolchain/models/model.tpn"); 
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
}

}


and this is the error

org.eclipse.m2m.atl.core.ATLCoreException: Error loading model.flk: null
	at org.eclipse.m2m.atl.core.emf.EMFInjector.inject(EMFInjector.java:70)
	at org.eclipse.m2m.atl.core.emf.EMFInjector.inject(EMFInjector.java:84)
	at org.eclipse.toolchain.Toolchain.main(Toolchain.java:142)
Caused by: java.lang.NullPointerException
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2164)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2042)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:128)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1847)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1030)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:81)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at org.eclipse.m2m.atl.core.emf.EMFInjector.inject(EMFInjector.java:65)
	... 2 more



Can you please help me!
Does it exist a java code which do the same (Successive ATL transformations + inter model references in java) ?
if it is exists, please share it!

Best regards,
Re: run successive ATL transformations with java [message #1164672 is a reply to message #1160684] Thu, 31 October 2013 21:15 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Hi,

There is a way to chain transformations without intermediate serialization:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.m2m.atl.doc%2Fguide%2Fuser%2FThe-ATL-Tools.html
("Making ATL transformations chains without intermediate serialization")

Could that help you ?

Aurel
Re: run successive ATL transformations with java [message #1165591 is a reply to message #1164672] Fri, 01 November 2013 11:50 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Dear Aurel,

thank you for your reply,
It works perfectly with ANT, and I can save the intermediate model.
This is an example of chaining of ATL transformations and also with the serialization of the intermediate model (for those who are interested)
<?xml version="1.0"?>
<project name="AtoBtoC" default="run" basedir=".">
    <property name="atl.launcher" value="EMF-specific VM" />

    <target name="run">
    	<atl.loadModel metamodel="%EMF" name="MA" path="./metamodels/A.ecore"/> 
    	<atl.loadModel metamodel="%EMF" name="MB" path="./metamodels/B.ecore"/>
    	<atl.loadModel metamodel="%EMF" name="MC" path="./metamodels/C.ecore"/>
    	
    	<atl.loadModel metamodel="MA" name="myModel-A" path="models/A.xmi"/>
    	
    	<atl.launch path="./transformations/AtoB.asm">
    		<option name="allowInterModelReferences" value="true"/>
    	 	<inmodel name="IN" model="myModel-A"/>			
    	 	<outmodel name="'''OUT'''" model="myModel-B" metamodel="MB"/>
    	</atl.launch>
    	
    	<atl.saveModel model="myModel-B" path="./models/B.xmi" />
    	
    	
    	<atl.launch path="./transformations/BtoC.asm">
    		<option name="allowInterModelReferences" value="true"/>
    		<inmodel name="INA" model="myModel-A"/> 
    	    <inmodel name="INB" model="myModel-B"/>			
    	 <outmodel name="OUT" model="myModel-C" metamodel="MC"/>
    	</atl.launch >
    	
    	<atl.saveModel model="myModel-C" path="./models/C.xmi" />

    </target>
</project>

However, I 'd like to run with java.
really, it is strange. It works with ANT but not with java Sad
Re: run successive ATL transformations with java [message #1169868 is a reply to message #1165591] Mon, 04 November 2013 08:43 Go to previous message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Would it be possible to reuse the same Model Factory everywhere ?
Maybe you can see how is ANT baking the launchers ?

Sorry I am not experienced with this kind of thing !
Previous Topic:convert XMI file TO Java class
Next Topic:[EMFTVM] How to transform stereotypes values?
Goto Forum:
  


Current Time: Fri Apr 26 12:20:56 GMT 2024

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

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

Back to the top