From 78edefc7871bdb11b487481876add645738762e0 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Tue, 1 Mar 2011 16:30:15 +0000
Subject: [PATCH] added emfstore and unicase client storage location providers

---
 org.fortiss.tooling.kernel/trunk/plugin.xml   | 12 +++
 ...ipseWorkspaceEMFStoreLocationProvider.java | 45 ++++++++++
 .../EclipseWorkspaceLocationProviderBase.java | 89 +++++++++++++++++++
 ...orkspaceUnicaseClientLocationProvider.java | 46 ++++++++++
 4 files changed, 192 insertions(+)
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceEMFStoreLocationProvider.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceLocationProviderBase.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceUnicaseClientLocationProvider.java

diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml
index c87f11ba8..e83075af4 100644
--- a/org.fortiss.tooling.kernel/trunk/plugin.xml
+++ b/org.fortiss.tooling.kernel/trunk/plugin.xml
@@ -13,6 +13,18 @@
             uri="http://www.fortiss.org/tooling/kernel">
       </package>
    </extension>
+   <extension
+         point="org.unicase.emfstore.locationprovider">
+      <LocationProvider
+            providerClass="org.fortiss.tooling.kernel.internal.emfstore.EclipseWorkspaceEMFStoreLocationProvider">
+      </LocationProvider>
+   </extension>
+   <extension
+         point="org.unicase.workspace.workspaceLocationProvider">
+      <LocationProvider
+            providerClass="org.fortiss.tooling.kernel.internal.emfstore.EclipseWorkspaceUnicaseClientLocationProvider">
+      </LocationProvider>
+   </extension>
    <extension
          point="org.eclipse.ui.editors">
       <editor
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceEMFStoreLocationProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceEMFStoreLocationProvider.java
new file mode 100644
index 000000000..7901f0c96
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceEMFStoreLocationProvider.java
@@ -0,0 +1,45 @@
+/*--------------------------------------------------------------------------+
+$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.internal.emfstore;
+
+import org.unicase.emfstore.LocationProvider;
+
+/**
+ * A {@link LocationProvider} which uses the Eclipse workspace location as base
+ * location. This provider is intended to be used with the
+ * <code>org.unicase.emfstore.locationprovider</code> extension point.
+ * 
+ * @author hoelzlf
+ * @author $Author$
+ * @version $Rev$
+ * @levd.rating RED Rev:
+ */
+public final class EclipseWorkspaceEMFStoreLocationProvider extends
+		EclipseWorkspaceLocationProviderBase {
+	/** {@inheritDoc} */
+	@Override
+	protected String getWorkspaceProjectName() {
+		return ".unicase_client";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected String getBackupProjectName() {
+		return ".unicase_client_backup";
+	}
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceLocationProviderBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceLocationProviderBase.java
new file mode 100644
index 000000000..08bb4cf0c
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceLocationProviderBase.java
@@ -0,0 +1,89 @@
+/*--------------------------------------------------------------------------+
+$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.internal.emfstore;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.unicase.emfstore.LocationProvider;
+
+/**
+ * Base implementation of a {@link LocationProvider} which uses the Eclipse
+ * workspace location as base location.
+ * 
+ * @author hoelzlf
+ * @author $Author$
+ * @version $Rev$
+ * @levd.rating RED Rev:
+ */
+public abstract class EclipseWorkspaceLocationProviderBase implements
+		LocationProvider {
+
+	/** Store the workspace location. */
+	private final IProject workspaceProject;
+
+	/** Stores the backup location. */
+	private final IProject backupProject;
+
+	/** Constructor. */
+	public EclipseWorkspaceLocationProviderBase() {
+		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+		this.workspaceProject = workspaceRoot
+				.getProject(getWorkspaceProjectName());
+		if (!workspaceProject.exists()) {
+			try {
+				workspaceProject.create(null);
+			} catch (CoreException e) {
+				printCreationError(getWorkspaceProjectName(), e);
+			}
+		}
+		this.backupProject = workspaceRoot.getProject(getBackupProjectName());
+		if (!backupProject.exists()) {
+			try {
+				backupProject.create(null);
+			} catch (CoreException e) {
+				printCreationError(getBackupProjectName(), e);
+			}
+		}
+	}
+
+	/** Prints error message to standard error. */
+	private final void printCreationError(String projectName, Exception ex) {
+		System.err.println("Could not create project " + projectName);
+		ex.printStackTrace(System.err);
+	}
+
+	/** Returns the name of the workspace project. */
+	protected abstract String getWorkspaceProjectName();
+
+	/** Returns the name of the backup project. */
+	protected abstract String getBackupProjectName();
+
+	/** {@inheritDoc} */
+	@Override
+	public final String getWorkspaceDirectory() {
+		return workspaceProject.getFullPath().toString();
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final String getBackupDirectory() {
+		return backupProject.getFullPath().toString();
+	}
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceUnicaseClientLocationProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceUnicaseClientLocationProvider.java
new file mode 100644
index 000000000..703f611d0
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/emfstore/EclipseWorkspaceUnicaseClientLocationProvider.java
@@ -0,0 +1,46 @@
+/*--------------------------------------------------------------------------+
+$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.internal.emfstore;
+
+import org.unicase.emfstore.LocationProvider;
+
+/**
+ * A {@link LocationProvider} which uses the Eclipse workspace location as base
+ * location. This provider is intended to be used with the
+ * <code>org.unicase.workspace.workspaceLocationProvider</code> extension point.
+ * 
+ * @author hoelzlf
+ * @author $Author$
+ * @version $Rev$
+ * @levd.rating RED Rev:
+ */
+public final class EclipseWorkspaceUnicaseClientLocationProvider extends
+		EclipseWorkspaceLocationProviderBase {
+
+	/** {@inheritDoc} */
+	@Override
+	protected String getWorkspaceProjectName() {
+		return "emfStoreServerWorkspaceProject";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected String getBackupProjectName() {
+		return "emfStoreServerBackupProject";
+	}
+}
-- 
GitLab