From fd876ac9063db86ed068a933a7be75453a844235 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 5 Sep 2011 15:31:18 +0000 Subject: [PATCH] fixed execution service. removed unnecessary platform transformations. added platform executable constraint. refs 136 --- .../internal/TransformationService.java | 3 +- ...tionUtil.java => TransformationUtils.java} | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) rename org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/{TransformationUtil.java => TransformationUtils.java} (73%) diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TransformationService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TransformationService.java index b39711750..8fceaae09 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TransformationService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TransformationService.java @@ -129,7 +129,8 @@ public class TransformationService extends List<ITransformationProvider> currentChain, Set<Class<?>> seenTargets, ITransformationContext context) { if (!currentChain.isEmpty() - && currentChain.get(currentChain.size() - 1).getTargetClass() == targetClass) { + && targetClass.isAssignableFrom(currentChain.get( + currentChain.size() - 1).getTargetClass())) { // found a complete chain => add to result and backtrack results.add(new TransformationProviderChain(currentChain)); return; diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtil.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java similarity index 73% rename from org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtil.java rename to org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java index c7c56ccdd..fa4c93ecd 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtil.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java @@ -33,23 +33,46 @@ import org.fortiss.tooling.kernel.service.ITransformationService; * @version $Rev$ * @ConQAT.Rating RED Hash: */ -public final class TransformationUtil { +public final class TransformationUtils { /** * Searches a transformation chain for the given model element and the * target class and returns the transformation result. */ @SuppressWarnings("unchecked") public static <T extends Object> T createTransformedObjectFor( - EObject modelElement, Class<T> targetClass, + final EObject modelElement, final Class<T> targetClass, ITransformationContext context) throws ChainTransformationFailedException { List<TransformationProviderChain> chainList = ITransformationService.INSTANCE .getTransformationProviderChain(modelElement.getClass(), targetClass, context); + ChainTransformationFailedException e = null; if (!chainList.isEmpty()) { - return (T) chainList.get(0).transform(modelElement, context); + Object executableObject = null; + for (TransformationProviderChain chain : chainList) { + try { + executableObject = chain.transform(modelElement, context); + e = null; + } catch (ChainTransformationFailedException ctfe) { + // fall through + e = ctfe; + executableObject = null; + } + } + if (e == null && executableObject != null) { + return (T) executableObject; + } } - return null; + if (e != null) { + throw e; + } + throw new ChainTransformationFailedException(null, null, null, null) { + /** {@inheritDoc} */ + @Override + public String getMessage() { + return "No transformation chain found from " + modelElement + + " to " + targetClass.getName(); + } + }; } - } -- GitLab