package org.muml.psm.allocation.algorithm.qvto;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
import org.muml.psm.allocation.algorithm.main.IAllocationComputationStrategy;
import org.muml.psm.allocation.algorithm.main.IComputationResult;

public class QVToBasedAllocationComputationStrategy<V> implements
		IAllocationComputationStrategy<EObject, V> {
	
	private final String transformationURI;
	
	protected QVToBasedAllocationComputationStrategy(String transformationURI) {
		this.transformationURI = transformationURI;
	}

	@Override
	@NonNull
	public IComputationResult<EObject> computeAllocation(
			@NonNull EObject allocationSpecification,
			@NonNull EObject oclContext,
			@Nullable IProgressMonitor progressMonitor) {
		QVToSingleOutExtentTransformationRunner runner =
				new QVToSingleOutExtentTransformationRunner(
						transformationURI,
						getConfigurationPropertyMap(),
						allocationSpecification,
						oclContext);
		ExecutionDiagnostic executionDiagnostic =
				runner.runTransformation(progressMonitor);
		BasicDiagnostic rootDiagnostic = createDiagnostic(executionDiagnostic);
		EObject result = null;
		if (runner.getOutExtent().getContents().size() == 1) {
			result = runner.getOutExtent()
					.getContents().get(0);
		}
		return new IComputationResult.DefaultComputationResult<EObject>(
				rootDiagnostic, result);
	}
	
	protected Map<String, Object> getConfigurationPropertyMap() {
		return new HashMap<String, Object>();
	}
	
	@Override
	@Nullable
	public V getConfiguration() {
		// by default our strategy cannot be configured
		return null;
	}
	
	private static BasicDiagnostic createDiagnostic(ExecutionDiagnostic executionDiagnostic) {
		BasicDiagnostic rootDiagnostic = createDiagnostic(
				Diagnostic.OK, null);
		rootDiagnostic.add(executionDiagnostic);
		return rootDiagnostic;
	}
	
	private static BasicDiagnostic createDiagnostic(int severity, @Nullable String message) {
		return new BasicDiagnostic(severity, null, 0, null, null);
	}

}

@@ -560,16 +560,117 @@
 nResult;
+%0Aimport org.muml.psm.allocation.algorithm.qvto.QVToBasedStrategyTransformationRunner.ExecutionResult;
 %0A%0Apublic
@@ -1157,84 +1157,59 @@
 %7B%0A%09%09
-QVToSingleOutExtentTransformationRunner runner =%0A%09%09%09%09new QVToSingleOutExtent
+ExecutionResult executionResult = QVToBasedStrategy
 Tran
@@ -1228,17 +1228,13 @@
 nner
-(%0A%09%09%09%09%09%09t
+.runT
 rans
@@ -1246,52 +1246,28 @@
 tion
-URI,%0A%09%09%09%09%09%09getConfigurationPropertyMap(),%0A%09%09
+(transformationURI,%0A
 %09%09%09%09
@@ -1294,15 +1294,9 @@
 ion,
-%0A%09%09%09%09%09%09
+ 
 oclC
@@ -1305,84 +1305,53 @@
 text
-);%0A%09%09ExecutionDiagnostic executionDiagnostic =%0A%09%09%09%09runner.runTransformation(
+,%0A%09%09%09%09getConfigurationPropertyMap(),%09%09%09%09%0A%09%09%09%09
 prog
@@ -1417,32 +1417,42 @@
 nostic(execution
+Result.get
 Diagnostic);%0A%09%09E
@@ -1441,24 +1441,26 @@
 etDiagnostic
+()
 );%0A%09%09EObject
@@ -1485,39 +1485,35 @@
 if (
-runner.getOutExtent().getConten
+executionResult.getOutObjec
 ts()
@@ -1544,45 +1544,35 @@
 t = 
-runner.getOutExtent()%0A%09%09%09%09%09.getConten
+executionResult.getOutObjec
 ts()

Use the QVToBasedStrategyTransformationRunner