summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Roldan Betancort2008-12-10 14:11:01 (EST)
committerVictor Roldan Betancort2008-12-10 14:11:01 (EST)
commit97245a797cb48729d90e2fb5c68e5be1bbd0e8b9 (patch)
treef0564071e926844b0f917c1415174614c3693b1a
parent827fd4717d90eb331983d13a3d8833bc0928d164 (diff)
downloadcdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.zip
cdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.tar.gz
cdo-97245a797cb48729d90e2fb5c68e5be1bbd0e8b9.tar.bz2
[256955] Make ResourceSet capable of retrieving CDOResources without prior preparation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256955
-rw-r--r--plugins/org.eclipse.emf.cdo/plugin.xml26
-rw-r--r--plugins/org.eclipse.emf.cdo/schema/persistent_package.exsd107
-rw-r--r--plugins/org.eclipse.emf.cdo/schema/viewProviders.exsd138
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOViewSet.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java11
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java41
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/AbstractCDOViewProvider.java83
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProvider.java54
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProviderRegistry.java41
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java3
-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
14 files changed, 627 insertions, 130 deletions
diff --git a/plugins/org.eclipse.emf.cdo/plugin.xml b/plugins/org.eclipse.emf.cdo/plugin.xml
index cef4cec..538cbbf 100644
--- a/plugins/org.eclipse.emf.cdo/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo/plugin.xml
@@ -2,22 +2,22 @@
<?eclipse version="3.3"?>
<!--
<copyright>
-
+
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:
Eike Stepper - Initial API and implementation
-
+
</copyright>
-->
<plugin>
- <extension-point id="persistent_package" name="CDO Persistent Package" schema="schema/persistent_package.exsd"/>
+ <extension-point id="viewProviders" name="CDO View Providers" schema="schema/viewProviders.exsd"/>
<extension
point="org.eclipse.net4j.util.factories">
@@ -30,7 +30,7 @@
productGroup="org.eclipse.emf.cdo.sessions"
type="cdo"/>
</extension>
-
+
<extension
point="org.eclipse.net4j.util.elementProcessors">
<elementProcessor
@@ -40,16 +40,20 @@
<extension
point="org.eclipse.emf.ecore.generated_package">
- <package
- uri="http://www.eclipse.org/emf/CDO/resource/2.0.0"
+ <package
+ uri="http://www.eclipse.org/emf/CDO/resource/2.0.0"
class="org.eclipse.emf.cdo.eresource.EresourcePackage"
- genModel="model/resource.genmodel"/>
+ genModel="model/resource.genmodel"/>
</extension>
+
<extension
- point="org.eclipse.emf.cdo.persistent_package">
- <package
- uri="http://www.eclipse.org/emf/CDO/resource/2.0.0"/>
+ point="org.eclipse.emf.ecore.protocol_parser">
+ <parser
+ class="org.eclipse.emf.cdo.eresource.impl.CDOResourceFactoryImpl"
+ protocolName="cdo">
+ </parser>
</extension>
+
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo/schema/persistent_package.exsd b/plugins/org.eclipse.emf.cdo/schema/persistent_package.exsd
deleted file mode 100644
index ea36de7..0000000
--- a/plugins/org.eclipse.emf.cdo/schema/persistent_package.exsd
+++ /dev/null
@@ -1,107 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.emf.cdo">
-<annotation>
- <appInfo>
- <meta.schema plugin="org.eclipse.emf.cdo" id="persistent_package" name="CDO Persistent Package"/>
- </appInfo>
- <documentation>
- [Enter description of this extension point.]
- </documentation>
- </annotation>
-
- <element name="extension">
- <complexType>
- <sequence>
- <element ref="package"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appInfo>
- <meta.attribute translatable="true"/>
- </appInfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="package">
- <annotation>
- <appInfo>
- <meta.element labelAttribute="uri"/>
- </appInfo>
- </annotation>
- <complexType>
- <attribute name="uri" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appInfo>
- <meta.section type="since"/>
- </appInfo>
- <documentation>
- [Enter the first release in which this extension point appears.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="examples"/>
- </appInfo>
- <documentation>
- [Enter extension point usage example here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
- [Enter information about supplied implementation of this extension point.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="copyright"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
-</schema>
diff --git a/plugins/org.eclipse.emf.cdo/schema/viewProviders.exsd b/plugins/org.eclipse.emf.cdo/schema/viewProviders.exsd
new file mode 100644
index 0000000..afe14de
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/schema/viewProviders.exsd
@@ -0,0 +1,138 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.cdo" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.emf.cdo" id="viewProviders" name="CDO View Providers"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to define the CDOViewProvider factories that create instances capable of handling URIs according to the defined regular expression. This is registered to a global CDOViewProviderFactory Registry &lt;samp&gt;CDOViewProviderFactory.INSTANCE&lt;/samp&gt;
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="viewProvider" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="viewProvider">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.cdo.util.CDOViewProvider"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="regex" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="priority" type="string" use="default" value="500">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 2.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ Following is an example of how a URI scheme can be registered:
+&lt;pre&gt;
+ &lt;viewprovider factory=&quot;org.eclipse.emf.cdo.util.DefaultCDOViewProvider$DefaultCDOViewProviderFactory&quot;
+ high_priority=&quot;false&quot;
+ regex=&quot;cdo.*&quot;&gt;
+ &lt;/viewprovider&gt;
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ The value of the class attribute must represent a class
+that implements &lt;samp&gt;org.eclipse.emf.ecore.resource.Resource.Factory&lt;/samp&gt;.
+&lt;p&gt;
+A URI scheme can be also registered from the source code with the &lt;samp&gt;Resource.Factory.Registry.INSTANCE&lt;/samp&gt; as follows:
+&lt;/p&gt;
+&lt;pre&gt;
+ Resource.Factory.Registry.INSTANCE.putFactory(new DefaultCDOViewProviderFactory(), &quot;cdo.*&quot;, &quot;false&quot;);
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ org.eclipse.emf.cdo.util.DefaultCDOViewProvider$DefaultCDOViewProviderFactory provides default stub implementation. org.eclipse.emf.cdo.internal.ui.preferences.PreferencesCDOViewProvider.PreferencesCDOViewProviderFactory creates a provider that opens views according to a preference-page based repository URI list.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2002, 2004 Eike Stepper and others.&lt;br&gt;
+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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOViewSet.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOViewSet.java
index 60403fc..030705b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOViewSet.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOViewSet.java
@@ -27,6 +27,8 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
*/
public interface CDOViewSet extends Notifier
{
+ public CDOView resolveView(String repositoryUUID);
+
public CDOView[] getViews();
public CDOResourceFactory getResourceFactory();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
index 803283d..68415d5 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
@@ -11,6 +11,8 @@
**************************************************************************/
package org.eclipse.emf.cdo.eresource;
+import org.eclipse.emf.cdo.CDOViewSet;
+
import org.eclipse.emf.ecore.resource.Resource;
/**
@@ -18,4 +20,13 @@ import org.eclipse.emf.ecore.resource.Resource;
*/
public interface CDOResourceFactory extends Resource.Factory
{
+ /**
+ * @since 2.0
+ */
+ public CDOViewSet getViewSet();
+
+ /**
+ * @since 2.0
+ */
+ public void setViewSet(CDOViewSet viewSet);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java
index d5e8a83..eee1cc6 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java
@@ -4,7 +4,7 @@
* 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
* Simon McDuff - http://bugs.eclipse.org/213402
@@ -12,12 +12,14 @@
**************************************************************************/
package org.eclipse.emf.cdo.eresource.impl;
+import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.CDOViewSet;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.cdo.util.CDOViewProvider;
+import org.eclipse.emf.cdo.util.CDOViewProviderRegistry;
-import org.eclipse.emf.internal.cdo.CDOViewSetImpl;
-import org.eclipse.emf.internal.cdo.InternalCDOView;
+import org.eclipse.emf.internal.cdo.InternalCDOViewSet;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -33,26 +35,43 @@ public class CDOResourceFactoryImpl implements Resource.Factory, CDOResourceFact
/**
* @since 2.0
*/
- private CDOViewSetImpl viewSet;
+ private InternalCDOViewSet viewSet;
/**
* @since 2.0
*/
public CDOResourceFactoryImpl(CDOViewSet viewSet)
{
- this.viewSet = (CDOViewSetImpl)viewSet;
+ setViewSet(viewSet);
}
- public Resource createResource(URI uri)
+ public CDOResourceFactoryImpl()
{
- // URI can be invalid or incomplete. Extract repo + resource path and build a new URI.
- String repositoryUUID = CDOURIUtil.extractRepositoryUUID(uri);
+ }
- // repoUUID can be null but can be null
- InternalCDOView view = viewSet.resolveView(repositoryUUID);
- String path = CDOURIUtil.extractResourcePath(uri);
+ /**
+ * @since 2.0
+ */
+ public CDOViewSet getViewSet()
+ {
+ return viewSet;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void setViewSet(CDOViewSet viewSet)
+ {
+ this.viewSet = (InternalCDOViewSet)viewSet;
+ }
+
+ public Resource createResource(URI uri)
+ {
+ CDOViewProvider viewProvider = CDOViewProviderRegistry.INSTANCE.getViewProvider(uri);
+ CDOView view = viewProvider.getView(uri, viewSet);
// Build a new URI with the view and the path
+ String path = CDOURIUtil.extractResourcePath(uri);
URI newURI = CDOURIUtil.createResourceURI(view, path);
// Important: Set URI *after* registration with the view!
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index ed54f76..15edc35 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -802,6 +802,7 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
{
notifications = new NotificationChainImpl(2);
}
+
notifications.add(new NotificationImpl(Notification.SET, oldResourceSet, resourceSet)
{
@Override
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/AbstractCDOViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/AbstractCDOViewProvider.java
new file mode 100644
index 0000000..3ae9f18
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/AbstractCDOViewProvider.java
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * 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.cdo.util;
+
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+
+import org.eclipse.emf.common.util.URI;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Base logic to handle CDOViewProvider priority and regular expression.
+ *
+ * @author Victor Roldan Betancort
+ * @since 2.0
+ */
+public abstract class AbstractCDOViewProvider implements CDOViewProvider
+{
+ private String regex;
+
+ private int priority = DEFAULT_PRIORITY;
+
+ @ExcludeFromDump
+ private transient Pattern pattern;
+
+ public AbstractCDOViewProvider()
+ {
+ }
+
+ public AbstractCDOViewProvider(String regex, int priority)
+ {
+ this.regex = regex;
+ this.priority = priority;
+ }
+
+ public AbstractCDOViewProvider(String regex)
+ {
+ this(regex, DEFAULT_PRIORITY);
+ }
+
+ public int getPriority()
+ {
+ return priority;
+ }
+
+ public void setPriority(int priority)
+ {
+ this.priority = priority;
+ }
+
+ public String getRegex()
+ {
+ return regex;
+ }
+
+ public void setRegex(String regex)
+ {
+ this.regex = regex;
+ }
+
+ public boolean matchesRegex(URI uri)
+ {
+ synchronized (regex)
+ {
+ if (pattern == null)
+ {
+ pattern = Pattern.compile(regex);
+ }
+ }
+
+ Matcher matcher = pattern.matcher(uri.toString());
+ return matcher.matches();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
index f227c13..326dd6b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
@@ -4,7 +4,7 @@
* 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:
* Simon McDuff - initial API and implementation
* Eike Stepper - maintenance
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProvider.java
new file mode 100644
index 0000000..ceb0302
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProvider.java
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * 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.cdo.util;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.CDOViewSet;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Capable of opening a <code>CDOView</code> on a target repository, defined by a URI. A regular expression and the
+ * priority are used to determine which is the most suitable provider
+ *
+ * @since 2.0
+ * @author Victor Roldan Betancort
+ * @see CDOView
+ * @see CDOViewProviderRegistry
+ */
+public interface CDOViewProvider
+{
+ public static final int DEFAULT_PRIORITY = 500;
+
+ /**
+ * Returns the priority of this provider. Usually used to choose between several <code>CDOViewProvider</code> that
+ * match the same repository URI.
+ */
+ public int getPriority();
+
+ /**
+ * Returns the regular expression that determines if the provider can handle certain URI
+ */
+ public String getRegex();
+
+ /**
+ * Checks if the URI matches with the regular expression of this provider
+ */
+ public boolean matchesRegex(URI uri);
+
+ /**
+ * Receives a URI and returns an opened <code>CDOView</code> against the repository. The implementer is responsible to
+ * do the UUID to physical host map in case necessary.
+ *
+ * @return a wired-up and opened <code>CDOView</code>
+ */
+ public CDOView getView(URI uri, CDOViewSet viewSet);
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProviderRegistry.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProviderRegistry.java
new file mode 100644
index 0000000..a3d1094
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOViewProviderRegistry.java
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * 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.cdo.util;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * A registry of CDOViewProvider implementations.
+ *
+ * @author Victor Roldan Betancort
+ * @since 2.0
+ */
+public interface CDOViewProviderRegistry extends IContainer<CDOViewProvider>
+{
+ public static final CDOViewProviderRegistry INSTANCE = org.eclipse.emf.internal.cdo.util.CDOViewProviderRegistryImpl.INSTANCE;
+
+ /**
+ * Returns a <code>CDOViewProvider</code> instance, determined by certain criteria based on the argument URI.
+ */
+ public CDOViewProvider getViewProvider(URI uri);
+
+ /**
+ * Registers a new <code>CDOViewProvider</code> instance
+ */
+ public void addViewProvider(CDOViewProvider viewProvider);
+
+ /**
+ * Removes certain <code>CDOViewProvider</code> instance from the registry
+ */
+ public void removeViewProvider(CDOViewProvider viewProvider);
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
index 8b3e0d8..edab834 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.internal.cdo.bundle;
import org.eclipse.emf.internal.cdo.util.CDOPackageTypeRegistryImpl;
+import org.eclipse.emf.internal.cdo.util.CDOViewProviderRegistryImpl;
import org.eclipse.net4j.util.om.OSGiActivator;
@@ -115,6 +116,7 @@ public final class Activator extends EMFPlugin
*/
protected void doStart() throws Exception
{
+ CDOViewProviderRegistryImpl.INSTANCE.activate();
}
/**
@@ -122,6 +124,7 @@ public final class Activator extends EMFPlugin
*/
protected void doStop() throws Exception
{
+ CDOViewProviderRegistryImpl.INSTANCE.deactivate();
CDOPackageTypeRegistryImpl.INSTANCE.deactivate();
}
}
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 0000000..ece60dd
--- /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 0000000..c5dd643
--- /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);
+ }
+ }
+ }
+}