diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationProviderBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationProviderBase.java new file mode 100644 index 0000000000000000000000000000000000000000..9999505af9b1d85fdce24e39b4de4ff74d1dd5c9 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationProviderBase.java @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2012 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.extension.base; + +import org.fortiss.tooling.kernel.extension.ITransformationProvider; +import org.fortiss.tooling.kernel.extension.data.ITransformationContext; +import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException; + +/** + * Base class for {@link ITransformationProvider}s. + * + * @param <S> + * the source object class + * @param <T> + * the target class + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating YELLOW Hash: E70B50712E9BA8739D02E8FE703FC5C0 + */ +public abstract class TransformationProviderBase<S extends Object, T extends Object> implements + ITransformationProvider { + + /** Returns the source class this provider can handle. */ + protected abstract Class<S> getSourceClass(); + + /** {@inheritDoc} */ + @Override + public abstract Class<T> getTargetClass(); + + /** {@inheritDoc} */ + @Override + public abstract T transform(Object source, ITransformationContext context) + throws TransformationFailedException; + + /** {@inheritDoc} */ + @Override + public boolean + canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) { + return getSourceClass().isAssignableFrom(sourceClass); + } + + /** {@inheritDoc} */ + @Override + public boolean canTransform(Object source, ITransformationContext context) { + return getSourceClass().isInstance(source); + } +}