Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.security/src/org/eclipse/emf/cdo/internal/security/ViewUtil.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.security/src/org/eclipse/emf/cdo/internal/security/ViewUtil.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.security/src/org/eclipse/emf/cdo/internal/security/ViewUtil.java b/plugins/org.eclipse.emf.cdo.security/src/org/eclipse/emf/cdo/internal/security/ViewUtil.java
new file mode 100644
index 0000000000..f2468f6c07
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.security/src/org/eclipse/emf/cdo/internal/security/ViewUtil.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.security;
+
+import org.eclipse.emf.cdo.common.revision.CDORevisionProvider;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ViewUtil
+{
+ private static final ThreadLocal<ViewCreator> VIEW_CREATOR = new ThreadLocal<ViewCreator>();
+
+ private static final ThreadLocal<Map<CDORevisionProvider, CDOView>> VIEWS = new ThreadLocal<Map<CDORevisionProvider, CDOView>>();
+
+ private ViewUtil()
+ {
+ }
+
+ private static Map<CDORevisionProvider, CDOView> getViews()
+ {
+ Map<CDORevisionProvider, CDOView> views = VIEWS.get();
+ if (views == null)
+ {
+ views = new HashMap<CDORevisionProvider, CDOView>();
+ VIEWS.set(views);
+ }
+
+ return views;
+ }
+
+ public static CDOView getView(CDORevisionProvider revisionProvider)
+ {
+ Map<CDORevisionProvider, CDOView> views = getViews();
+
+ CDOView view = views.get(revisionProvider);
+ if (view == null)
+ {
+ ViewCreator viewCreator = VIEW_CREATOR.get();
+ if (viewCreator == null)
+ {
+ throw new IllegalStateException("No view creator available for " + revisionProvider);
+ }
+
+ view = viewCreator.createView(revisionProvider);
+ views.put(revisionProvider, view);
+ }
+
+ return view;
+ }
+
+ public static void initViewCreation(ViewCreator viewCreator)
+ {
+ VIEW_CREATOR.set(viewCreator);
+ }
+
+ public static void doneViewCreation()
+ {
+ VIEW_CREATOR.remove();
+ VIEWS.remove();
+ }
+}

Back to the top