[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] [ATL] Saving Model Programmatically

Hi all,

I am using code from a post in Jan, by Wong who outlined code to use to do a transformation programmatically. The problem is when I go to save the model created from the transformation, I get an exception suggestion that the workspace is closed.

Below is the error and then the code (commented where exception occours)

Anybody have any ideas?
Mark

Trans MM: Author >>> Person
Trans Instance: IN >>> OUT
ASM: /home/mmelia/workspace3/AntworksDennies1/bin/Author2Person.asm
09-Jun-2008 12:39:30 org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel save
SEVERE: ERROR: save not implemented !
java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:326)
at org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlEMFModelHandler.java:144)
at org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlEMFModelHandler.java:65)
at JavaATL.ATLTransformations.runATLTransformation(JavaATL.java:111)
at JavaATL.ATLTransformations.main(JavaATL.java:43)


import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


import org.atl.eclipse.engine.AtlLauncher; import org.atl.eclipse.engine.AtlModelHandler; import org.atl.engine.vm.nativelib.ASMModel;


class ATLTransformations {



	public static void main(String[] args) {
		
		runATLTransformation();


}


public static void runATLTransformation() {


try {
AtlModelHandler emfamh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);


URL asmurl = ATLTransformations.class.getResource("../DM2CG.asm");
ASMModel inputMetaModel = emfamh.loadModel("DOMAIN", emfamh.getMof(), ATLTransformations.class.getResource("../Metamodels/skos2.ecore").openStream());
ASMModel outputMetaModel = emfamh.loadModel("COURSE", emfamh.getMof(), ATLTransformations.class.getResource("../Metamodels/Course.ecore").openStream());
ASMModel inputInstance = emfamh.loadModel("inputInstance", emfamh.getMof(), ATLTransformations.class.getResource("../caviar.ecore").openStream());
ASMModel outputInstance;



Map<String, ASMModel> models = new HashMap<String, ASMModel>();

models.put(inputMetaModel.getName(), inputMetaModel); models.put(outputMetaModel.getName(), outputMetaModel); System.out.println("Trans MM: "+inputMetaModel.getName()+" >>> "+outputMetaModel.getName());

models.put("IN", inputInstance); // input model
outputInstance = emfamh.newModel("coursexmi", outputMetaModel); // output model
models.put("OUT", outputInstance);
System.out.println("Trans Instance: "+inputInstance.getName()+" >>> "+outputInstance.getName());


Map params = Collections.EMPTY_MAP;
Map libs = Collections.EMPTY_MAP;

			System.out.println("ASM: "+asmurl.getPath());


AtlLauncher.getDefault().launch(asmurl, libs, models, params);

OutputStream out = new FileOutputStream(new File("C:/workspaceEclipse/Antworks/bin/zzzz.xmi"));


AtlModelHandler.getHandler(outputMetaModel).saveModel(outputInstance,out); //*************EXCEPTION THROWN**********************/



System.out.println(outputInstance);
out.flush();
out.close();

} catch (Exception e) {
e.printStackTrace();
}

}

}