diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java index 4ca011907013d69aad4b12d55b342bde73f4c89c..e90ecfe664ddf82482583e438f51be2b3e0bc806 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TransformationUtils.java @@ -31,7 +31,7 @@ import org.fortiss.tooling.kernel.service.ITransformationService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: A592C08FD3D4504BBFC841C98C4A627A + * @ConQAT.Rating YELLOW Hash: 34A2DE2F88136C0B20E55E74D6E7F00A */ public final class TransformationUtils { /** @@ -44,24 +44,22 @@ public final class TransformationUtils { * the class of the transformation result * @param context * the transformation context - * @return the transformation result (an instance of class - * <code>targetClass</code>). + * @return the transformation result (an instance of class <code>targetClass</code>). * @throws ChainTransformationFailedException * if no transformation chain could be found or none of the * possible chains succeeded. */ @SuppressWarnings("unchecked") - public static <T extends Object> T createTransformedObjectFor( - final EObject sourceElement, final Class<T> targetClass, - ITransformationContext context) + public static <T extends Object> T createTransformedObjectFor(final EObject sourceElement, + final Class<T> targetClass, ITransformationContext context) throws ChainTransformationFailedException { - List<TransformationProviderChain> chainList = ITransformationService.INSTANCE - .getTransformationProviderChain(sourceElement.getClass(), - targetClass, context); + List<TransformationProviderChain> chainList = + ITransformationService.INSTANCE.getTransformationProviderChain( + sourceElement.getClass(), targetClass, context); ChainTransformationFailedException e = null; - if (!chainList.isEmpty()) { + if(!chainList.isEmpty()) { Object executableObject = null; - for (TransformationProviderChain chain : chainList) { + for(TransformationProviderChain chain : chainList) { try { // for the moment, we use the first chain // alternatives need an interpretation of the context, which @@ -69,37 +67,36 @@ public final class TransformationUtils { executableObject = chain.transform(sourceElement, context); e = null; break; - } catch (ChainTransformationFailedException ctfe) { + } catch(ChainTransformationFailedException ctfe) { // fall through e = ctfe; } } - if (e == null && executableObject != null) { - return (T) executableObject; + if(e == null && executableObject != null) { + return (T)executableObject; } } - if (e != null) { + if(e != null) { throw e; } throw new ChainTransformationFailedException(null, null, null, null) { /** {@inheritDoc} */ @Override public String getMessage() { - return "No transformation chain found from " + sourceElement - + " to " + targetClass.getName(); + return "No transformation chain found from " + sourceElement + " to " + + targetClass.getName(); } }; } /** * Searches a transformation chain for the given model element and the - * target class and returns the transformation result. This method returns - * <code>null</code> if the transformation failed. The exception is + * target class and returns the transformation result. This method returns <code>null</code> if + * the transformation failed. The exception is * suppressed. * * This is a fail-silent version of - * {@link #createTransformedObjectFor(EObject, Class, ITransformationContext)} - * . + * {@link #createTransformedObjectFor(EObject, Class, ITransformationContext)} . * * @param sourceElement * the source of the transformation @@ -107,18 +104,32 @@ public final class TransformationUtils { * the class of the transformation result * @param context * the transformation context - * @return the transformation result (an instance of class - * <code>targetClass</code>). + * @return the transformation result (an instance of class <code>targetClass</code>). */ public static <T extends Object> T createTransformedObjectWithoutExceptionFor( - EObject sourceElement, Class<T> targetClass, - ITransformationContext context) { + EObject sourceElement, Class<T> targetClass, ITransformationContext context) { try { - T result = createTransformedObjectFor(sourceElement, targetClass, - context); + T result = createTransformedObjectFor(sourceElement, targetClass, context); return result; - } catch (ChainTransformationFailedException ctfe) { + } catch(ChainTransformationFailedException ctfe) { return null; } } + + /** + * Searches a transformation chain for the given model element and the target class and returns + * {@code true} if such a chain exists. + * + * @param sourceElement + * the source of the transformation + * @param targetClass + * the class of the transformation result + * @param context + * the transformation context + * @return {@code true} if a transformation chain exists, {@code false} otherwise + */ + public static boolean canTransform(EObject sourceElement, Class<?> targetClass, + ITransformationContext context) { + return ITransformationService.INSTANCE.canTransform(sourceElement, targetClass, context); + } }