diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationContextChainBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationContextChainBase.java new file mode 100644 index 0000000000000000000000000000000000000000..d8a980ac9d08c94c69e4b6d7724c6ad8a476dd91 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationContextChainBase.java @@ -0,0 +1,65 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.data.ITransformationContext; + +/** + * Base implementation of {@link ITransformationContext}, which stores a + * reference to another context. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating YELLOW Hash: 662BCDD98432EED08BA052803173A5D0 + */ +public abstract class TransformationContextChainBase implements + ITransformationContext { + + /** Stores the chained context. */ + protected final ITransformationContext chainedContext; + + /** Constructor. */ + public TransformationContextChainBase(ITransformationContext chainedContext) { + this.chainedContext = chainedContext; + } + + /** Constructor. */ + public TransformationContextChainBase() { + this(null); + } + + /** Returns the next {@link ITransformationContext} in the chain. */ + public ITransformationContext getNextContext() { + return chainedContext; + } + + /** Finds an ITransform of the given class in the chain. */ + @SuppressWarnings("unchecked") + public <T extends ITransformationContext> T findContextinChain( + Class<T> clazz) { + if (clazz.isAssignableFrom(this.getClass())) { + return (T) this; + } + if (chainedContext instanceof TransformationContextChainBase) { + return ((TransformationContextChainBase) chainedContext) + .findContextinChain(clazz); + } + return null; + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/ModelElementTransformationContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/ModelElementTransformationContext.java new file mode 100644 index 0000000000000000000000000000000000000000..9a3b61334ac6ecf4e8fad7dd114bec1d7be25ca8 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/ModelElementTransformationContext.java @@ -0,0 +1,53 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.data; + +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.extension.base.TransformationContextChainBase; + +/** + * An {@link ITransformationContext} with an EObject context element. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating YELLOW Hash: 86FBA7A228E86492FB4A54CDD086CFCC + */ +public class ModelElementTransformationContext extends + TransformationContextChainBase { + + /** Stores the model element. */ + protected final EObject modelElement; + + /** Constructor. */ + public ModelElementTransformationContext(EObject modelElement, + ITransformationContext context) { + super(context); + this.modelElement = modelElement; + } + + /** Constructor. */ + public ModelElementTransformationContext(EObject modelElement) { + this(modelElement, null); + } + + /** Returns the model element. */ + public EObject getModelElement() { + return modelElement; + } +}