From f943b129e7ba7944a8bcb904bbfd2af63519c8a6 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Tue, 23 Aug 2011 12:11:08 +0000
Subject: [PATCH] added base transformation contexts

---
 .../base/TransformationContextChainBase.java  | 65 +++++++++++++++++++
 .../ModelElementTransformationContext.java    | 53 +++++++++++++++
 2 files changed, 118 insertions(+)
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/TransformationContextChainBase.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/ModelElementTransformationContext.java

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 000000000..d8a980ac9
--- /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 000000000..9a3b61334
--- /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;
+	}
+}
-- 
GitLab