summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-03 05:23:36 (EDT)
committerEike Stepper2008-05-03 05:23:36 (EDT)
commit51e2386e4b69a3a66a5b0436efc2c7f22e78d441 (patch)
treed17fd35348a7e11d10ff5fb6e84baf9854949d44
parent88292f9084a9b2e3b225ffd1f8ce612ad26b4222 (diff)
downloadcdo-51e2386e4b69a3a66a5b0436efc2c7f22e78d441.zip
cdo-51e2386e4b69a3a66a5b0436efc2c7f22e78d441.tar.gz
cdo-51e2386e4b69a3a66a5b0436efc2c7f22e78d441.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/src/org/eclipse/emf/cdo/util/CDOPackageTypeRegistry.java12
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageTypeRegistryImpl.java146
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java9
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java160
5 files changed, 237 insertions, 102 deletions
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
index f9fd681..e2644fc 100644
--- 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
@@ -12,6 +12,8 @@ package org.eclipse.emf.cdo.util;
import org.eclipse.net4j.util.registry.IRegistry;
+import org.eclipse.emf.ecore.EPackage;
+
/**
* Can only be used with Eclipse running!
*
@@ -20,4 +22,14 @@ import org.eclipse.net4j.util.registry.IRegistry;
public interface CDOPackageTypeRegistry extends IRegistry<String, CDOPackageType>
{
public static final CDOPackageTypeRegistry INSTANCE = org.eclipse.emf.internal.cdo.util.CDOPackageTypeRegistryImpl.INSTANCE;
+
+ public CDOPackageType getPackageType(EPackage ePackage);
+
+ public void register(EPackage ePackage);
+
+ public void registerLegacy(String uri);
+
+ public void registerNative(String uri);
+
+ public void registerConverted(String uri);
}
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
index 1ffba00..4a2fa64 100644
--- 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
@@ -15,12 +15,17 @@ 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.CDOObjectImpl;
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.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -52,12 +57,66 @@ public final class CDOPackageTypeRegistryImpl extends HashMapRegistry<String, CD
private CDOPackageTypeRegistryImpl()
{
- if (!OMPlatform.INSTANCE.isOSGiRunning())
+ if (OMPlatform.INSTANCE.isOSGiRunning())
+ {
+ initPackageTypes();
+ }
+ }
+
+ public CDOPackageType getPackageType(EPackage ePackage)
+ {
+ if (ePackage.getClass() == EPackageImpl.class)
+ {
+ // Dynamic packages can be considered native
+ return CDOPackageType.NATIVE;
+ }
+
+ EPackage topLevelPackage = ModelUtil.getTopLevelPackage(ePackage);
+ EClass eClass = getAnyEClass(topLevelPackage);
+ if (eClass == null)
+ {
+ throw new IllegalArgumentException("ePackage does not contain classes");
+ }
+
+ try
+ {
+ if (isConverted(eClass))
+ {
+ return CDOPackageType.CONVERTED;
+ }
+ }
+ catch (Throwable ignore)
+ {
+ // Legacy system might not be available
+ }
+
+ Class<?> instanceClass = eClass.getInstanceClass();
+ if (CDOObjectImpl.class.isAssignableFrom(instanceClass))
{
- throw new IllegalStateException("OSGi is not running");
+ return CDOPackageType.NATIVE;
}
- initPackageTypes();
+ return CDOPackageType.LEGACY;
+ }
+
+ public void register(EPackage ePackage)
+ {
+ put(ePackage.getNsURI(), getPackageType(ePackage));
+ }
+
+ public void registerLegacy(String uri)
+ {
+ put(uri, CDOPackageType.LEGACY);
+ }
+
+ public void registerNative(String uri)
+ {
+ put(uri, CDOPackageType.NATIVE);
+ }
+
+ public void registerConverted(String uri)
+ {
+ put(uri, CDOPackageType.CONVERTED);
}
@Override
@@ -65,13 +124,16 @@ public final class CDOPackageTypeRegistryImpl extends HashMapRegistry<String, CD
{
super.doActivate();
- try
- {
- connectExtensionTracker();
- }
- catch (Throwable t)
+ if (OMPlatform.INSTANCE.isOSGiRunning())
{
- OM.LOG.error(t);
+ try
+ {
+ connectExtensionTracker();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.error(t);
+ }
}
}
@@ -113,23 +175,7 @@ public final class CDOPackageTypeRegistryImpl extends HashMapRegistry<String, CD
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;
- }
- }
-
+ packageType = getBundleType(bundle);
bundles.put(bundleName, packageType);
}
@@ -138,6 +184,54 @@ public final class CDOPackageTypeRegistryImpl extends HashMapRegistry<String, CD
}
}
+ private CDOPackageType getBundleType(Bundle bundle)
+ {
+ if (bundle.getEntry("META-INF/CDO.MF") != null)
+ {
+ return CDOPackageType.NATIVE;
+ }
+ else
+ {
+ String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (version.endsWith(CDOUtil.CDO_VERSION_SUFFIX))
+ {
+ return CDOPackageType.CONVERTED;
+ }
+ else
+ {
+ return CDOPackageType.LEGACY;
+ }
+ }
+ }
+
+ private EClass getAnyEClass(EPackage ePackage)
+ {
+ for (EClassifier classifier : ePackage.getEClassifiers())
+ {
+ if (classifier instanceof EClass)
+ {
+ return (EClass)classifier;
+ }
+ }
+
+ for (EPackage subpackage : ePackage.getESubpackages())
+ {
+ EClass eClass = getAnyEClass(subpackage);
+ if (eClass != null)
+ {
+ return eClass;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isConverted(EClass eClass)
+ {
+ Class<?> instanceClass = eClass.getInstanceClass();
+ return org.eclipse.emf.ecore.impl.CDOAware.class.isAssignableFrom(instanceClass);
+ }
+
private void connectExtensionTracker()
{
ExtensionTracker extensionTracker = new ExtensionTracker();
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
index 96cff11..8cb7757 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
@@ -38,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @author Eike Stepper
*/
-public abstract class AbstractBundle implements OMBundle
+public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport, OMBundle.TranslationSupport
{
private AbstractPlatform platform;
@@ -100,6 +100,16 @@ public abstract class AbstractBundle implements OMBundle
this.bundleContext = bundleContext;
}
+ public DebugSupport getDebugSupport()
+ {
+ return this;
+ }
+
+ public TranslationSupport getTranslationSupport()
+ {
+ return this;
+ }
+
public boolean isDebugging()
{
if (!platform.isDebugging())
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java
index ce01bef..a491d8c 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.internal.util.om.trace;
import org.eclipse.net4j.internal.util.bundle.AbstractPlatform;
import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMBundle.DebugSupport;
import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent;
import org.eclipse.net4j.util.om.trace.OMTracer;
@@ -39,7 +40,7 @@ public class Tracer implements OMTracer
private Tracer(Tracer parent, String name)
{
- this.bundle = parent.getBundle();
+ bundle = parent.getBundle();
this.parent = parent;
this.name = name;
fullName = parent.getFullName() + "." + name; //$NON-NLS-1$
@@ -67,12 +68,14 @@ public class Tracer implements OMTracer
public boolean isEnabled()
{
- return bundle.isDebugging() && bundle.getDebugOption(fullName, false);
+ DebugSupport debugSupport = bundle.getDebugSupport();
+ return debugSupport.isDebugging() && debugSupport.getDebugOption(fullName, false);
}
public void setEnabled(boolean enabled)
{
- bundle.setDebugOption(fullName, enabled);
+ DebugSupport debugSupport = bundle.getDebugSupport();
+ debugSupport.setDebugOption(fullName, enabled);
}
public void trace(OMTraceHandlerEvent event)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
index dd472d6..91ca5cf 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OMBundle.java
@@ -37,23 +37,7 @@ public interface OMBundle
public OMLogger logger();
- public boolean isDebugging();
-
- public void setDebugging(boolean debugging);
-
- public String getDebugOption(String option);
-
- public void setDebugOption(String option, String value);
-
- public String getDebugOption(String option, String defaultValue);
-
- public boolean getDebugOption(String option, boolean defaultValue);
-
- public void setDebugOption(String option, boolean value);
-
- public int getDebugOption(String option, int defaultValue);
-
- public void setDebugOption(String option, int value);
+ public OMPreferences preferences();
public File getConfigFile();
@@ -61,70 +45,102 @@ public interface OMBundle
public String getStateLocation();
- public OMPreferences preferences();
-
public InputStream getInputStream(String path) throws IOException;
- /**
- * Indicates whether strings should be translated by default.
- *
- * @return <code>true</code> if strings should be translated by default; <code>false</code> otherwise.
- */
- public boolean shouldTranslate();
+ public DebugSupport getDebugSupport();
- /**
- * Sets whether strings should be translated by default.
- *
- * @param shouldTranslate
- * whether strings should be translated by default.
- */
- public void setShouldTranslate(boolean shouldTranslate);
+ public TranslationSupport getTranslationSupport();
/**
- * Returns the string resource associated with the key.
- *
- * @param key
- * the key of the string resource.
- * @return the string resource associated with the key.
+ * @author Eike Stepper
*/
- String getString(String key);
+ public interface DebugSupport
+ {
+ public boolean isDebugging();
- /**
- * Returns the string resource associated with the key.
- *
- * @param key
- * the key of the string resource.
- * @param translate
- * whether the result is to be translated to the current locale.
- * @return the string resource associated with the key.
- */
- String getString(String key, boolean translate);
+ public void setDebugging(boolean debugging);
- /**
- * Returns a string resource associated with the key, and performs substitutions.
- *
- * @param key
- * the key of the string.
- * @param args
- * the message substitutions.
- * @return a string resource associated with the key.
- * @see #getString(String)
- * @see java.text.MessageFormat#format(String, Object...)
- */
- String getString(String key, Object... args);
+ public String getDebugOption(String option);
+
+ public void setDebugOption(String option, String value);
+
+ public String getDebugOption(String option, String defaultValue);
+
+ public boolean getDebugOption(String option, boolean defaultValue);
+
+ public void setDebugOption(String option, boolean value);
+
+ public int getDebugOption(String option, int defaultValue);
+
+ public void setDebugOption(String option, int value);
+ }
/**
- * Returns a string resource associated with the key, and performs substitutions.
- *
- * @param key
- * the key of the string.
- * @param translate
- * whether the result is to be translated to the current locale.
- * @param args
- * the message substitutions.
- * @return a string resource associated with the key.
- * @see #getString(String)
- * @see java.text.MessageFormat#format(String, Object[])
+ * @author Eike Stepper
*/
- String getString(String key, boolean translate, Object... args);
+ public interface TranslationSupport
+ {
+ /**
+ * Indicates whether strings should be translated by default.
+ *
+ * @return <code>true</code> if strings should be translated by default; <code>false</code> otherwise.
+ */
+ public boolean shouldTranslate();
+
+ /**
+ * Sets whether strings should be translated by default.
+ *
+ * @param shouldTranslate
+ * whether strings should be translated by default.
+ */
+ public void setShouldTranslate(boolean shouldTranslate);
+
+ /**
+ * Returns the string resource associated with the key.
+ *
+ * @param key
+ * the key of the string resource.
+ * @return the string resource associated with the key.
+ */
+ String getString(String key);
+
+ /**
+ * Returns the string resource associated with the key.
+ *
+ * @param key
+ * the key of the string resource.
+ * @param translate
+ * whether the result is to be translated to the current locale.
+ * @return the string resource associated with the key.
+ */
+ String getString(String key, boolean translate);
+
+ /**
+ * Returns a string resource associated with the key, and performs substitutions.
+ *
+ * @param key
+ * the key of the string.
+ * @param args
+ * the message substitutions.
+ * @return a string resource associated with the key.
+ * @see #getString(String)
+ * @see java.text.MessageFormat#format(String, Object...)
+ */
+ String getString(String key, Object... args);
+
+ /**
+ * Returns a string resource associated with the key, and performs substitutions.
+ *
+ * @param key
+ * the key of the string.
+ * @param translate
+ * whether the result is to be translated to the current locale.
+ * @param args
+ * the message substitutions.
+ * @return a string resource associated with the key.
+ * @see #getString(String)
+ * @see java.text.MessageFormat#format(String, Object[])
+ */
+ String getString(String key, boolean translate, Object... args);
+ }
}