From c6c831c6c47da54c5b46b1f2feda3a23ec5f9343 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Thu, 14 Jun 2012 14:34:48 +0000 Subject: [PATCH] further rework of code generator (still to weird) refs 857 --- .../base/TransformationProviderBase.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationProviderBase.java 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 000000000..9999505af --- /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); + } +} -- GitLab