[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] Re: [ATL] ATL API strangeness

Rene Ladan wrote:
I get some strange results when programmatically invoking ATL.
The method doATLTransformation() in the attached file Transform.java doesn't seem to save the output models to the correct place.
Currently, everything is sent to outModels[0], but the output should go to the specified index of outModels[] (here 2).
As a result, the wrong part of the instance model gets substituted (which happens to throw an exception).


Another bogus index: outModels[5] (i.e. the last assignment)

I've attached a diff representing the current Transform.java (mostly cleanups, still bogus).


Could I be bogusly aliasing something in Transform.java?

I'm currently using Eclipse 3.3.2 (20080221) with EMF 2.3.1 (20080205) and ATL 2.0.0 (20080303).
There didn't seem any updates available.

Rene
Index: Transform.java
===================================================================
--- Transform.java	(revision 313)
+++ Transform.java	(working copy)
@@ -25,6 +25,10 @@
  * @author rladan
  */
 public class Transform {
+
+	/** Array containing the model type names. */
+	public final String[] modelNames = {"scenario", "udd", "action_beh", "action_proc", "behaviour", "resource"};
+
 	private String transPath = Utils.mainPath + "transformations/";
 	private final HashMap<String, ASMEMFModel> models = new HashMap<String, ASMEMFModel>();
 	private ASMEMFModel metaModel;
@@ -40,7 +44,6 @@
 	 */
 	private void addMetaModel(final String metaid, final String metapath) throws FileNotFoundException {
 		this.metaModel = (ASMEMFModel) ((AtlEMFModelHandler) this.amh).loadModel(metaid, this.amh.getMof(), new FileInputStream(metapath));
-		this.metaModel.setIsTarget(false);
 		this.models.put(metaid, this.metaModel);
 	}
 
@@ -52,7 +55,6 @@
 	private void addInputModel(final ByteArrayInputStream inModel, final String inModelName) {
 		ASMEMFModel inputModel;
 		inputModel = (ASMEMFModel) ((AtlEMFModelHandler) this.amh).loadModel(inModelName, this.metaModel, inModel);
-		inputModel.setIsTarget(false);
 		inputModel.setCheckSameModel(false);
 		this.models.put(inModelName, inputModel);
 	}
@@ -66,7 +68,6 @@
 		ASMEMFModel outputModel;
 		try {
 			outputModel = ASMEMFModel.newASMEMFModel(outModelName, outModelName, this.metaModel, this.ml);
-			outputModel.setIsTarget(true);
 			outputModel.setCheckSameModel(false);
 			this.models.put(outModelName, outputModel);
 		} catch (final Exception e) {
@@ -100,36 +101,20 @@
 		this.addMetaModel("meta", this.transPath + "meta.ecore");
 		this.addInputModel(parameters, "parameters");
 
-		if (inModels[0].available() > 0)
-			this.addInputModel(inModels[0], "IN_scenario");
-		this.addOutputModel("OUT_scenario");
+		for (int i = 0; i < this.modelNames.length; i++)
+			if (inModels[i].available() > 0) {
+				this.addInputModel(inModels[i], "IN_" + this.modelNames[i]);
+				this.addOutputModel("OUT_" + this.modelNames[i]);
+				inModels[i].reset();
+			}
 
-		if (inModels[1].available() > 0)
-			this.addInputModel(inModels[1], "IN_udd");
-		this.addOutputModel("OUT_udd");
-
-		if (inModels[2].available() > 0)
-			this.addInputModel(inModels[2], "IN_action_beh");
-		if (inModels[3].available() > 0)
-			this.addInputModel(inModels[3], "IN_action_proc");
-		this.addOutputModel("OUT_action");
-
-		if (inModels[4].available() > 0)
-			this.addInputModel(inModels[4], "IN_behaviour");
-		this.addOutputModel("OUT_behaviour");
-
-		if (inModels[5].available() > 0)
-			this.addInputModel(inModels[5], "IN_resource");
-		this.addOutputModel("OUT_resource");
-
 		final AtlLauncher myLauncher = AtlLauncher.getDefault();
 		myLauncher.launch(trans, libs, this.models, Collections.EMPTY_MAP, Collections.EMPTY_LIST, Collections.EMPTY_MAP);
 
- 		this.amh.saveModel(this.models.get("OUT_scenario"), outModels[0]);
-		this.amh.saveModel(this.models.get("OUT_udd"), outModels[1]);
-		this.amh.saveModel(this.models.get("OUT_action_beh"), outModels[2]);
-		this.amh.saveModel(this.models.get("OUT_action_proc"), outModels[3]);
-		this.amh.saveModel(this.models.get("OUT_behaviour"), outModels[4]);
-		this.amh.saveModel(this.models.get("OUT_resource"), outModels[5]);
+		for (int i = 0; i < this.modelNames.length; i++) {
+			inModels[i].reset();
+			if (inModels[i].available() > 0)
+				this.amh.saveModel(this.models.get("OUT_" + this.modelNames[i]), outModels[i]);
+		}
 	}
 }