Bug 479778 - [DI] Exceptions with concurrent user sessions

Running e4 application in a multi-user environment (RAP) leads to
concurrency exceptions (see bug 487874 and bug 479778). The root cause
is the shared service context between e4 workbench instances. To
workaround this issue we need this new API.

Add EclipseContextFactory#createServiceContext API.

Change-Id: I7e9aebd31f6eb15c72b79b41d2f70367b158b78f
Signed-off-by: Ivan Furnadjiev <ivan@eclipsesource.com>
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/EclipseContextFactory.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/EclipseContextFactory.java
index 5fdabb5..e7124e9 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/EclipseContextFactory.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/EclipseContextFactory.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2013 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -55,11 +55,26 @@
 		synchronized (serviceContexts) {
 			IEclipseContext result = serviceContexts.get(bundleContext);
 			if (result == null) {
-				result = new EclipseContextOSGi(bundleContext);
-				result.set(EclipseContext.DEBUG_STRING, "OSGi context for bundle: " + bundleContext.getBundle().getSymbolicName()); //$NON-NLS-1$
+				result = createServiceContext(bundleContext);
 				serviceContexts.put(bundleContext, result);
 			}
 			return result;
 		}
 	}
+
+	/**
+	 * Creates and returns a new context that can be used to lookup OSGi
+	 * services. A client must dispose the provided context.
+	 *
+	 * @param bundleContext The bundle context to use for service lookup
+	 * @return A new context containing all OSGi services
+	 *
+	 * @since 1.5
+	 */
+	public static IEclipseContext createServiceContext(BundleContext bundleContext) {
+		IEclipseContext result = new EclipseContextOSGi(bundleContext);
+		result.set(EclipseContext.DEBUG_STRING, "OSGi context for bundle: " + bundleContext.getBundle().getSymbolicName()); //$NON-NLS-1$
+		return result;
+	}
+
 }
\ No newline at end of file