Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Roldan Betancort2008-12-10 14:11:01 -0500
committerVictor Roldan Betancort2008-12-10 14:11:01 -0500
commit97245a797cb48729d90e2fb5c68e5be1bbd0e8b9 (patch)
treef0564071e926844b0f917c1415174614c3693b1a /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util
parent827fd4717d90eb331983d13a3d8833bc0928d164 (diff)
downloadcdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.tar.gz
cdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.tar.xz
cdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.zip
[256955] Make ResourceSet capable of retrieving CDOResources without prior preparation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256955
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java48
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java200
2 files changed, 248 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java
new file mode 100644
index 0000000000..ece60dd4fa
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Victor Roldan Betancort - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.CDOViewSet;
+import org.eclipse.emf.cdo.util.AbstractCDOViewProvider;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Emulates the same behaviour as before the CDOViewProvider concept was introduced. Will provide a view from an already
+ * populated <code>CDOViewSet</code>
+ *
+ * @author Victor Roldan Betancort
+ * @since 2.0
+ */
+public class CDOViewProviderImpl extends AbstractCDOViewProvider
+{
+ public CDOViewProviderImpl()
+ {
+ super("cdo:.*");
+ }
+
+ public CDOView getView(URI uri, CDOViewSet viewSet)
+ {
+ if (viewSet == null)
+ {
+ throw new IllegalArgumentException("viewSet == null");
+ }
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("uri == null");
+ }
+
+ String repositoryUUID = CDOURIUtil.extractRepositoryUUID(uri);
+ return viewSet.resolveView(repositoryUUID);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java
new file mode 100644
index 0000000000..c5dd643f8e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java
@@ -0,0 +1,200 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Victor Roldan Betancort - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.CDOViewSet;
+import org.eclipse.emf.cdo.util.AbstractCDOViewProvider;
+import org.eclipse.emf.cdo.util.CDOViewProvider;
+import org.eclipse.emf.cdo.util.CDOViewProviderRegistry;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.container.Container;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import org.eclipse.emf.common.util.URI;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * When instanced in Eclipse, it's populated with contributions from the viewProvider Extension Point. A default
+ * CDOViewProvider implementation is registered, regardless of the execution environment.
+ *
+ * @author Victor Roldan Betancort
+ * @since 2.0
+ * @see CDOViewProvider
+ */
+public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider> implements CDOViewProviderRegistry
+{
+ public static final CDOViewProviderRegistryImpl INSTANCE = new CDOViewProviderRegistryImpl();
+
+ private static final String EXT_POINT = "viewProviders";
+
+ private List<CDOViewProvider> viewProviders = new ArrayList<CDOViewProvider>();
+
+ public CDOViewProviderRegistryImpl()
+ {
+ addViewProvider(new CDOViewProviderImpl());
+ }
+
+ public CDOViewProvider getViewProvider(URI uri)
+ {
+ CDOViewProvider result = null;
+ for (CDOViewProvider viewProvider : viewProviders)
+ {
+ if (viewProvider.matchesRegex(uri))
+ {
+ if (result == null || result.getPriority() < viewProvider.getPriority())
+ {
+ result = viewProvider;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public void addViewProvider(CDOViewProvider viewProvider)
+ {
+ boolean added;
+ synchronized (viewProviders)
+ {
+ added = !viewProviders.contains(viewProvider);
+ if (added)
+ {
+ viewProviders.add(viewProvider);
+ }
+ }
+
+ if (added)
+ {
+ fireElementAddedEvent(viewProvider);
+ }
+ }
+
+ public void removeViewProvider(CDOViewProvider viewProvider)
+ {
+ boolean removed;
+ synchronized (viewProviders)
+ {
+ removed = viewProviders.remove(viewProvider);
+ }
+
+ if (removed)
+ {
+ fireElementRemovedEvent(viewProvider);
+ }
+ }
+
+ public CDOViewProvider[] getElements()
+ {
+ synchronized (viewProviders)
+ {
+ return viewProviders.toArray(new CDOViewProvider[viewProviders.size()]);
+ }
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ synchronized (viewProviders)
+ {
+ return viewProviders.isEmpty();
+ }
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ if (OMPlatform.INSTANCE.isOSGiRunning())
+ {
+ try
+ {
+ readExtensions();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.error(t);
+ }
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ super.doDeactivate();
+ }
+
+ public void readExtensions()
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT);
+ for (IConfigurationElement element : configurationElements)
+ {
+ try
+ {
+ CDOViewProviderDescriptor descriptor = new CDOViewProviderDescriptor(element);
+ addViewProvider(descriptor);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class CDOViewProviderDescriptor extends AbstractCDOViewProvider
+ {
+ private IConfigurationElement element;
+
+ public CDOViewProviderDescriptor(IConfigurationElement element)
+ {
+ super(element.getAttribute("regex"), Integer.parseInt(element.getAttribute("priority")));
+ this.element = element;
+
+ if (StringUtil.isEmpty(element.getAttribute("class")))
+ {
+ throw new IllegalArgumentException("class not defined for extension " + element);
+ }
+
+ if (StringUtil.isEmpty(element.getAttribute("regex")))
+ {
+ throw new IllegalArgumentException("regex not defined for extension " + element);
+ }
+ }
+
+ public CDOView getView(URI uri, CDOViewSet viewSet)
+ {
+ try
+ {
+ CDOViewProvider viewProvider = (CDOViewProvider)element.createExecutableExtension("class");
+ return viewProvider.getView(uri, viewSet);
+ }
+ catch (CoreException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+}

Back to the top