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 b39711750b62143088fc6c833f7c811f9fb11310..8fceaae0910083454f56f8b5c0abdae3bbc87e07 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 c7c56ccdd39a4aad93440569688af1373b8f968b..fa4c93ecd1930bd5f66f03d4079201d0d6951160 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(); + } + }; } - }