|
|
|
Re: Execute atl in a java program [message #898735 is a reply to message #897409] |
Fri, 27 July 2012 11:46 |
Gunnar Arndt Messages: 82 Registered: June 2012 |
Member |
|
|
You can easily replace the deprecated methods of ATLLauncher by valid ones with an additional parameter.
This is the code I am currently using for that purpose (still having problems during the transformation, though):
final Map<String, ASMEMFModel> models = new HashMap<String, ASMEMFModel>();
final AtlEMFModelHandler modelHandler = (AtlEMFModelHandler) AtlModelHandler
.getDefault(AtlModelHandler.AMH_EMF);
final EMFModelLoader modelLoader = (EMFModelLoader) modelHandler
.createModelLoader();
/**
* Create the metamodels' URIs.
*/
final URI modelTransformationModelResource =
URI.createFileURI("..\\ModelTransformation.ecore");
final URI otxModelResource =
URI.createFileURI("..\\otx.ecore");
final URI hmiModelResource =
URI.createFileURI("..\\hmi.ecore");
/**
* Load the metamodels by their previously created URI.
*/
final ASMEMFModel modelTransformationMetaModel = modelLoader
.loadModel("ModelTransformation", modelLoader.getMOF(),
modelTransformationModelResource);
final ASMEMFModel otxMetaModel = modelLoader.loadModel("otx",
modelLoader.getMOF(), otxModelResource);
final ASMEMFModel hmiMetaModel = modelLoader.loadModel("hmi",
modelLoader.getMOF(), hmiModelResource);
/**
* Load the input model from the given file.
*/
final URI inputModelUri = URI.createFileURI(inputFile.getPath());
final ASMEMFModel modelTransformationInputModel = modelLoader
.loadModel("IN", modelTransformationMetaModel,
inputModelUri);
/**
* Create output models (TODO allow inter-model references!).
*/
final URI otxOutputUri = URI.createFileURI(new File(folder
.getAbsolutePath(), "out.otx").getPath());
final ASMEMFModel otxOutputModel = (ASMEMFModel) modelLoader
.newModel("OUT", otxOutputUri.toFileString(), otxMetaModel);
final URI hmiOutputUri = URI.createFileURI(new File(folder
.getAbsolutePath(), "out.hmi").getPath());
final ASMEMFModel hmiOutputModel = (ASMEMFModel) modelLoader
.newModel("hmi", hmiOutputUri.toFileString(), hmiMetaModel);
models.put("transformate", modelTransformationMetaModel);
models.put("otx", otxMetaModel);
models.put("otxHmi", hmiMetaModel);
models.put("IN", modelTransformationInputModel);
models.put("OUT", otxOutputModel);
models.put("hmi", hmiOutputModel);
/**
* Determine the compiled ATL rule file.
*/
final URL atlAsmUrl = new URL(
"..\\transformate2otx.asm");
/**
* Important: Allow inter-model references.
*/
final Map<String, String> options = new HashMap<String, String>();
options.put("allowInterModelReferences", "true");
// options.put("outputModelContentTypesDetection", "true");
/**
* Perform the model-to-model transformation.
*/
AtlLauncher.getDefault().launch(atlAsmUrl, Collections.emptyMap(),
models, Collections.emptyMap(), Collections.emptyList(),
options);
modelLoader.save(otxOutputModel, otxOutputUri.toFileString());
You'll have to replace the file names, of course.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03620 seconds