summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-28 03:51:28 (EDT)
committerEike Stepper2008-04-28 03:51:28 (EDT)
commit528983f0e7f1d228431b7826c56c7f41e2bf9bd2 (patch)
treee3c37403726c9bb0dc1bf53cd6253825acf7507f
parent3180457e9c4298980b5d3479222a59c913597cff (diff)
downloadcdo-528983f0e7f1d228431b7826c56c7f41e2bf9bd2.zip
cdo-528983f0e7f1d228431b7826c56c7f41e2bf9bd2.tar.gz
cdo-528983f0e7f1d228431b7826c56c7f41e2bf9bd2.tar.bz2
[227995] Implement a self-populating EPackageRegistry
https://bugs.eclipse.org/bugs/show_bug.cgi?id=227995
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectPackageDialog.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageTypeRegistry.java23
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java72
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java (renamed from plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java)58
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageTypeRegistryImpl.java177
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java2
12 files changed, 260 insertions, 104 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java
index e0ec0f3..70c0268 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java
@@ -19,7 +19,7 @@ import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.ui.CDOItemProvider;
import org.eclipse.emf.cdo.util.CDOPackageRegistry;
import org.eclipse.emf.cdo.util.CDOPackageType;
-import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.ui.UIUtil;
@@ -198,7 +198,7 @@ public class PackageManagerDialog extends TitleAreaDialog
uri = ((EPackage)ePackage).getNsURI();
}
- CDOPackageType packageType = CDOUtil.getPackageTypes().get(uri);
+ CDOPackageType packageType = CDOPackageTypeRegistry.INSTANCE.get(uri);
if (packageType == null)
{
return "?";
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectPackageDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectPackageDialog.java
index 2b5db25..a79be83 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectPackageDialog.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/SelectPackageDialog.java
@@ -13,7 +13,7 @@ package org.eclipse.emf.cdo.internal.ui.dialogs;
import org.eclipse.emf.cdo.internal.ui.SharedIcons;
import org.eclipse.emf.cdo.internal.ui.bundle.OM;
import org.eclipse.emf.cdo.util.CDOPackageType;
-import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.widgets.BaseDialog;
@@ -37,7 +37,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -47,8 +46,6 @@ public class SelectPackageDialog extends BaseDialog<CheckboxTableViewer>
{
private static final Set<String> NO_URIS = Collections.emptySet();
- private Map<String, CDOPackageType> packageTypes = CDOUtil.getPackageTypes();
-
private Set<String> excludedURIs = new HashSet<String>();
private Set<String> checkedURIs = new HashSet<String>();
@@ -76,7 +73,7 @@ public class SelectPackageDialog extends BaseDialog<CheckboxTableViewer>
viewer.getTable().setLayoutData(UIUtil.createGridData());
viewer.setContentProvider(new PackageContentProvider());
viewer.setLabelProvider(new PackageLabelProvider());
- viewer.setInput(packageTypes);
+ viewer.setInput(CDOPackageTypeRegistry.INSTANCE);
String[] uris = OM.PREF_HISTORY_SELECT_PACKAGES.getValue();
if (uris != null)
@@ -119,7 +116,7 @@ public class SelectPackageDialog extends BaseDialog<CheckboxTableViewer>
public Object[] getElements(Object inputElement)
{
- Set<String> uris = new HashSet<String>(packageTypes.keySet());
+ Set<String> uris = new HashSet<String>(CDOPackageTypeRegistry.INSTANCE.keySet());
uris.removeAll(excludedURIs);
List<String> elements = new ArrayList<String>(uris);
@@ -150,7 +147,7 @@ public class SelectPackageDialog extends BaseDialog<CheckboxTableViewer>
{
if (element instanceof String)
{
- CDOPackageType packageType = packageTypes.get(element);
+ CDOPackageType packageType = CDOPackageTypeRegistry.INSTANCE.get(element);
switch (packageType)
{
case CONVERTED:
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
index 3644db7..708f370 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
@@ -37,7 +37,7 @@ import org.eclipse.emf.cdo.internal.ui.actions.RollbackTransactionAction;
import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory;
import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory.Entry;
import org.eclipse.emf.cdo.util.CDOPackageType;
-import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.util.container.IContainer;
@@ -315,7 +315,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
protected boolean fillGenerated(MenuManager manager, CDOSession session)
{
- Set<Map.Entry<String, CDOPackageType>> entrySet = CDOUtil.getPackageTypes().entrySet();
+ Set<Map.Entry<String, CDOPackageType>> entrySet = CDOPackageTypeRegistry.INSTANCE.entrySet();
List<Map.Entry<String, CDOPackageType>> entryList = new ArrayList<Map.Entry<String, CDOPackageType>>(entrySet);
Collections.sort(entryList, new Comparator<Map.Entry<String, CDOPackageType>>()
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageTypeRegistry.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageTypeRegistry.java
new file mode 100644
index 0000000..f9fd681
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageTypeRegistry.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * 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
+ **************************************************************************/
+package org.eclipse.emf.cdo.util;
+
+import org.eclipse.net4j.util.registry.IRegistry;
+
+/**
+ * Can only be used with Eclipse running!
+ *
+ * @author Eike Stepper
+ */
+public interface CDOPackageTypeRegistry extends IRegistry<String, CDOPackageType>
+{
+ public static final CDOPackageTypeRegistry INSTANCE = org.eclipse.emf.internal.cdo.util.CDOPackageTypeRegistryImpl.INSTANCE;
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index 941624a..c8a6261 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.util;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
-import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
import org.eclipse.emf.internal.cdo.CDOSessionFactory;
@@ -28,7 +27,6 @@ import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.signal.failover.IFailOverStrategy;
-import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.emf.common.notify.Adapter;
@@ -41,18 +39,9 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -61,73 +50,12 @@ import java.util.Map;
*/
public final class CDOUtil
{
- private static Map<String, CDOPackageType> packageTypes;
-
public static final String CDO_VERSION_SUFFIX = "-CDO";
private CDOUtil()
{
}
- /**
- * Can only be used with Eclipse running!
- */
- public static synchronized Map<String, CDOPackageType> getPackageTypes()
- {
- if (packageTypes == null)
- {
- packageTypes = analyzePackageTypes();
- }
-
- return packageTypes;
- }
-
- private static HashMap<String, CDOPackageType> analyzePackageTypes()
- {
- HashMap<String, CDOPackageType> bundles = new HashMap<String, CDOPackageType>();
- HashMap<String, CDOPackageType> result = new HashMap<String, CDOPackageType>();
-
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- String ecoreID = EcorePlugin.getPlugin().getBundle().getSymbolicName();
- String extPoint = EcorePlugin.GENERATED_PACKAGE_PPID;
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(ecoreID, extPoint);
- for (IConfigurationElement element : elements)
- {
- String uri = element.getAttribute("uri");
- if (!StringUtil.isEmpty(uri) && !uri.equals(EresourcePackage.eINSTANCE.getNsURI()))
- {
- String bundleName = element.getContributor().getName();
- CDOPackageType packageType = bundles.get(bundleName);
- if (packageType == null)
- {
- Bundle bundle = Platform.getBundle(bundleName);
- if (bundle.getEntry("META-INF/CDO.MF") != null)
- {
- packageType = CDOPackageType.NATIVE;
- }
- else
- {
- String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
- if (version.endsWith(CDOUtil.CDO_VERSION_SUFFIX))
- {
- packageType = CDOPackageType.CONVERTED;
- }
- else
- {
- packageType = CDOPackageType.LEGACY;
- }
- }
-
- bundles.put(bundleName, packageType);
- }
-
- result.put(uri, packageType);
- }
- }
-
- return result;
- }
-
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects,
boolean automaticPackageRegistry, IFailOverStrategy failOverStrategy) throws ConnectorException
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
index c5f214f..e0626ad 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
@@ -12,6 +12,8 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.internal.cdo.util.CDOPackageRegistryImpl;
+
import org.eclipse.net4j.internal.util.factory.Factory;
import org.eclipse.net4j.signal.failover.IFailOverStrategy;
import org.eclipse.net4j.util.container.IManagedContainer;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
index e7bb4c2..1628c84 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
@@ -38,6 +38,7 @@ import org.eclipse.emf.internal.cdo.protocol.OpenSessionRequest;
import org.eclipse.emf.internal.cdo.protocol.OpenSessionResult;
import org.eclipse.emf.internal.cdo.protocol.QueryObjectTypesRequest;
import org.eclipse.emf.internal.cdo.protocol.ViewsChangedRequest;
+import org.eclipse.emf.internal.cdo.util.CDOPackageRegistryImpl;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
import org.eclipse.emf.internal.cdo.util.ProxyResolverURIResourceMap;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java
index bad9675..fb954f6 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java
@@ -8,21 +8,23 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.emf.internal.cdo;
+package org.eclipse.emf.internal.cdo.util;
import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOPackage;
import org.eclipse.emf.cdo.protocol.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.util.CDOPackageRegistry;
import org.eclipse.emf.cdo.util.CDOPackageType;
-import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
import org.eclipse.emf.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.util.ModelUtil;
+import org.eclipse.net4j.internal.util.container.ContainerEventAdapter;
import org.eclipse.net4j.internal.util.lifecycle.LifecycleEventAdapter;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
@@ -172,8 +174,6 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
*/
public static class SelfPopulating extends CDOPackageRegistryImpl
{
- private final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, SelfPopulating.class);
-
private static final long serialVersionUID = 1L;
private IListener sessionListener = new LifecycleEventAdapter()
@@ -188,6 +188,17 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
protected void onAboutToDeactivate(ILifecycle lifecycle)
{
getSession().removeListener(this);
+ CDOPackageTypeRegistry.INSTANCE.removeListener(typeListener);
+ }
+ };
+
+ private IListener typeListener = new ContainerEventAdapter<Map.Entry<String, CDOPackageType>>()
+ {
+ @Override
+ protected void onAdded(IContainer<java.util.Map.Entry<String, CDOPackageType>> container,
+ java.util.Map.Entry<String, CDOPackageType> entry)
+ {
+ addEntry(entry);
}
};
@@ -199,28 +210,33 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
protected void populate()
{
- Map<String, CDOPackageType> packageTypes = CDOUtil.getPackageTypes();
- for (Map.Entry<String, CDOPackageType> entry : packageTypes.entrySet())
+ for (Map.Entry<String, CDOPackageType> entry : CDOPackageTypeRegistry.INSTANCE.entrySet())
+ {
+ addEntry(entry);
+ }
+
+ CDOPackageTypeRegistry.INSTANCE.addListener(typeListener);
+ }
+
+ protected void addEntry(Map.Entry<String, CDOPackageType> entry)
+ {
+ CDOPackageType packageType = entry.getValue();
+ if (packageType != CDOPackageType.LEGACY)
{
- CDOPackageType packageType = entry.getValue();
- if (packageType != CDOPackageType.LEGACY)
+ String uri = entry.getKey();
+ if (!containsKey(uri))
{
- String uri = entry.getKey();
- if (!containsKey(uri))
+ try
+ {
+ EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(uri);
+ putEPackage(ePackage);
+ }
+ catch (RuntimeException ex)
{
- try
- {
- EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(uri);
- putEPackage(ePackage);
- }
- catch (RuntimeException ex)
- {
- OM.LOG.error(ex);
- }
+ OM.LOG.error(ex);
}
}
}
}
-
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageTypeRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageTypeRegistryImpl.java
new file mode 100644
index 0000000..2efc8dd
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageTypeRegistryImpl.java
@@ -0,0 +1,177 @@
+/***************************************************************************
+ * 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
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.cdo.util.CDOPackageType;
+import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.internal.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IFilter;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public final class CDOPackageTypeRegistryImpl extends HashMapRegistry<String, CDOPackageType> implements
+ CDOPackageTypeRegistry
+{
+ public static final CDOPackageTypeRegistryImpl INSTANCE = new CDOPackageTypeRegistryImpl();
+
+ private static final IExtensionRegistry EXT_REGISTRY = Platform.getExtensionRegistry();
+
+ private static final String EXT_POINT = EcorePlugin.getPlugin().getBundle().getSymbolicName() + "."
+ + EcorePlugin.GENERATED_PACKAGE_PPID;
+
+ private Object extensionTracker;
+
+ private CDOPackageTypeRegistryImpl()
+ {
+ initPackageTypes();
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ if (OMPlatform.INSTANCE.isOSGiRunning())
+ {
+ try
+ {
+ connectExtensionTracker();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.error(t);
+ }
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ if (OMPlatform.INSTANCE.isOSGiRunning())
+ {
+ try
+ {
+ disconnectExtensionTracker();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.error(t);
+ }
+ }
+
+ super.doDeactivate();
+ }
+
+ private void initPackageTypes()
+ {
+ IConfigurationElement[] elements = EXT_REGISTRY.getConfigurationElementsFor(EXT_POINT);
+ addPackageTypes(elements);
+ }
+
+ private void addPackageTypes(IConfigurationElement[] elements)
+ {
+ Map<String, CDOPackageType> bundles = new HashMap<String, CDOPackageType>();
+ for (IConfigurationElement element : elements)
+ {
+ String uri = element.getAttribute("uri");
+ if (!StringUtil.isEmpty(uri) && !uri.equals(EresourcePackage.eINSTANCE.getNsURI()))
+ {
+ String bundleName = element.getContributor().getName();
+ CDOPackageType packageType = bundles.get(bundleName);
+ if (packageType == null)
+ {
+ Bundle bundle = Platform.getBundle(bundleName);
+ if (bundle.getEntry("META-INF/CDO.MF") != null)
+ {
+ packageType = CDOPackageType.NATIVE;
+ }
+ else
+ {
+ String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (version.endsWith(CDOUtil.CDO_VERSION_SUFFIX))
+ {
+ packageType = CDOPackageType.CONVERTED;
+ }
+ else
+ {
+ packageType = CDOPackageType.LEGACY;
+ }
+ }
+
+ bundles.put(bundleName, packageType);
+ }
+
+ put(uri, packageType);
+ }
+ }
+ }
+
+ private void connectExtensionTracker()
+ {
+ ExtensionTracker extensionTracker = new ExtensionTracker();
+ extensionTracker.registerHandler(new IExtensionChangeHandler()
+ {
+ public void addExtension(IExtensionTracker tracker, IExtension extension)
+ {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ addPackageTypes(elements);
+ }
+
+ public void removeExtension(IExtension extension, Object[] objects)
+ {
+ }
+ }, createExtensionPointFilter());
+
+ this.extensionTracker = extensionTracker;
+ }
+
+ private void disconnectExtensionTracker()
+ {
+ ExtensionTracker extensionTracker = (ExtensionTracker)this.extensionTracker;
+ extensionTracker.close();
+ }
+
+ private IFilter createExtensionPointFilter()
+ {
+ final IExtensionPoint xpt = EXT_REGISTRY.getExtensionPoint(EXT_POINT);
+ return new IFilter()
+ {
+ public boolean matches(IExtensionPoint target)
+ {
+ return xpt.equals(target);
+ }
+ };
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
index 03df25a..c05bef1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyPlatform.java
@@ -27,6 +27,11 @@ public class LegacyPlatform extends AbstractPlatform
{
}
+ public boolean isOSGiRunning()
+ {
+ return false;
+ }
+
@Override
protected OMBundle createBundle(String bundleID, Class<?> accessor)
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
index 1b2ae94..a83c568 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiPlatform.java
@@ -40,6 +40,11 @@ public class OSGiPlatform extends AbstractPlatform
}
}
+ public boolean isOSGiRunning()
+ {
+ return true;
+ }
+
@Override
protected OMBundle createBundle(String bundleID, Class<?> accessor)
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
index 62fc0f0..0a54cf9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMPlatform.java
@@ -27,6 +27,8 @@ public interface OMPlatform
public OMBundle bundle(String bundleID, Class<?> accessor);
+ public boolean isOSGiRunning();
+
public boolean isDebugging();
public void setDebugging(boolean debugging);