Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2006-02-16 02:10:00 +0000
committerDJ Houghton2006-02-16 02:10:00 +0000
commit83dc53593d83b80e40b8a874184772cc554f1324 (patch)
tree0479371d88c6d7b4a33b0c4ddd194175022e6df2
parentde3f8e71e580c92124f2844519bc60ab8669680e (diff)
downloadrt.equinox.bundles-83dc53593d83b80e40b8a874184772cc554f1324.tar.gz
rt.equinox.bundles-83dc53593d83b80e40b8a874184772cc554f1324.tar.xz
rt.equinox.bundles-83dc53593d83b80e40b8a874184772cc554f1324.zip
Bug 112856 - Bundles should be able to contribute extension point to other namespacesv20060215a
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java4
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionHandle.java16
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionPointHandle.java10
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElement.java21
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElementHandle.java15
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Contribution.java24
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Extension.java34
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionDelta.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionHandle.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPoint.java13
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPointHandle.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java187
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionsParser.java59
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexChildren.java104
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexElement.java98
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryObjectManager.java209
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java116
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableWriter.java78
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/Activator.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java15
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EquinoxRegistryStrategy.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/OSGIUtils.java7
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryProviderOSGI.java3
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java91
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactoryOSGi.java56
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactorySimple.java40
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IConfigurationElement.java20
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IContributor.java36
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExecutableExtensionFactory.java4
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtension.java20
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionPoint.java20
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionRegistry.java49
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IRegistryProvider.java30
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryFactory.java61
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryUtils.java91
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/ExtensionTracker.java2
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/IFilter.java8
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/IRegistryProvider.java36
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryContributor.java126
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryStrategy.java96
40 files changed, 1312 insertions, 497 deletions
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
index a2f2b447f..4ee794ac0 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
@@ -185,10 +185,10 @@ public class DefaultPreferences extends EclipsePreferences {
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
for (int j = 0; j < elements.length; j++)
if (ELEMENT_INITIALIZER.equals(elements[j].getName())) {
- if (name().equals(elements[j].getNamespace())) {
+ if (name().equals(elements[j].getContributor().getName())) {
if (EclipsePreferences.DEBUG_PREFERENCE_GENERAL) {
IExtension theExtension = elements[j].getDeclaringExtension();
- String extensionNamespace = theExtension.getNamespace();
+ String extensionNamespace = theExtension.getContributor().getName();
Bundle underlyingBundle = PreferencesOSGiUtils.getDefault().getBundle(extensionNamespace);
String ownerName;
if (underlyingBundle != null)
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionHandle.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionHandle.java
index f5eb08378..1dda8b613 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionHandle.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionHandle.java
@@ -21,7 +21,6 @@ import org.eclipse.core.runtime.*;
* @since org.eclipse.equinox.registry 3.2
*/
public class BaseExtensionHandle extends Handle implements IExtension {
- static final BaseExtensionHandle[] EMPTY_ARRAY = new BaseExtensionHandle[0];
public BaseExtensionHandle(IObjectManager objectManager, int id) {
super(objectManager, id);
@@ -35,8 +34,21 @@ public class BaseExtensionHandle extends Handle implements IExtension {
return getExtension().shouldPersist();
}
+ // Method left for backward compatiblity only
public String getNamespace() {
- return getExtension().getNamespaceName();
+ return getContributor().getName();
+ }
+
+ public String getNamespaceIdentifier() {
+ return getExtension().getNamespaceIdentifier();
+ }
+
+ public IContributor getContributor() {
+ return getExtension().getContributor();
+ }
+
+ String getContributorId() {
+ return getExtension().getContributorId();
}
public String getExtensionPointUniqueIdentifier() {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionPointHandle.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionPointHandle.java
index 946d48680..b6ad27bb6 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionPointHandle.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/BaseExtensionPointHandle.java
@@ -23,7 +23,6 @@ import org.eclipse.core.runtime.*;
* @since org.eclipse.equinox.registry 3.2
*/
public class BaseExtensionPointHandle extends Handle implements IExtensionPoint {
- static final BaseExtensionPointHandle[] EMPTY_ARRAY = new BaseExtensionPointHandle[0];
public BaseExtensionPointHandle(IObjectManager objectManager, int id) {
super(objectManager, id);
@@ -33,9 +32,18 @@ public class BaseExtensionPointHandle extends Handle implements IExtensionPoint
return (IExtension[]) objectManager.getHandles(getExtensionPoint().getRawChildren(), RegistryObjectManager.EXTENSION);
}
+ // This method is left for backward compatibility only
public String getNamespace() {
+ return getContributor().getName();
+ }
+
+ public String getNamespaceIdentifier() {
return getExtensionPoint().getNamespace();
}
+
+ public IContributor getContributor() {
+ return getExtensionPoint().getContributor();
+ }
protected boolean shouldPersist() {
return getExtensionPoint().shouldPersist();
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElement.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElement.java
index 0ddd83478..9f973b970 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElement.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElement.java
@@ -12,6 +12,7 @@ package org.eclipse.core.internal.registry;
import java.util.Hashtable;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.osgi.util.NLS;
/**
@@ -35,7 +36,7 @@ public class ConfigurationElement extends RegistryObject {
//The name of the configuration element
private String name;
- //The ID of the namespace owner.
+ //ID of the actual contributor of this element
//This value can be null when the element is loaded from disk and the owner has been uninstalled.
//This happens when the configuration is obtained from a delta containing removed extension.
private String contributorId;
@@ -121,11 +122,11 @@ public class ConfigurationElement extends RegistryObject {
propertiesAndValue = newPropertiesAndValue;
}
- void setNamespaceOwnerId(String namespaceOwnerId) {
- this.contributorId = namespaceOwnerId;
+ void setContributorId(String id) {
+ this.contributorId = id;
}
- protected String getNamespaceOwnerId() {
+ protected String getContributorId() {
return contributorId;
}
@@ -168,8 +169,8 @@ public class ConfigurationElement extends RegistryObject {
parentType = type;
}
- protected String getNamespace() {
- return registry.getNamespace(contributorId);
+ public IContributor getContributor() {
+ return registry.getObjectManager().getContributor(contributorId);
}
protected Object createExecutableExtension(String attributeName) throws CoreException {
@@ -238,10 +239,8 @@ public class ConfigurationElement extends RegistryObject {
}
// create a new instance
- Object result = null;
-
- // check if alternative processing strategy is present
- result = registry.processExecutableExtension(contributorName, contributorId, getNamespace(), className, initData, attributeName, this);
+ RegistryContributor defaultContributor = registry.getObjectManager().getContributor(contributorId);
+ Object result = registry.createExecutableExtension(defaultContributor, className, contributorName);
// Check if we have extension adapter and initialize;
// Make the call even if the initialization string is null
@@ -255,7 +254,7 @@ public class ConfigurationElement extends RegistryObject {
throw ce;
} catch (Exception te) {
// user code caused exception
- throwException(NLS.bind(RegistryMessages.plugin_initObjectError, getNamespace(), className), te);
+ throwException(NLS.bind(RegistryMessages.plugin_initObjectError, getContributor().getName(), className), te);
}
// Deal with executable extension factories.
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElementHandle.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElementHandle.java
index 3f9645b85..0469d8339 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElementHandle.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ConfigurationElementHandle.java
@@ -112,11 +112,18 @@ public class ConfigurationElementHandle extends Handle implements IConfiguration
return getConfigurationElement();
}
+ // Method left for backward compatibility only
public String getNamespace() {
- String result = getConfigurationElement().getNamespace();
- if (result == null)
- return getDeclaringExtension().getNamespace();
- return result;
+ return getContributor().getName();
+ }
+
+ public String getNamespaceIdentifier() {
+ // namespace name is determined by the contributing extension
+ return getDeclaringExtension().getNamespaceIdentifier();
+ }
+
+ public IContributor getContributor() {
+ return getConfigurationElement().getContributor();
}
public boolean isValid() {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Contribution.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Contribution.java
index 7dfdf3210..7d1a8ca3e 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Contribution.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Contribution.java
@@ -22,12 +22,11 @@ public class Contribution implements KeyedElement {
//The registry that owns this object
protected ExtensionRegistry registry;
- // The actual contributor of the contribution.
+ // The actual contributor of the contribution
final protected String contributorId;
- // cached Id of the namespace owner (might be same or different from the contributorId)
- // null if it is not cached yet or no namespace was found during previous cache attempt.
- private String namespaceOwnerId = null;
+ // Value is derived from the contributorId and cached for performance
+ private String defaultNamespace = null;
// indicates if this contribution needs to be saved in the registry cache
protected boolean persist;
@@ -101,21 +100,14 @@ public class Contribution implements KeyedElement {
return results;
}
- public String getNamespace() {
- return registry.getNamespace(contributorId);
+ public String getDefaultNamespace() {
+ if (defaultNamespace == null)
+ defaultNamespace = registry.getObjectManager().getContributor(contributorId).getName();
+ return defaultNamespace;
}
public String toString() {
- return "Contribution: " + contributorId + " in namespace" + getNamespace(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected String getNamespaceOwnerId() {
- // Performance: this function is not called during warm Eclipse startup using cached
- // extension registry, but is called about 45 times per contribution during
- // the "clean" Eclipse start. Cache the result.
- if (namespaceOwnerId == null)
- namespaceOwnerId = registry.getNamespaceOwnerId(contributorId);
- return namespaceOwnerId;
+ return "Contribution: " + contributorId + " in namespace" + getDefaultNamespace(); //$NON-NLS-1$ //$NON-NLS-2$
}
//Implements the KeyedElement interface
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Extension.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Extension.java
index e7e385af4..f2814069c 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Extension.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/Extension.java
@@ -11,6 +11,7 @@
package org.eclipse.core.internal.registry;
import java.lang.ref.SoftReference;
+import org.eclipse.core.runtime.IContributor;
/**
* An object which represents the user-defined extension in a plug-in manifest.
@@ -21,14 +22,15 @@ public class Extension extends RegistryObject {
//Extension simple identifier
private String simpleId;
//The namespace for the extension.
- private String namespaceName;
+ private String namespaceIdentifier;
// Place holder for the label and the extension point. It contains either a String[] or a SoftReference to a String[].
//The array layout is [label, extension point name]
private Object extraInformation;
private static final byte LABEL = 0; //The human readable name of the extension
private static final byte XPT_NAME = 1; // The fully qualified name of the extension point to which this extension is attached to
- private static final int EXTRA_SIZE = 2;
+ private static final byte CONTRIBUTOR_ID = 2; // ID of the actual contributor of this extension
+ private static final int EXTRA_SIZE = 3;
protected Extension(ExtensionRegistry registry, boolean persist) {
super(registry, persist);
@@ -41,7 +43,7 @@ public class Extension extends RegistryObject {
this.simpleId = simpleId;
setRawChildren(children);
setExtraDataOffset(extraData);
- this.namespaceName = namespace;
+ this.namespaceIdentifier = namespace;
}
protected String getExtensionPointIdentifier() {
@@ -53,7 +55,7 @@ public class Extension extends RegistryObject {
}
protected String getUniqueIdentifier() {
- return simpleId == null ? null : this.getNamespaceName() + '.' + simpleId;
+ return simpleId == null ? null : this.getNamespaceIdentifier() + '.' + simpleId;
}
void setExtensionPointIdentifier(String value) {
@@ -94,12 +96,28 @@ public class Extension extends RegistryObject {
((String[]) extraInformation)[LABEL] = value;
}
- public String getNamespaceName() {
- return namespaceName;
+ String getContributorId() {
+ String s = getExtraData()[CONTRIBUTOR_ID];
+ if (s == null)
+ return ""; //$NON-NLS-1$
+ return s;
+ }
+
+ public IContributor getContributor() {
+ return registry.getObjectManager().getContributor(getContributorId());
+ }
+
+ void setContributorId(String value) {
+ ensureExtraInformationType();
+ ((String[]) extraInformation)[CONTRIBUTOR_ID] = value;
+ }
+
+ public String getNamespaceIdentifier() {
+ return namespaceIdentifier;
}
- void setNamespaceName(String value) {
- namespaceName = value;
+ void setNamespaceIdentifier(String value) {
+ namespaceIdentifier = value;
}
public String toString() {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionDelta.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionDelta.java
index a66602512..83d1d7567 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionDelta.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionDelta.java
@@ -55,7 +55,7 @@ public class ExtensionDelta implements IExtensionDelta {
}
public String toString() {
- return "\n\t\t" + getExtensionPoint().getUniqueIdentifier() + " - " + getExtension().getNamespace() + '.' + getExtension().getSimpleIdentifier() + " (" + getKindString(this.getKind()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return "\n\t\t" + getExtensionPoint().getUniqueIdentifier() + " - " + getExtension().getNamespaceIdentifier() + '.' + getExtension().getSimpleIdentifier() + " (" + getKindString(this.getKind()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
public static String getKindString(int kind) {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionHandle.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionHandle.java
index c1046a7db..908e9fa86 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionHandle.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionHandle.java
@@ -21,6 +21,8 @@ package org.eclipse.core.internal.registry;
*/
public class ExtensionHandle extends BaseExtensionHandle {
+ static final ExtensionHandle[] EMPTY_ARRAY = new ExtensionHandle[0];
+
public ExtensionHandle(IObjectManager objectManager, int id) {
super(objectManager, id);
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPoint.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPoint.java
index c883e0189..fe96df5e0 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPoint.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPoint.java
@@ -12,6 +12,7 @@ package org.eclipse.core.internal.registry;
import java.io.File;
import java.lang.ref.SoftReference;
+import org.eclipse.core.runtime.IContributor;
/**
* An object which represents the user-defined extension point in a
@@ -27,8 +28,8 @@ public class ExtensionPoint extends RegistryObject {
private static final byte LABEL = 0; //The human readable name for the extension point
private static final byte SCHEMA = 1; //The schema of the extension point
private static final byte QUALIFIED_NAME = 2; //The fully qualified name of the extension point
- private static final byte NAMESPACE = 3; //The name of the namespace contributing the extension point
- private static final byte CONTRIBUTOR_ID = 4; //The namespace owner contributing the extension point
+ private static final byte NAMESPACE = 3; //The name of the namespace of the extension point
+ private static final byte CONTRIBUTOR_ID = 4; //The ID of the actual contributor of the extension point
private static final int EXTRA_SIZE = 5;
protected ExtensionPoint(ExtensionRegistry registry, boolean persist) {
@@ -94,10 +95,14 @@ public class ExtensionPoint extends RegistryObject {
return getExtraData()[NAMESPACE];
}
- protected String getNamespaceOwnerId() {
+ protected String getContributorId() {
return getExtraData()[CONTRIBUTOR_ID];
}
+ public IContributor getContributor() {
+ return registry.getObjectManager().getContributor(getContributorId());
+ }
+
void setSchema(String value) {
ensureExtraInformationType();
((String[]) extraInformation)[SCHEMA] = value;
@@ -118,7 +123,7 @@ public class ExtensionPoint extends RegistryObject {
((String[]) extraInformation)[NAMESPACE] = value;
}
- void setNamespaceOwnerId(String id) {
+ void setContributorId(String id) {
ensureExtraInformationType();
((String[]) extraInformation)[CONTRIBUTOR_ID] = id;
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPointHandle.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPointHandle.java
index b338eafda..8f8ee9bc0 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPointHandle.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionPointHandle.java
@@ -21,6 +21,8 @@ package org.eclipse.core.internal.registry;
*/
public class ExtensionPointHandle extends BaseExtensionPointHandle {
+ static final ExtensionPointHandle[] EMPTY_ARRAY = new ExtensionPointHandle[0];
+
public ExtensionPointHandle(IObjectManager objectManager, int id) {
super(objectManager, id);
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
index 5b7efadab..0dbf750b4 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
@@ -17,6 +17,7 @@ import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.internal.registry.spi.ConfigurationElementDescription;
import org.eclipse.core.internal.registry.spi.ConfigurationElementAttribute;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.core.runtime.spi.RegistryStrategy;
import org.eclipse.osgi.storagemanager.StorageManager;
import org.eclipse.osgi.util.NLS;
@@ -184,14 +185,9 @@ public class ExtensionRegistry implements IExtensionRegistry {
}
private void basicAdd(Contribution element, boolean link) {
- // ignore anonymous namespaces
- if (element.getNamespace() == null)
- return;
-
registryObjects.addContribution(element);
if (!link)
return;
-
Set affectedNamespaces = addExtensionsAndExtensionPoints(element);
setObjectManagers(affectedNamespaces, registryObjects.createDelegatingObjectManager(registryObjects.getAssociatedObjects(element.getContributorId())));
}
@@ -211,6 +207,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
setObjectManagers(affectedNamespaces, registryObjects.createDelegatingObjectManager(associatedObjects));
registryObjects.removeContribution(contributorId);
+ registryObjects.removeContributor(contributorId);
}
// allow other objects in the registry to use the same lock
@@ -299,16 +296,11 @@ public class ExtensionRegistry implements IExtensionRegistry {
return null;
String namespace = extensionId.substring(0, lastdot);
- String[] contributorIds = getContributorIds(namespace);
- for (int i = 0; i < contributorIds.length; i++) {
- int[] extensions = registryObjects.getExtensionsFrom(contributorIds[i]);
- for (int j = 0; j < extensions.length; j++) {
- Extension ext = (Extension) registryObjects.getObject(extensions[j], RegistryObjectManager.EXTENSION);
- if (extensionId.equals(ext.getUniqueIdentifier()) && registryObjects.getExtensionPointObject(ext.getExtensionPointIdentifier()) != null) {
- return (IExtension) registryObjects.getHandle(extensions[j], RegistryObjectManager.EXTENSION);
- }
- }
-
+ ExtensionHandle[] extensions = registryObjects.getExtensionsFromNamespace(namespace);
+ for (int i = 0; i < extensions.length; i++) {
+ ExtensionHandle suspect = extensions[i];
+ if (extensionId.equals(suspect.getUniqueIdentifier()))
+ return suspect;
}
return null;
}
@@ -375,15 +367,10 @@ public class ExtensionRegistry implements IExtensionRegistry {
* (non-Javadoc)
* @see org.eclipse.core.runtime.IExtensionRegistry#getExtensionPoints(java.lang.String)
*/
- public IExtensionPoint[] getExtensionPoints(String namespace) {
+ public IExtensionPoint[] getExtensionPoints(String namespaceName) {
access.enterRead();
try {
- String[] contributorIds = getContributorIds(namespace);
- IExtensionPoint[] result = ExtensionPointHandle.EMPTY_ARRAY;
- for (int i = 0; i < contributorIds.length; i++) {
- result = (IExtensionPoint[]) concatArrays(result, registryObjects.getHandles(registryObjects.getExtensionPointsFrom(contributorIds[i]), RegistryObjectManager.EXTENSION_POINT));
- }
- return result;
+ return registryObjects.getExtensionPointsFromNamespace(namespaceName);
} finally {
access.exitRead();
}
@@ -393,22 +380,10 @@ public class ExtensionRegistry implements IExtensionRegistry {
* (non-Javadoc)
* @see org.eclipse.core.runtime.IExtensionRegistry#getExtensions(java.lang.String)
*/
- public IExtension[] getExtensions(String namespace) {
+ public IExtension[] getExtensions(String namespaceName) {
access.enterRead();
try {
- String[] contributorIds = getContributorIds(namespace);
- List tmp = new ArrayList();
- for (int i = 0; i < contributorIds.length; i++) {
- Extension[] exts = (Extension[]) registryObjects.getObjects(registryObjects.getExtensionsFrom(contributorIds[i]), RegistryObjectManager.EXTENSION);
- for (int j = 0; j < exts.length; j++) {
- if (registryObjects.getExtensionPointObject(exts[j].getExtensionPointIdentifier()) != null)
- tmp.add(registryObjects.getHandle(exts[j].getObjectId(), RegistryObjectManager.EXTENSION));
- }
- }
- if (tmp.size() == 0)
- return ExtensionHandle.EMPTY_ARRAY;
- IExtension[] result = new IExtension[tmp.size()];
- return (IExtension[]) tmp.toArray(result);
+ return registryObjects.getExtensionsFromNamespace(namespaceName);
} finally {
access.exitRead();
}
@@ -421,15 +396,18 @@ public class ExtensionRegistry implements IExtensionRegistry {
public String[] getNamespaces() {
access.enterRead();
try {
- Set namespaces = registryObjects.getNamespaces();
- String[] result = new String[namespaces.size()];
- return (String[]) namespaces.toArray(result);
+ KeyedElement[] namespaceElements = registryObjects.getNamespacesIndex().elements();
+ String[] namespaceNames = new String[namespaceElements.length];
+ for (int i = 0; i < namespaceElements.length; i++) {
+ namespaceNames[i] = (String) ((RegistryIndexElement) namespaceElements[i]).getKey();
+ }
+ return namespaceNames;
} finally {
access.exitRead();
}
}
- public boolean hasNamespace(String name) {
+ public boolean hasContribution(String name) {
access.enterRead();
try {
return registryObjects.hasContribution(name);
@@ -498,6 +476,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
//Return the affected namespace
private String removeExtension(int extensionId) {
Extension extension = (Extension) registryObjects.getObject(extensionId, RegistryObjectManager.EXTENSION);
+ registryObjects.removeExtensionFromNamespaceIndex(extensionId, extension.getNamespaceIdentifier());
String xptName = extension.getExtensionPointIdentifier();
ExtensionPoint extPoint = registryObjects.getExtensionPointObject(xptName);
if (extPoint == null) {
@@ -522,6 +501,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
private String removeExtensionPoint(int extPoint) {
ExtensionPoint extensionPoint = (ExtensionPoint) registryObjects.getObject(extPoint, RegistryObjectManager.EXTENSION_POINT);
+ registryObjects.removeExtensionPointFromNamespaceIndex(extPoint, extensionPoint.getNamespace());
int[] existingExtensions = extensionPoint.getRawChildren();
if (existingExtensions == null || existingExtensions.length == 0) {
return null;
@@ -583,6 +563,8 @@ public class ExtensionRegistry implements IExtensionRegistry {
theTableReader.setExtraDataFile(cacheStorageManager.lookup(TableReader.EXTRA, false));
theTableReader.setMainDataFile(cacheStorageManager.lookup(TableReader.MAIN, false));
theTableReader.setContributionsFile(cacheStorageManager.lookup(TableReader.CONTRIBUTIONS, false));
+ theTableReader.setContributorsFile(cacheStorageManager.lookup(TableReader.CONTRIBUTORS, false));
+ theTableReader.setNamespacesFile(cacheStorageManager.lookup(TableReader.NAMESPACES, false));
theTableReader.setOrphansFile(cacheStorageManager.lookup(TableReader.ORPHANS, false));
isRegistryFilledFromCache = registryObjects.init(computeTimeStamp());
} catch (IOException e) {
@@ -645,6 +627,8 @@ public class ExtensionRegistry implements IExtensionRegistry {
File mainFile = null;
File extraFile = null;
File contributionsFile = null;
+ File contributorsFile = null;
+ File namespacesFile = null;
File orphansFile = null;
TableWriter theTableWriter = new TableWriter(this);
@@ -654,16 +638,22 @@ public class ExtensionRegistry implements IExtensionRegistry {
cacheStorageManager.lookup(TableReader.MAIN, true);
cacheStorageManager.lookup(TableReader.EXTRA, true);
cacheStorageManager.lookup(TableReader.CONTRIBUTIONS, true);
+ cacheStorageManager.lookup(TableReader.CONTRIBUTORS, true);
+ cacheStorageManager.lookup(TableReader.NAMESPACES, true);
cacheStorageManager.lookup(TableReader.ORPHANS, true);
tableFile = File.createTempFile(TableReader.TABLE, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
mainFile = File.createTempFile(TableReader.MAIN, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
extraFile = File.createTempFile(TableReader.EXTRA, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
contributionsFile = File.createTempFile(TableReader.CONTRIBUTIONS, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
+ contributorsFile = File.createTempFile(TableReader.CONTRIBUTORS, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
+ namespacesFile = File.createTempFile(TableReader.NAMESPACES, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
orphansFile = File.createTempFile(TableReader.ORPHANS, ".new", cacheStorageManager.getBase()); //$NON-NLS-1$
theTableWriter.setTableFile(tableFile);
theTableWriter.setExtraDataFile(extraFile);
theTableWriter.setMainDataFile(mainFile);
theTableWriter.setContributionsFile(contributionsFile);
+ theTableWriter.setContributorsFile(contributorsFile);
+ theTableWriter.setNamespacesFile(namespacesFile);
theTableWriter.setOrphansFile(orphansFile);
} catch (IOException e) {
cacheStorageManager.close();
@@ -671,7 +661,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
}
try {
if (theTableWriter.saveCache(registryObjects, computeTimeStamp()))
- cacheStorageManager.update(new String[] {TableReader.TABLE, TableReader.MAIN, TableReader.EXTRA, TableReader.CONTRIBUTIONS, TableReader.ORPHANS}, new String[] {tableFile.getName(), mainFile.getName(), extraFile.getName(), contributionsFile.getName(), orphansFile.getName()});
+ cacheStorageManager.update(new String[] {TableReader.TABLE, TableReader.MAIN, TableReader.EXTRA, TableReader.CONTRIBUTIONS, TableReader.CONTRIBUTORS, TableReader.NAMESPACES, TableReader.ORPHANS}, new String[] {tableFile.getName(), mainFile.getName(), extraFile.getName(), contributionsFile.getName(), contributorsFile.getName(), namespacesFile.getName(), orphansFile.getName()});
} catch (IOException e) {
//Ignore the exception since we can recompute the cache
}
@@ -777,24 +767,8 @@ public class ExtensionRegistry implements IExtensionRegistry {
return isRegistryFilledFromCache;
}
- public Object processExecutableExtension(String contributorName, String namespaceOwnerId, String namespaceName, String className, Object initData, String propertyName, ConfigurationElement confElement) throws CoreException {
- ConfigurationElementHandle confElementHandle = new ConfigurationElementHandle(getObjectManager(), confElement.getObjectId());
- return strategy.createExecutableExtension(contributorName, namespaceOwnerId, namespaceName, className, initData, propertyName, confElementHandle);
- }
-
- //////////////////////////////////////////////////////////////////////////////////////////
- // Registry namespace resolution
-
- public String getNamespaceOwnerId(String contributorId) {
- return strategy.getNamespaceOwnerId(contributorId);
- }
-
- public String getNamespace(String contributorId) {
- return strategy.getNamespace(contributorId);
- }
-
- public String[] getContributorIds(String namespace) {
- return strategy.getNamespaceContributors(namespace);
+ public Object createExecutableExtension(RegistryContributor defaultContributor, String className, String requestedContributorName) throws CoreException {
+ return strategy.createExecutableExtension(defaultContributor, className, requestedContributorName);
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -898,19 +872,23 @@ public class ExtensionRegistry implements IExtensionRegistry {
return false;
}
- public boolean addContribution(InputStream is, String contributorId, boolean persist, String contributionName, ResourceBundle b, Object key) {
+ public boolean addContribution(InputStream is, IContributor contributor, boolean persist, String contributionName, ResourceBundle translationBundle, Object key) {
if (!checkReadWriteAccess(key, persist))
throw new IllegalArgumentException("Unauthorized access to the ExtensionRegistry.addXMLContribution() method. Check if proper access token is supplied."); //$NON-NLS-1$
if (contributionName == null)
contributionName = ""; //$NON-NLS-1$
- String ownerName = getNamespace(contributorId);
+
+ RegistryContributor internalContributor = (RegistryContributor) contributor;
+ registryObjects.addContributor(internalContributor); // only adds a contributor if it is not already present
+
+ String ownerName = internalContributor.getActualName();
String message = NLS.bind(RegistryMessages.parse_problems, ownerName);
MultiStatus problems = new MultiStatus(RegistryMessages.OWNER_NAME, ExtensionsParser.PARSE_PROBLEM, message, null);
ExtensionsParser parser = new ExtensionsParser(problems, this);
- Contribution contribution = getElementFactory().createContribution(contributorId, persist);
+ Contribution contribution = getElementFactory().createContribution(internalContributor.getActualId(), persist);
try {
- parser.parseManifest(strategy.getXMLParser(), new InputSource(is), contributionName, getObjectManager(), contribution, b);
+ parser.parseManifest(strategy.getXMLParser(), new InputSource(is), contributionName, getObjectManager(), contribution, translationBundle);
if (problems.getSeverity() != IStatus.OK) {
log(problems);
return false;
@@ -950,7 +928,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
*
* @param identifier Id of the extension point. If non-qualified names is supplied,
* it will be converted internally into a fully qualified name
- * @param contributorId ID of the supplier of this contribution
+ * @param contributor the contributor of this extension point
* @param persist indicates if contribution should be stored in the registry cache. If false,
* contribution is not persisted in the registry cache and is lost on Eclipse restart
* @param label display string for the extension point
@@ -962,9 +940,14 @@ public class ExtensionRegistry implements IExtensionRegistry {
* allows non-persisted registry elements to be modified.
* @throws IllegalArgumentException if incorrect token is passed in
*/
- public void addExtensionPoint(String identifier, String contributorId, boolean persist, String label, String schemaReference, Object token) throws IllegalArgumentException {
+ public void addExtensionPoint(String identifier, IContributor contributor, boolean persist, String label, String schemaReference, Object token) throws IllegalArgumentException {
if (!checkReadWriteAccess(token, persist))
throw new IllegalArgumentException("Unauthorized access to the ExtensionRegistry.addExtensionPoint() method. Check if proper access token is supplied."); //$NON-NLS-1$
+
+ RegistryContributor internalContributor = (RegistryContributor) contributor;
+ registryObjects.addContributor(internalContributor); // only adds a contributor if it is not already present
+ String contributorId = internalContributor.getActualId();
+
// Extension point Id might not be null
if (identifier == null) {
String message = NLS.bind(RegistryMessages.create_failedExtensionPoint, label);
@@ -973,24 +956,29 @@ public class ExtensionRegistry implements IExtensionRegistry {
if (schemaReference == null)
schemaReference = ""; //$NON-NLS-1$
- // prepare namespace information
- String namespaceName = getNamespace(contributorId);
- String namespaceOwnerId = getNamespaceOwnerId(contributorId);
-
// addition wraps in a contribution
Contribution contribution = getElementFactory().createContribution(contributorId, persist);
-
ExtensionPoint currentExtPoint = getElementFactory().createExtensionPoint(persist);
- String uniqueId = namespaceName + '.' + identifier;
+
+ String uniqueId;
+ String namespaceName;
+ int simpleIdStart = identifier.lastIndexOf('.');
+ if (simpleIdStart == -1) {
+ namespaceName = contribution.getDefaultNamespace();
+ uniqueId = namespaceName + '.' + identifier;
+ } else {
+ namespaceName = identifier.substring(0, simpleIdStart);
+ uniqueId = identifier;
+ }
currentExtPoint.setUniqueIdentifier(uniqueId);
+ currentExtPoint.setNamespace(namespaceName);
String labelNLS = translate(label, null);
currentExtPoint.setLabel(labelNLS);
currentExtPoint.setSchema(schemaReference);
getObjectManager().addExtensionPoint(currentExtPoint, true);
- currentExtPoint.setNamespace(namespaceName);
- currentExtPoint.setNamespaceOwnerId(namespaceOwnerId);
+ currentExtPoint.setContributorId(contributorId);
// array format: {Number of extension points, Number of extensions, Extension Id}
int[] contributionChildren = new int[3];
@@ -1015,7 +1003,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
*
* @param identifier Id of the extension. If non-qualified name is supplied,
* it will be converted internally into a fully qualified name
- * @param contributorId ID of the supplier of this contribution
+ * @param contributor the contributor of this extension
* @param persist indicates if contribution should be stored in the registry cache. If false,
* contribution is not persisted in the registry cache and is lost on Eclipse restart
* @param label display string for this extension
@@ -1028,33 +1016,46 @@ public class ExtensionRegistry implements IExtensionRegistry {
* allows non-persisted registry elements to be modified.
* @throws IllegalArgumentException if incorrect token is passed in
*/
- public void addExtension(String identifier, String contributorId, boolean persist, String label, String extensionPointId, ConfigurationElementDescription configurationElements, Object token) throws IllegalArgumentException {
+ public void addExtension(String identifier, IContributor contributor, boolean persist, String label, String extensionPointId, ConfigurationElementDescription configurationElements, Object token) throws IllegalArgumentException {
if (!checkReadWriteAccess(token, persist))
throw new IllegalArgumentException("Unauthorized access to the ExtensionRegistry.addExtensionPoint() method. Check if proper access token is supplied."); //$NON-NLS-1$
// prepare namespace information
- String namespaceName = getNamespace(contributorId);
- String namespaceOwnerId = getNamespaceOwnerId(contributorId);
+ RegistryContributor internalContributor = (RegistryContributor) contributor;
+ registryObjects.addContributor(internalContributor); // only adds a contributor if it is not already present
+ String contributorId = internalContributor.getActualId();
// addition wraps in a contribution
Contribution contribution = getElementFactory().createContribution(contributorId, persist);
-
Extension currentExtension = getElementFactory().createExtension(persist);
- currentExtension.setSimpleIdentifier(identifier);
+
+ String simpleId;
+ String namespaceName;
+ int simpleIdStart = identifier.lastIndexOf('.');
+ if (simpleIdStart != -1) {
+ simpleId = identifier.substring(simpleIdStart + 1);
+ namespaceName = identifier.substring(0, simpleIdStart);
+ } else {
+ simpleId = identifier;
+ namespaceName = contribution.getDefaultNamespace();
+ }
+ currentExtension.setSimpleIdentifier(simpleId);
+ currentExtension.setNamespaceIdentifier(namespaceName);
+
String extensionLabelNLS = translate(label, null);
currentExtension.setLabel(extensionLabelNLS);
String targetExtensionPointId;
if (extensionPointId.indexOf('.') == -1) // No dots -> namespace name added at the start
- targetExtensionPointId = namespaceName + '.' + extensionPointId;
+ targetExtensionPointId = contribution.getDefaultNamespace() + '.' + extensionPointId;
else
targetExtensionPointId = extensionPointId;
currentExtension.setExtensionPointIdentifier(targetExtensionPointId);
getObjectManager().add(currentExtension, true);
- createExtensionData(namespaceOwnerId, configurationElements, currentExtension, persist);
+ createExtensionData(contributorId, configurationElements, currentExtension, persist);
- currentExtension.setNamespaceName(namespaceName);
+ currentExtension.setContributorId(contributorId);
int[] contributionChildren = new int[3];
@@ -1067,9 +1068,9 @@ public class ExtensionRegistry implements IExtensionRegistry {
}
// Fill in the actual content of this extension
- private void createExtensionData(String namespaceOwnerId, ConfigurationElementDescription description, RegistryObject parent, boolean persist) {
+ private void createExtensionData(String contributorId, ConfigurationElementDescription description, RegistryObject parent, boolean persist) {
ConfigurationElement currentConfigurationElement = getElementFactory().createConfigurationElement(persist);
- currentConfigurationElement.setNamespaceOwnerId(namespaceOwnerId);
+ currentConfigurationElement.setContributorId(contributorId);
currentConfigurationElement.setName(description.getName());
ConfigurationElementAttribute[] descriptionProperties = description.getAttributes();
@@ -1095,7 +1096,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
ConfigurationElementDescription[] children = description.getChildren();
if (children != null) {
for (int i = 0; i < children.length; i++) {
- createExtensionData(namespaceOwnerId, children[i], currentConfigurationElement, persist);
+ createExtensionData(contributorId, children[i], currentConfigurationElement, persist);
}
}
@@ -1142,17 +1143,7 @@ public class ExtensionRegistry implements IExtensionRegistry {
registryObjects.addNavigableObjects(removed);
getDelta(namespace).setObjectManager(registryObjects.createDelegatingObjectManager(removed));
- String[] possibleContributors = strategy.getNamespaceContributors(namespace);
- for (int i = 0; i < possibleContributors.length; i++) {
- Contribution contribution = registryObjects.getContribution(possibleContributors[i]);
- if (contribution.hasChild(id)) {
- contribution.unlinkChild(id);
- if (contribution.isEmpty())
- registryObjects.removeContribution(possibleContributors[i]);
- break;
- }
- }
-
+ registryObjects.unlinkChildFromContributions(id);
fireRegistryChangeEvent();
} finally {
access.exitWrite();
@@ -1161,7 +1152,9 @@ public class ExtensionRegistry implements IExtensionRegistry {
}
/**
- * This is an experimental function. It <b>will</b> be modified in future.
+ * <strong>EXPERIMENTAL</strong>. This method has been added as part of a work in progress.
+ * There is a guarantee neither that this API will work nor that it will remain the same.
+ * Please do not use this method without consulting with the Equinox team.
*/
public Object getTemporaryUserToken() {
return userToken;
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionsParser.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionsParser.java
index fc7e72e47..6147ad218 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionsParser.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionsParser.java
@@ -15,7 +15,6 @@ import java.io.IOException;
import java.util.*;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.core.internal.registry.osgi.Activator;
import org.eclipse.core.runtime.*;
import org.eclipse.osgi.util.NLS;
import org.xml.sax.*;
@@ -81,7 +80,7 @@ public class ExtensionsParser extends DefaultHandler {
// Keep track of the object encountered.
private RegistryObjectManager objectManager;
- private Contribution namespace;
+ private Contribution contribution;
//This keeps tracks of the value of the configuration element in case the value comes in several pieces (see characters()). See as well bug 75592.
private String configurationElementValue;
@@ -207,7 +206,7 @@ public class ExtensionsParser extends DefaultHandler {
}
extensions.clear();
}
- namespace.setRawChildren(namespaceChildren);
+ contribution.setRawChildren(namespaceChildren);
break;
case BUNDLE_EXTENSION_POINT_STATE :
if (elementName.equals(EXTENSION_POINT)) {
@@ -219,7 +218,9 @@ public class ExtensionsParser extends DefaultHandler {
stateStack.pop();
// Finish up extension object
Extension currentExtension = (Extension) objectStack.pop();
- currentExtension.setNamespaceName(namespace.getNamespace());
+ if (currentExtension.getNamespaceIdentifier() == null)
+ currentExtension.setNamespaceIdentifier(contribution.getDefaultNamespace());
+ currentExtension.setContributorId(contribution.getContributorId());
scratchVectors[EXTENSION_INDEX].add(currentExtension);
}
break;
@@ -279,8 +280,8 @@ public class ExtensionsParser extends DefaultHandler {
configurationElementValue = null;
// create a new Configuration Element and push it onto the object stack
- ConfigurationElement currentConfigurationElement = registry.getElementFactory().createConfigurationElement(namespace.shouldPersist());
- currentConfigurationElement.setNamespaceOwnerId(namespace.getNamespaceOwnerId());
+ ConfigurationElement currentConfigurationElement = registry.getElementFactory().createConfigurationElement(contribution.shouldPersist());
+ currentConfigurationElement.setContributorId(contribution.getContributorId());
objectStack.push(currentConfigurationElement);
currentConfigurationElement.setName(elementName);
@@ -297,7 +298,7 @@ public class ExtensionsParser extends DefaultHandler {
// in compatibility mode, any extraneous elements will be silently ignored
compatibilityMode = attributes.getLength() > 0;
stateStack.push(new Integer(BUNDLE_STATE));
- objectStack.push(namespace);
+ objectStack.push(contribution);
}
private void handleBundleState(String elementName, Attributes attributes) {
@@ -341,7 +342,7 @@ public class ExtensionsParser extends DefaultHandler {
this.resources = bundle;
this.objectManager = registryObjects;
//initialize the parser with this object
- this.namespace = currentNamespace;
+ this.contribution = currentNamespace;
if (registry.debug())
start = System.currentTimeMillis();
@@ -388,7 +389,7 @@ public class ExtensionsParser extends DefaultHandler {
}
private void parseExtensionAttributes(Attributes attributes) {
- Extension currentExtension = registry.getElementFactory().createExtension(namespace.shouldPersist());
+ Extension currentExtension = registry.getElementFactory().createExtension(contribution.shouldPersist());
objectStack.push(currentExtension);
// Process Attributes
@@ -399,13 +400,24 @@ public class ExtensionsParser extends DefaultHandler {
if (attrName.equals(EXTENSION_NAME))
currentExtension.setLabel(translate(attrValue));
- else if (attrName.equals(EXTENSION_ID))
- currentExtension.setSimpleIdentifier(attrValue);
- else if (attrName.equals(EXTENSION_TARGET)) {
+ else if (attrName.equals(EXTENSION_ID)) {
+ String simpleId;
+ String namespaceName;
+ int simpleIdStart = attrValue.lastIndexOf('.');
+ if (simpleIdStart != -1) {
+ simpleId = attrValue.substring(simpleIdStart + 1);
+ namespaceName = attrValue.substring(0, simpleIdStart);
+ } else {
+ simpleId = attrValue;
+ namespaceName = contribution.getDefaultNamespace();
+ }
+ currentExtension.setSimpleIdentifier(simpleId);
+ currentExtension.setNamespaceIdentifier(namespaceName);
+ } else if (attrName.equals(EXTENSION_TARGET)) {
// check if point is specified as a simple or qualified name
String targetName;
if (attrValue.lastIndexOf('.') == -1) {
- String baseId = namespace.getNamespace();
+ String baseId = contribution.getDefaultNamespace();
targetName = baseId + '.' + attrValue;
} else
targetName = attrValue;
@@ -447,7 +459,7 @@ public class ExtensionsParser extends DefaultHandler {
}
private void parseExtensionPointAttributes(Attributes attributes) {
- ExtensionPoint currentExtPoint = registry.getElementFactory().createExtensionPoint(namespace.shouldPersist());
+ ExtensionPoint currentExtPoint = registry.getElementFactory().createExtensionPoint(contribution.shouldPersist());
// Process Attributes
int len = (attributes != null) ? attributes.getLength() : 0;
@@ -458,7 +470,19 @@ public class ExtensionsParser extends DefaultHandler {
if (attrName.equals(EXTENSION_POINT_NAME))
currentExtPoint.setLabel(translate(attrValue));
else if (attrName.equals(EXTENSION_POINT_ID)) {
- currentExtPoint.setUniqueIdentifier(namespace.getNamespace() + '.' + attrValue);
+ String uniqueId;
+ String namespaceName;
+ int simpleIdStart = attrValue.lastIndexOf('.');
+ if (simpleIdStart == -1) {
+ namespaceName = contribution.getDefaultNamespace();
+ uniqueId = namespaceName + '.' + attrValue;
+ } else {
+ namespaceName = attrValue.substring(0, simpleIdStart);
+ uniqueId = attrValue;
+ }
+ currentExtPoint.setUniqueIdentifier(uniqueId);
+ currentExtPoint.setNamespace(namespaceName);
+
} else if (attrName.equals(EXTENSION_POINT_SCHEMA))
currentExtPoint.setSchema(attrValue);
else
@@ -473,8 +497,9 @@ public class ExtensionsParser extends DefaultHandler {
}
objectManager.addExtensionPoint(currentExtPoint, true);
- currentExtPoint.setNamespace(namespace.getNamespace());
- currentExtPoint.setNamespaceOwnerId(namespace.getNamespaceOwnerId());
+ if (currentExtPoint.getNamespace() == null)
+ currentExtPoint.setNamespace(contribution.getDefaultNamespace());
+ currentExtPoint.setContributorId(contribution.getContributorId());
// Now populate the the vector just below us on the objectStack with this extension point
scratchVectors[EXTENSION_POINT_INDEX].add(currentExtPoint);
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexChildren.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexChildren.java
new file mode 100644
index 000000000..705c4574a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexChildren.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.registry;
+
+public class RegistryIndexChildren {
+
+ static final int[] EMPTY_ARRAY = new int[0];
+
+ private int[] children;
+
+ public RegistryIndexChildren() {
+ children = EMPTY_ARRAY;
+ }
+
+ public RegistryIndexChildren(int[] children) {
+ this.children = children;
+ }
+
+ public int[] getChildren() {
+ return children;
+ }
+
+ public int findChild(int id) {
+ for (int i = 0; i < children.length; i++) {
+ if (children[i] == id)
+ return i;
+ }
+ return -1;
+ }
+
+ public boolean unlinkChild(int id) {
+ int index = findChild(id);
+ if (index == -1)
+ return false; // there is no such element
+
+ // copy the array except one element at index
+ int[] result = new int[children.length - 1];
+ System.arraycopy(children, 0, result, 0, index);
+ System.arraycopy(children, index + 1, result, index, children.length - index - 1);
+ children = result;
+ return true;
+ }
+
+ public boolean linkChild(int id) {
+ if (children.length == 0) {
+ children = new int[] {id};
+ return true;
+ }
+
+ // add new element at the end
+ int[] result = new int[children.length + 1];
+ System.arraycopy(children, 0, result, 0, children.length);
+ result[children.length] = id;
+ children = result;
+ return true;
+ }
+
+ public boolean linkChildren(int[] IDs) {
+ if (children.length == 0) {
+ children = IDs;
+ return true;
+ }
+ int[] result = new int[children.length + IDs.length];
+ System.arraycopy(children, 0, result, 0, children.length);
+ System.arraycopy(IDs, 0, result, children.length, IDs.length);
+ children = result;
+ return true;
+ }
+
+ public boolean unlinkChildren(int[] IDs) {
+ if (children.length == 0)
+ return (IDs.length == 0);
+
+ int size = children.length;
+ for (int i = 0; i < IDs.length; i++) {
+ int index = findChild(IDs[i]);
+ if (index != -1) {
+ children[i] = -1;
+ size--;
+ }
+ }
+ if (size == 0) {
+ children = EMPTY_ARRAY;
+ return true;
+ }
+ int[] result = new int[size];
+ int pos = 0;
+ for (int i = 0; i < children.length; i++) {
+ if (children[i] == -1)
+ continue;
+ result[pos] = children[i];
+ pos++;
+ }
+ return true;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexElement.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexElement.java
new file mode 100644
index 000000000..6daf40b8b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryIndexElement.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.registry;
+
+public class RegistryIndexElement implements KeyedElement {
+
+ // The key on which indexing is done
+ final protected String key;
+
+ // Extension points matching the key
+ private RegistryIndexChildren extensionPoints;
+
+ // Extensions matching the key
+ private RegistryIndexChildren extensions;
+
+ public RegistryIndexElement(String key) {
+ this.key = key;
+ }
+
+ public RegistryIndexElement(String key, int[] extensionPoints, int[] extensions) {
+ this.key = key;
+ this.extensionPoints = new RegistryIndexChildren(extensionPoints);
+ this.extensions = new RegistryIndexChildren(extensions);
+ }
+
+ protected int[] getExtensions() {
+ if (extensions == null)
+ return RegistryIndexChildren.EMPTY_ARRAY;
+ return extensions.getChildren();
+ }
+
+ protected int[] getExtensionPoints() {
+ if (extensionPoints == null)
+ return RegistryIndexChildren.EMPTY_ARRAY;
+ return extensionPoints.getChildren();
+ }
+
+ public boolean updateExtension(int id, boolean add) {
+ if (extensions == null)
+ extensions = new RegistryIndexChildren();
+
+ if (add)
+ return extensions.linkChild(id);
+ else
+ return extensions.unlinkChild(id);
+ }
+
+ public boolean updateExtensions(int[] IDs, boolean add) {
+ if (extensions == null)
+ extensions = new RegistryIndexChildren();
+
+ if (add)
+ return extensions.linkChildren(IDs);
+ else
+ return extensions.unlinkChildren(IDs);
+ }
+
+ public boolean updateExtensionPoint(int id, boolean add) {
+ if (extensionPoints == null)
+ extensionPoints = new RegistryIndexChildren();
+
+ if (add)
+ return extensionPoints.linkChild(id);
+ else
+ return extensionPoints.unlinkChild(id);
+ }
+
+ public boolean updateExtensionPoints(int[] IDs, boolean add) {
+ if (extensionPoints == null)
+ extensionPoints = new RegistryIndexChildren();
+
+ if (add)
+ return extensionPoints.linkChildren(IDs);
+ else
+ return extensionPoints.unlinkChildren(IDs);
+ }
+
+ //Implements the KeyedElement interface
+ public int getKeyHashCode() {
+ return getKey().hashCode();
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public boolean compare(KeyedElement other) {
+ return key.equals(((RegistryIndexElement) other).key);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryObjectManager.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryObjectManager.java
index c2bb4b57b..93bd2b7b7 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryObjectManager.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/RegistryObjectManager.java
@@ -13,6 +13,7 @@ package org.eclipse.core.internal.registry;
import java.lang.ref.SoftReference;
import java.util.*;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.spi.RegistryContributor;
/**
* This class manage all the object from the registry but does not deal with their dependencies.
@@ -48,6 +49,10 @@ public class RegistryObjectManager implements IObjectManager {
private KeyedHashSet newContributions; //represents the contributers added during this session.
private Object formerContributions; //represents the contributers encountered in previous sessions. This is loaded lazily.
+ private HashMap contributors; // key: contributor ID; value: contributor name
+ private HashMap removedContributors; // key: contributor ID; value: contributor name
+ private KeyedHashSet namespacesIndex; // registry elements (extension & extensionpoints) indexed by namespaces
+
// Map key: extensionPointFullyQualifiedName, value int[] of orphan extensions.
// The orphan access does not need to be synchronized because the it is protected by the lock in extension registry.
private Object orphanExtensions;
@@ -117,6 +122,79 @@ public class RegistryObjectManager implements IObjectManager {
((Contribution) existingContribution).mergeContribution(contribution);
else
newContributions.add(contribution);
+
+ updateNamespaceIndex(contribution, true);
+ }
+
+ // TODO make ExtensionPoint, Extension provide namespace in a same way (move it to the RegistryObject?)
+ // See if all the registryObjects have the same namespace. If not, return null.
+ // Also can return null if empty array is passed in or objects are of an unexpected type
+ private String findCommonNamespaceIdentifier(RegistryObject[] registryObjects) {
+ String namespaceName = null;
+ for (int i = 0; i < registryObjects.length; i++) {
+ RegistryObject currentObject = registryObjects[i];
+ String tmp = null;
+ if (currentObject instanceof ExtensionPoint)
+ tmp = ((ExtensionPoint) currentObject).getNamespace();
+ else if (currentObject instanceof Extension)
+ tmp = ((Extension) currentObject).getNamespaceIdentifier();
+
+ if (namespaceName == null) {
+ namespaceName = tmp;
+ continue;
+ }
+ if (!namespaceName.equals(tmp)) {
+ return null;
+ }
+ }
+ return namespaceName;
+ }
+
+ synchronized void removeExtensionPointFromNamespaceIndex(int extensionPoint, String namespaceName) {
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ indexElement.updateExtensionPoint(extensionPoint, false);
+ }
+
+ synchronized void removeExtensionFromNamespaceIndex(int extensions, String namespaceName) {
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ indexElement.updateExtension(extensions, false);
+ }
+
+ // Called from a synchronized method
+ private void updateNamespaceIndex(Contribution contribution, boolean added) {
+ // if all extension points are from the same namespace combine them in one block and add them all together
+ int[] contribExtensionPoints = contribution.getExtensionPoints();
+ RegistryObject[] extensionPointObjects = getObjects(contribExtensionPoints, EXTENSION_POINT);
+ String commonExptsNamespace = null;
+ if (contribExtensionPoints.length > 1)
+ commonExptsNamespace = findCommonNamespaceIdentifier(extensionPointObjects);
+ if (commonExptsNamespace != null) {
+ RegistryIndexElement indexElement = getNamespaceIndex(commonExptsNamespace);
+ indexElement.updateExtensionPoints(contribExtensionPoints, added);
+ } else {
+ for (int i = 0; i < contribExtensionPoints.length; i++) {
+ String namespaceName = ((ExtensionPoint) extensionPointObjects[i]).getNamespace();
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ indexElement.updateExtensionPoint(contribExtensionPoints[i], added);
+ }
+ }
+
+ // if all extensions are from the same namespace combine them in one block and add them all together
+ int[] contrExtensions = contribution.getExtensions();
+ RegistryObject[] extensionObjects = getObjects(contrExtensions, EXTENSION);
+ String commonExtNamespace = null;
+ if (contrExtensions.length > 1)
+ commonExtNamespace = findCommonNamespaceIdentifier(extensionObjects);
+ if (commonExtNamespace != null) {
+ RegistryIndexElement indexElement = getNamespaceIndex(commonExtNamespace);
+ indexElement.updateExtensions(contrExtensions, added);
+ } else {
+ for (int i = 0; i < contrExtensions.length; i++) {
+ String namespaceName = ((Extension) extensionObjects[i]).getNamespaceIdentifier();
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ indexElement.updateExtension(contrExtensions[i], added);
+ }
+ }
}
synchronized int[] getExtensionPointsFrom(String id) {
@@ -128,19 +206,6 @@ public class RegistryObjectManager implements IObjectManager {
return ((Contribution) tmp).getExtensionPoints();
}
- synchronized Set getNamespaces() {
- KeyedElement[] formerElts = getFormerContributions().elements();
- KeyedElement[] newElts = newContributions.elements();
- Set tmp = new HashSet(formerElts.length + newElts.length);
- for (int i = 0; i < formerElts.length; i++) {
- tmp.add(((Contribution) formerElts[i]).getNamespace());
- }
- for (int i = 0; i < newElts.length; i++) {
- tmp.add(((Contribution) newElts[i]).getNamespace());
- }
- return tmp;
- }
-
synchronized boolean hasContribution(String id) {
Object result = newContributions.getByKey(id);
if (result == null)
@@ -154,7 +219,7 @@ public class RegistryObjectManager implements IObjectManager {
return new KeyedHashSet(0);
if (formerContributions == null || (result = ((KeyedHashSet) ((formerContributions instanceof SoftReference) ? ((SoftReference) formerContributions).get() : formerContributions))) == null) {
- result = registry.getTableReader().loadNamespaces();
+ result = registry.getTableReader().loadContributions();
formerContributions = new SoftReference(result);
}
return result;
@@ -496,6 +561,71 @@ public class RegistryObjectManager implements IObjectManager {
return new KeyedHashSet[] {newContributions, getFormerContributions()};
}
+ // This method is used internally and by the writer to reach in. Notice that it doesn't
+ // return contributors marked as removed.
+ HashMap getContributors() {
+ if (contributors == null) {
+ if (fromCache == false)
+ contributors = new HashMap();
+ else
+ contributors = registry.getTableReader().loadContributors();
+ }
+ return contributors;
+ }
+
+ synchronized RegistryContributor getContributor(String id) {
+ RegistryContributor contributor = (RegistryContributor) getContributors().get(id);
+ if (contributor != null)
+ return contributor;
+ // check if we have it among removed contributors - potentially
+ // notification of removals might be processed after the contributor
+ // marked as removed:
+ if (removedContributors != null)
+ return (RegistryContributor) removedContributors.get(id);
+ return null;
+ }
+
+ // only adds a contributor if it is not already present in the table
+ synchronized void addContributor(RegistryContributor newContributor) {
+ String key = newContributor.getActualId();
+ if (!getContributors().containsKey(key)) {
+ isDirty = true;
+ if (removedContributors != null)
+ removedContributors.remove(key);
+ getContributors().put(key, newContributor);
+ }
+ }
+
+ synchronized void removeContributor(String id) {
+ isDirty = true;
+ RegistryContributor removed = (RegistryContributor) getContributors().remove(id);
+ if (removed != null) {
+ if (removedContributors == null)
+ removedContributors = new HashMap();
+ removedContributors.put(id, removed);
+ }
+ }
+
+ KeyedHashSet getNamespacesIndex() {
+ if (namespacesIndex == null) {
+ if (fromCache == false)
+ namespacesIndex = new KeyedHashSet(0);
+ else
+ namespacesIndex = registry.getTableReader().loadNamespaces();
+ }
+ return namespacesIndex;
+ }
+
+ // Find or create required index element
+ private RegistryIndexElement getNamespaceIndex(String namespaceName) {
+ RegistryIndexElement indexElement = (RegistryIndexElement) getNamespacesIndex().getByKey(namespaceName);
+ if (indexElement == null) {
+ indexElement = new RegistryIndexElement(namespaceName);
+ namespacesIndex.add(indexElement);
+ }
+ return indexElement;
+ }
+
/**
* Collect all the objects that are removed by this operation and store
* them in a IObjectManager so that they can be accessed from the appropriate
@@ -583,10 +713,51 @@ public class RegistryObjectManager implements IObjectManager {
return registry;
}
- synchronized Contribution getContribution(String id) {
- KeyedElement tmp = newContributions.getByKey(id);
- if (tmp == null)
- tmp = getFormerContributions().getByKey(id);
- return (Contribution) tmp;
+ // Called from a synchronized method only
+ private boolean unlinkChildFromContributions(KeyedElement[] contributions, int id) {
+ for (int i = 0; i < contributions.length; i++) {
+ Contribution candidate = (Contribution) contributions[i];
+ if (candidate == null)
+ continue;
+ if (candidate.hasChild(id)) {
+ candidate.unlinkChild(id);
+ if (candidate.isEmpty())
+ removeContribution(candidate.getContributorId());
+ return true;
+ }
+ }
+ return false;
+ }
+
+ synchronized boolean unlinkChildFromContributions(int id) {
+ if (unlinkChildFromContributions(newContributions.elements, id))
+ return true;
+ return unlinkChildFromContributions(getFormerContributions().elements, id);
+ }
+
+ synchronized public ExtensionPointHandle[] getExtensionPointsFromNamespace(String namespaceName) {
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ int[] namespaceExtensionPoints = indexElement.getExtensionPoints();
+ return (ExtensionPointHandle[]) getHandles(namespaceExtensionPoints, EXTENSION_POINT);
+ }
+
+ static final ExtensionHandle[] EMPTY_EXTENSIONS_ARRAY = new ExtensionHandle[0];
+
+ // This method filters out extensions with no extension point
+ synchronized public ExtensionHandle[] getExtensionsFromNamespace(String namespaceName) {
+ RegistryIndexElement indexElement = getNamespaceIndex(namespaceName);
+ int[] namespaceExtensions = indexElement.getExtensions();
+
+ // filter extensions with no extension point (orphan extensions)
+ List tmp = new ArrayList();
+ Extension[] exts = (Extension[]) getObjects(namespaceExtensions, EXTENSION);
+ for (int i = 0; i < exts.length; i++) {
+ if (getExtensionPointObject(exts[i].getExtensionPointIdentifier()) != null)
+ tmp.add(getHandle(exts[i].getObjectId(), EXTENSION));
+ }
+ if (tmp.size() == 0)
+ return EMPTY_EXTENSIONS_ARRAY;
+ ExtensionHandle[] result = new ExtensionHandle[tmp.size()];
+ return (ExtensionHandle[]) tmp.toArray(result);
}
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java
index 3d9094933..d0113cc27 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableReader.java
@@ -14,6 +14,7 @@ import java.io.*;
import java.util.HashMap;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.osgi.util.NLS;
public class TableReader {
@@ -22,8 +23,9 @@ public class TableReader {
static final int OBJECT = 1;
//The version of the cache
- static final int CACHE_VERSION = 2;
+ static final int CACHE_VERSION = 3;
// Version 1 -> 2: the contributor Ids changed from "long" to "String"
+ // Version 2 -> 3: added namespace index and the table of contributors
//Informations representing the MAIN file
static final String MAIN = ".mainData"; //$NON-NLS-1$
@@ -39,10 +41,18 @@ public class TableReader {
static final String TABLE = ".table"; //$NON-NLS-1$
File tableFile;
- //The namespace file
+ //The contributions file
static final String CONTRIBUTIONS = ".contributions"; //$NON-NLS-1$
File contributionsFile;
+ //The contributor file
+ static final String CONTRIBUTORS = ".contributors"; //$NON-NLS-1$
+ File contributorsFile;
+
+ //The namespace file
+ static final String NAMESPACES = ".namespaces"; //$NON-NLS-1$
+ File namespacesFile;
+
//The orphan file
static final String ORPHANS = ".orphans"; //$NON-NLS-1$
File orphansFile;
@@ -73,6 +83,14 @@ public class TableReader {
contributionsFile = namespace;
}
+ void setContributorsFile(File file) {
+ contributorsFile = file;
+ }
+
+ void setNamespacesFile(File file) {
+ namespacesFile = file;
+ }
+
void setOrphansFile(File orphan) {
orphansFile = orphan;
}
@@ -124,12 +142,30 @@ public class TableReader {
long mainDataFileSize = in.readLong();
long extraDataFileSize = in.readLong();
long contributionsFileSize = in.readLong();
+ long contributorsFileSize = in.readLong();
+ long namespacesFileSize = in.readLong();
long orphansFileSize = in.readLong();
String osStamp = in.readUTF();
String windowsStamp = in.readUTF();
String localeStamp = in.readUTF();
- long timeStamp = registry.computeState();
- return ((expectedTimestamp == 0 || expectedTimestamp == registryStamp) && (installStamp == timeStamp) && (osStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_OS))) && (windowsStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_WS))) && (localeStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_NL))) && mainDataFileSize == mainDataFile.length() && extraDataFileSize == extraDataFile.length() && contributionsFileSize == contributionsFile.length() && orphansFileSize == orphansFile.length());
+
+ boolean validTime = (expectedTimestamp == 0 || expectedTimestamp == registryStamp);
+ boolean validInstall = (installStamp == registry.computeState());
+ boolean validOS = (osStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_OS)));
+ boolean validWS = (windowsStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_WS)));
+ boolean validNL = (localeStamp.equals(RegistryProperties.getProperty(IRegistryConstants.PROP_NL)));
+
+ if (!validTime || !validInstall || !validOS || !validWS || !validNL)
+ return false;
+
+ boolean validMain = (mainDataFileSize == mainDataFile.length());
+ boolean validExtra = (extraDataFileSize == extraDataFile.length());
+ boolean validContrib = (contributionsFileSize == contributionsFile.length());
+ boolean validContributors = (contributorsFileSize == contributorsFile.length());
+ boolean validNamespace = (namespacesFileSize == namespacesFile.length());
+ boolean validOrphan = (orphansFileSize == orphansFile.length());
+
+ return (validMain && validExtra && validContrib && validContributors && validNamespace && validOrphan);
} catch (IOException e) {
log(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, fileError, RegistryMessages.meta_registryCacheInconsistent, e));
return false;
@@ -188,7 +224,7 @@ public class TableReader {
ConfigurationElement ce = basicLoadConfigurationElement(currentStream, namespaceOwnerId);
if (namespaceOwnerId == null)
- namespaceOwnerId = ce.getNamespaceOwnerId();
+ namespaceOwnerId = ce.getContributorId();
int[] children = ce.getRawChildren();
if (depth + 1 > maxDepth)
return ce;
@@ -327,7 +363,7 @@ public class TableReader {
}
private String[] basicLoadExtensionExtraData() throws IOException {
- return new String[] {readStringOrNull(extraInput), readStringOrNull(extraInput)};
+ return new String[] {readStringOrNull(extraInput), readStringOrNull(extraInput), readStringOrNull(extraInput)};
}
public String[] loadExtensionPointExtraData(int offset) {
@@ -355,7 +391,7 @@ public class TableReader {
return result;
}
- public KeyedHashSet loadNamespaces() {
+ public KeyedHashSet loadContributions() {
DataInputStream namespaceInput = null;
try {
synchronized (contributionsFile) {
@@ -384,6 +420,69 @@ public class TableReader {
}
}
+ final static float contributorsLoadFactor = 1.2f; // allocate more memory to avoid resizing
+
+ public HashMap loadContributors() {
+ HashMap result = null;
+ DataInputStream contributorsInput = null;
+ try {
+ synchronized (contributorsFile) {
+ contributorsInput = new DataInputStream(new BufferedInputStream(new FileInputStream(contributorsFile)));
+ int size = contributorsInput.readInt();
+ result = new HashMap((int) (size * contributorsLoadFactor));
+ for (int i = 0; i < size; i++) {
+ String id = readStringOrNull(contributorsInput);
+ String name = readStringOrNull(contributorsInput);
+ String hostId = readStringOrNull(contributorsInput);
+ String hostName = readStringOrNull(contributorsInput);
+ result.put(id, new RegistryContributor(id, name, hostId, hostName));
+ }
+ }
+ return result;
+ } catch (IOException e) {
+ String message = NLS.bind(RegistryMessages.meta_regCacheIOExceptionReading, contributorsFile);
+ log(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, fileError, message, e));
+ return null;
+ } finally {
+ if (contributorsInput != null)
+ try {
+ contributorsInput.close();
+ } catch (IOException e1) {
+ //Ignore
+ }
+ }
+ }
+
+ public KeyedHashSet loadNamespaces() {
+ DataInputStream namespaceInput = null;
+ try {
+ synchronized (namespacesFile) {
+ namespaceInput = new DataInputStream(new BufferedInputStream(new FileInputStream(namespacesFile)));
+ int size = namespaceInput.readInt();
+ KeyedHashSet result = new KeyedHashSet(size);
+ for (int i = 0; i < size; i++) {
+ String key = readStringOrNull(namespaceInput);
+ RegistryIndexElement indexElement = new RegistryIndexElement(key);
+ indexElement.updateExtensionPoints(readArray(namespaceInput), true);
+ indexElement.updateExtensions(readArray(namespaceInput), true);
+ result.add(indexElement);
+ }
+ return result;
+ }
+ } catch (IOException e) {
+ String message = NLS.bind(RegistryMessages.meta_regCacheIOExceptionReading, namespacesFile);
+ log(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, fileError, message, e));
+ return null;
+ } finally {
+ if (namespaceInput != null)
+ try {
+ namespaceInput.close();
+ } catch (IOException e1) {
+ //Ignore
+ }
+ }
+ }
+
private void loadAllOrphans(RegistryObjectManager objectManager) throws IOException {
//Read the extensions and configuration elements of the orphans
int orphans = objectManager.getOrphanExtensions().size();
@@ -441,7 +540,7 @@ public class TableReader {
xpt.setSchema(tmp[1]);
xpt.setUniqueIdentifier(tmp[2]);
xpt.setNamespace(tmp[3]);
- xpt.setNamespaceOwnerId(tmp[4]);
+ xpt.setContributorId(tmp[4]);
return xpt;
}
@@ -451,6 +550,7 @@ public class TableReader {
tmp = basicLoadExtensionExtraData();
loaded.setLabel(tmp[0]);
loaded.setExtensionPointIdentifier(tmp[1]);
+ loaded.setContributorId(tmp[2]);
objectManager.add(loaded, holdObjects);
return loaded;
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableWriter.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableWriter.java
index ca530ec10..3699d5129 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableWriter.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/TableWriter.java
@@ -13,6 +13,7 @@ package org.eclipse.core.internal.registry;
import java.io.*;
import java.util.*;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.spi.RegistryContributor;
public class TableWriter {
private static final byte fileError = 0;
@@ -21,6 +22,8 @@ public class TableWriter {
File extraDataFile;
File tableFile;
File contributionsFile;
+ File contributorsFile;
+ File namespacesFile;
File orphansFile;
void setMainDataFile(File main) {
@@ -39,6 +42,14 @@ public class TableWriter {
contributionsFile = fileName;
}
+ void setContributorsFile(File fileName) {
+ contributorsFile = fileName;
+ }
+
+ void setNamespacesFile(File fileName) {
+ namespacesFile = fileName;
+ }
+
void setOrphansFile(File orphan) {
orphansFile = orphan;
}
@@ -132,12 +143,14 @@ public class TableWriter {
saveExtensionPoint(points[i]);
}
saveOrphans();
- saveNamespaces(objectManager.getContributions());
+ saveContributions(objectManager.getContributions());
+ saveContributors(objectManager.getContributors());
+ saveNamespaces(objectManager.getNamespacesIndex());
closeFiles(); //Close the files here so we can write the appropriate size information in the table file.
saveTables(timestamp); //Write the table last so if that is something went wrong we can know
}
- private void saveNamespaces(KeyedHashSet[] contributions) throws IOException {
+ private void saveContributions(KeyedHashSet[] contributions) throws IOException {
FileOutputStream fosNamespace = new FileOutputStream(contributionsFile);
DataOutputStream outputNamespace = new DataOutputStream(new BufferedOutputStream(fosNamespace));
KeyedElement[] newElements = contributions[0].elements();
@@ -174,6 +187,56 @@ public class TableWriter {
outputNamespace.close();
}
+ private void saveNamespaces(KeyedHashSet namespacesIndex) throws IOException {
+ FileOutputStream fosNamespace = new FileOutputStream(namespacesFile);
+ DataOutputStream outputNamespace = new DataOutputStream(new BufferedOutputStream(fosNamespace));
+ KeyedElement[] elements = namespacesIndex.elements();
+
+ KeyedElement[] cachedElements = new KeyedElement[elements.length];
+ int cacheSize = 0;
+ for (int i = 0; i < elements.length; i++) {
+ RegistryIndexElement element = (RegistryIndexElement) elements[i];
+ int[] extensionPoints = filter(element.getExtensionPoints());
+ int[] extensions = filter(element.getExtensions());
+ if (extensionPoints.length == 0 && extensions.length == 0)
+ continue;
+ RegistryIndexElement cachedElement = new RegistryIndexElement((String) element.getKey(), extensionPoints, extensions);
+ cachedElements[cacheSize] = cachedElement;
+ cacheSize++;
+ }
+
+ outputNamespace.writeInt(cacheSize);
+ for (int i = 0; i < cacheSize; i++) {
+ RegistryIndexElement element = (RegistryIndexElement) cachedElements[i];
+ writeStringOrNull((String) element.getKey(), outputNamespace);
+ saveArray(element.getExtensionPoints(), outputNamespace); // it was pre-filtered as we counted the number of elements
+ saveArray(element.getExtensions(), outputNamespace); // it was pre-filtered as we counted the number of elements
+ }
+ outputNamespace.flush();
+ fosNamespace.getFD().sync();
+ outputNamespace.close();
+ }
+
+ private void saveContributors(HashMap contributors) throws IOException {
+ FileOutputStream fosContributors = new FileOutputStream(contributorsFile);
+ DataOutputStream outputContributors = new DataOutputStream(new BufferedOutputStream(fosContributors));
+
+ Collection entries = contributors.values();
+ outputContributors.writeInt(entries.size());
+
+ for (Iterator i = entries.iterator(); i.hasNext();) {
+ RegistryContributor contributor = (RegistryContributor) i.next();
+ writeStringOrNull(contributor.getActualId(), outputContributors);
+ writeStringOrNull(contributor.getActualName(), outputContributors);
+ writeStringOrNull(contributor.getId(), outputContributors);
+ writeStringOrNull(contributor.getName(), outputContributors);
+ }
+
+ outputContributors.flush();
+ fosContributors.getFD().sync();
+ outputContributors.close();
+ }
+
private void saveTables(long registryTimeStamp) throws IOException {
FileOutputStream fosTable = new FileOutputStream(tableFile);
DataOutputStream outputTable = new DataOutputStream(new BufferedOutputStream(fosTable));
@@ -193,6 +256,8 @@ public class TableWriter {
output.writeLong(mainDataFile.length());
output.writeLong(extraDataFile.length());
output.writeLong(contributionsFile.length());
+ output.writeLong(contributorsFile.length());
+ output.writeLong(namespacesFile.length());
output.writeLong(orphansFile.length());
output.writeUTF(RegistryProperties.getProperty(IRegistryConstants.PROP_OS));
output.writeUTF(RegistryProperties.getProperty(IRegistryConstants.PROP_WS));
@@ -230,7 +295,7 @@ public class TableWriter {
offsets.put(ext.getId(), outputStream.size());
outputStream.writeInt(ext.getId());
writeStringOrNull(ext.getSimpleIdentifier(), outputStream);
- writeStringOrNull(ext.getNamespace(), outputStream);
+ writeStringOrNull(ext.getNamespaceIdentifier(), outputStream);
saveArray(filter(ext.getObject().getRawChildren()), outputStream);
outputStream.writeInt(getExtraDataPosition());
saveExtensionData(ext);
@@ -256,7 +321,7 @@ public class TableWriter {
currentOutput.writeInt(element.getId());
ConfigurationElement actualCe = (ConfigurationElement) element.getObject();
- writeStringOrNull(actualCe.getNamespaceOwnerId(), currentOutput);
+ writeStringOrNull(actualCe.getContributorId(), currentOutput);
writeStringOrNull(actualCe.getName(), currentOutput);
currentOutput.writeInt(actualCe.parentId);
currentOutput.writeByte(actualCe.parentType);
@@ -300,13 +365,14 @@ public class TableWriter {
writeStringOrNull(xpt.getLabel(), extraOutput);
writeStringOrNull(xpt.getSchemaReference(), extraOutput);
writeStringOrNull(xpt.getUniqueIdentifier(), extraOutput);
- writeStringOrNull(xpt.getNamespace(), extraOutput);
- writeStringOrNull(((ExtensionPoint) xpt.getObject()).getNamespaceOwnerId(), extraOutput);
+ writeStringOrNull(xpt.getNamespaceIdentifier(), extraOutput);
+ writeStringOrNull(((ExtensionPoint) xpt.getObject()).getContributorId(), extraOutput);
}
private void saveExtensionData(ExtensionHandle extension) throws IOException {
writeStringOrNull(extension.getLabel(), extraOutput);
writeStringOrNull(extension.getExtensionPointUniqueIdentifier(), extraOutput);
+ writeStringOrNull(extension.getContributorId(), extraOutput);
}
private void writeStringOrNull(String string, DataOutputStream out) throws IOException {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/Activator.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/Activator.java
index a47c096d7..0fea3b049 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/Activator.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/Activator.java
@@ -110,7 +110,7 @@ public class Activator implements BundleActivator {
registryRegistration = Activator.getContext().registerService(IExtensionRegistry.class.getName(), defaultRegistry, new Hashtable());
defaultProvider = new RegistryProviderOSGI();
// Set the registry provider and specify this as a default registry:
- RegistryUtils.setRegistryProvider(defaultProvider);
+ RegistryFactory.setDefaultRegistryProvider(defaultProvider);
}
private void stopRegistry() {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
index 3eb79df05..482cffcfb 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
@@ -87,14 +87,14 @@ public class EclipseBundleListener implements SynchronousBundleListener {
}
private void removeBundle(Bundle bundle) {
- registry.remove(RegistryUtils.getContributorId(bundle));
+ registry.remove(Long.toString(bundle.getBundleId()));
}
private void addBundle(Bundle bundle) {
- String contributorId = RegistryUtils.getContributorId(bundle);
+ String contributorId = Long.toString(bundle.getBundleId());
// if the given bundle already exists in the registry then return.
// note that this does not work for update cases.
- if (registry.hasNamespace(contributorId))
+ if (registry.hasContribution(contributorId))
return;
// bail out if system bundle
if (bundle.getBundleId() == 0)
@@ -127,14 +127,15 @@ public class EclipseBundleListener implements SynchronousBundleListener {
if (is == null)
return;
- ResourceBundle b = null;
+ ResourceBundle translationBundle = null;
try {
- b = ResourceTranslator.getResourceBundle(bundle);
+ translationBundle = ResourceTranslator.getResourceBundle(bundle);
} catch (MissingResourceException e) {
//Ignore the exception
}
-
- registry.addContribution(is, contributorId, true, manifestName, b, token);
+
+ IContributor contributor = ContributorFactoryOSGi.createContributor(bundle);
+ registry.addContribution(is, contributor, true, manifestName, translationBundle, token);
// bug 70941
// need to ensure we can find resource bundles from fragments
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EquinoxRegistryStrategy.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EquinoxRegistryStrategy.java
index 5e53d59ba..907f88c70 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EquinoxRegistryStrategy.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EquinoxRegistryStrategy.java
@@ -24,7 +24,7 @@ import org.eclipse.osgi.service.resolver.PlatformAdmin;
* - Use Eclipse platform state for cache validation
* - Supplied alternative cache location (primarily used with shared installs)
*
- * @since org.eclipse.equinox.registry 1.0
+ * @since org.eclipse.equinox.registry 3.2
*/
public class EquinoxRegistryStrategy extends RegistryStrategyOSGI {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/OSGIUtils.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/OSGIUtils.java
index d1af544ca..64e9386a2 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/OSGIUtils.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/OSGIUtils.java
@@ -25,7 +25,7 @@ import org.osgi.util.tracker.ServiceTracker;
* The class contains a set of helper methods for the runtime content plugin.
* The closeServices() method should be called before the plugin is stopped.
*
- * @since org.eclipse.equinox.registry 1.0
+ * @since org.eclipse.equinox.registry 3.2
*/
public class OSGIUtils {
private ServiceTracker debugTracker = null;
@@ -160,10 +160,9 @@ public class OSGIUtils {
}
public Location getConfigurationLocation() {
- if (configurationLocationTracker != null)
- return (Location) configurationLocationTracker.getService();
- else
+ if (configurationLocationTracker == null)
return null;
+ return (Location) configurationLocationTracker.getService();
}
public PlatformAdmin getPlatformAdmin() {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryProviderOSGI.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryProviderOSGI.java
index 3b46dfe7f..564d0ebee 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryProviderOSGI.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryProviderOSGI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2006 IBM Corporation 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
@@ -13,6 +13,7 @@ package org.eclipse.core.internal.registry.osgi;
import org.eclipse.core.internal.registry.RegistryMessages;
import org.eclipse.core.internal.runtime.RuntimeLog;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.spi.IRegistryProvider;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
index 0722f8daa..fbc03f847 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/RegistryStrategyOSGI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation 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
@@ -22,6 +22,7 @@ import org.eclipse.core.internal.runtime.ResourceTranslator;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.core.runtime.spi.RegistryStrategy;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
@@ -40,7 +41,7 @@ import org.osgi.util.tracker.ServiceTracker;
* - XML parser is obtained via an OSGi service
*
* @see RegistryFactory#setRegistryProvider(IRegistryProvider)
- * @since org.eclipse.equinox.registry 1.0
+ * @since org.eclipse.equinox.registry 3.2
*/
public class RegistryStrategyOSGI extends RegistryStrategy {
@@ -80,7 +81,7 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
return false; // Clients are not allowed to add information into this registry
}
- public final String translate(String key, ResourceBundle resources) {
+ public String translate(String key, ResourceBundle resources) {
return ResourceTranslator.getResourceString(null, key, resources);
}
@@ -118,7 +119,7 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
}
}
- public final void scheduleChangeEvent(Object[] listeners, Map deltas, Object registry) {
+ public void scheduleChangeEvent(Object[] listeners, Map deltas, Object registry) {
new ExtensionEventDispatcherJob(listeners, deltas, registry).schedule();
}
@@ -148,7 +149,7 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
private ReferenceMap bundleMap = new ReferenceMap(ReferenceMap.SOFT, DEFAULT_BUNDLECACHE_SIZE, DEFAULT_BUNDLECACHE_LOADFACTOR);
// String Id to OSGi Bundle conversion
- public Bundle getBundle(String id) {
+ private Bundle getBundle(String id) {
if (id == null)
return null;
long OSGiId;
@@ -168,80 +169,24 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
return bundle;
}
- // Getting String Id from an OSGi Bundle
- static public String getId(Bundle bundle) {
- if (bundle == null)
- return null;
- return Long.toString(bundle.getBundleId());
- }
-
- private Bundle getNamespaceBundle(String contributingBundleId) {
- Bundle contributingBundle = getBundle(contributingBundleId);
- if (contributingBundle == null) // When restored from disk the underlying bundle may have been uninstalled
- throw new IllegalStateException("Internal error in extension registry. The bundle corresponding to this contribution has been uninstalled."); //$NON-NLS-1$
- if (OSGIUtils.getDefault().isFragment(contributingBundle)) {
- Bundle[] hosts = OSGIUtils.getDefault().getHosts(contributingBundle);
- if (hosts != null)
- return hosts[0];
- }
- return contributingBundle;
- }
-
- public String getNamespaceOwnerId(String contributorId) {
- if (contributorId == null)
- return null;
- Bundle namespaceBundle = getNamespaceBundle(contributorId);
- return getId(namespaceBundle);
- }
-
- public String getNamespace(String contributorId) {
- if (contributorId == null)
- return null;
- Bundle namespaceBundle = getNamespaceBundle(contributorId);
- if (namespaceBundle == null)
- return null;
- return namespaceBundle.getSymbolicName();
- }
-
- public String[] getNamespaceContributors(String namespace) {
- Bundle correspondingHost = OSGIUtils.getDefault().getBundle(namespace);
- if (correspondingHost == null)
- return new String[0];
- Bundle[] fragments = OSGIUtils.getDefault().getFragments(correspondingHost);
- if (fragments == null)
- return new String[] {getId(correspondingHost)};
- String[] result = new String[fragments.length + 1];
- for (int i = 0; i < fragments.length; i++) {
- result[i] = getId(fragments[i]);
- }
- result[fragments.length] = getId(correspondingHost);
- return result;
- }
-
/////////////////////////////////////////////////////////////////////////////////////
// Executable extensions: bundle-based class loading
- public Object createExecutableExtension(String pluginName, String namespaceOwnerId, String namespaceName, String className, Object initData, String propertyName, org.eclipse.core.runtime.IConfigurationElement confElement) throws CoreException {
+ public Object createExecutableExtension(RegistryContributor contributor, String className, String overridenContributorName) throws CoreException {
+ Bundle contributingBundle;
+ if (overridenContributorName != null && !overridenContributorName.equals("")) //$NON-NLS-1$
+ contributingBundle = OSGIUtils.getDefault().getBundle(overridenContributorName);
+ else
+ contributingBundle = getBundle(contributor.getId());
- if (pluginName != null && !pluginName.equals("") && !pluginName.equals(namespaceName)) { //$NON-NLS-1$
- Bundle otherBundle = null;
- otherBundle = OSGIUtils.getDefault().getBundle(pluginName);
- return createExecutableExtension(otherBundle, className, initData, propertyName, confElement);
- }
-
- Bundle contributingBundle = getBundle(namespaceOwnerId);
- return createExecutableExtension(contributingBundle, className, initData, propertyName, confElement);
- }
-
- private Object createExecutableExtension(Bundle bundle, String className, Object initData, String propertyName, org.eclipse.core.runtime.IConfigurationElement confElement) throws CoreException {
- // load the requested class from this plugin
+ // load the requested class from this bundle
Class classInstance = null;
try {
- classInstance = bundle.loadClass(className);
+ classInstance = contributingBundle.loadClass(className);
} catch (Exception e1) {
- throwException(NLS.bind(RegistryMessages.plugin_loadClassError, bundle.getSymbolicName(), className), e1);
+ throwException(NLS.bind(RegistryMessages.plugin_loadClassError, contributingBundle.getSymbolicName(), className), e1);
} catch (LinkageError e) {
- throwException(NLS.bind(RegistryMessages.plugin_loadClassError, bundle.getSymbolicName(), className), e);
+ throwException(NLS.bind(RegistryMessages.plugin_loadClassError, contributingBundle.getSymbolicName(), className), e);
}
// create a new instance
@@ -249,9 +194,8 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
try {
result = classInstance.newInstance();
} catch (Exception e) {
- throwException(NLS.bind(RegistryMessages.plugin_instantiateClassError, bundle.getSymbolicName(), className), e);
+ throwException(NLS.bind(RegistryMessages.plugin_instantiateClassError, contributingBundle.getSymbolicName(), className), e);
}
-
return result;
}
@@ -340,5 +284,4 @@ public class RegistryStrategyOSGI extends RegistryStrategy {
}
return (SAXParserFactory) xmlTracker.getService();
}
-
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactoryOSGi.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactoryOSGi.java
new file mode 100644
index 000000000..d6b2b4d42
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactoryOSGi.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.runtime;
+
+import org.eclipse.core.internal.registry.osgi.OSGIUtils;
+import org.eclipse.core.runtime.spi.RegistryContributor;
+import org.osgi.framework.Bundle;
+
+/**
+ * The contributor factory creates new registry contributors for use in OSGi-based
+ * registries.
+ * <p>
+ * This class can not be extended or instantiated by clients.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @since org.eclipse.equinox.registry 3.2
+ */
+public final class ContributorFactoryOSGi {
+
+ /**
+ * Creates registry contributor object based on a Bundle.
+ * @param contributor bundle associated with the contribution
+ * @return new registry contributor based on the Bundle
+ */
+ public static IContributor createContributor(Bundle contributor) {
+ String id = Long.toString(contributor.getBundleId());
+ String name = contributor.getSymbolicName();
+ String hostId = null;
+ String hostName = null;
+
+ // determine host properties, if any
+ if (OSGIUtils.getDefault().isFragment(contributor)) {
+ Bundle[] hosts = OSGIUtils.getDefault().getHosts(contributor);
+ if (hosts != null) {
+ Bundle hostBundle = hosts[0];
+ hostId = Long.toString(hostBundle.getBundleId());
+ hostName = hostBundle.getSymbolicName();
+ }
+ }
+
+ return new RegistryContributor(id, name, hostId, hostName);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactorySimple.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactorySimple.java
new file mode 100644
index 000000000..11100b0de
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/ContributorFactorySimple.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.runtime;
+
+import org.eclipse.core.runtime.spi.RegistryContributor;
+
+/**
+ * The contributor factory creates new registry contributors for use in a simple
+ * registry based on the String representation of the determining object.
+ * <p>
+ * This class can not be extended or instantiated by clients.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @since org.eclipse.equinox.registry 3.2
+ */
+public final class ContributorFactorySimple {
+
+ /**
+ * Creates registry contributor object based on a determining object.
+ * @param determiningObject object associated with the contribution
+ * @return new registry contributor based on the determining object
+ */
+ public static IContributor createContributor(Object determiningObject) {
+ String id = determiningObject.toString();
+ return new RegistryContributor(id, id, null, null);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IConfigurationElement.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IConfigurationElement.java
index 648a0be7a..d20ba072e 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IConfigurationElement.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IConfigurationElement.java
@@ -275,9 +275,29 @@ public interface IConfigurationElement {
* @throws InvalidRegistryObjectException if this configuration element is no longer valid
* @see IExtensionRegistry
* @since 3.1
+ *
+ * @deprecated As namespace is no longer restricted to the contributor name,
+ * use {@link #getNamespaceIdentifier()} to obtain namespace name or {@link #getContributor()}
+ * to get the name of the contributor of this registry element
*/
public String getNamespace() throws InvalidRegistryObjectException;
+ /**
+ * Returns the namespace name for this configuration element.
+ * @return the namespace name for this configuration element
+ * @throws InvalidRegistryObjectException if this configuration element is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public String getNamespaceIdentifier() throws InvalidRegistryObjectException;
+
+ /**
+ * Returns the contributor of the configuration element.
+ * @return the contributor for this configuration element
+ * @throws InvalidRegistryObjectException if this configuration element is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public IContributor getContributor() throws InvalidRegistryObjectException;
+
/* (non-javadoc)
* @see Object#equals(java.lang.Object)
*/
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IContributor.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IContributor.java
new file mode 100644
index 000000000..be72cb512
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IContributor.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.runtime;
+
+/**
+ * This interface describes a registry contributor - an entity that supplies information
+ * to the extension registry.
+ * <p>
+ * A registry contributor objects can be obtained by calling {@link IExtensionPoint#getContributor()},
+ * {@link IExtension#getContributor()}, and {@link IConfigurationElement#getContributor()}.
+ * Alternatively, a contributor factory appropriate for the registry in use can be called to directly
+ * obtain an IContributor object.
+ * </p><p>
+ * This interface is not intended to be implemented or extended by clients.
+ * </p>
+ * @see org.eclipse.core.runtime.ContributorFactoryOSGi
+ * @see org.eclipse.core.runtime.ContributorFactorySimple
+ *
+ * @since org.eclipse.equinox.registry 3.2
+ */
+public interface IContributor {
+
+ /**
+ * Provides name of the contributor (e.g., "org.eclipse.core.runtime").
+ * @return name of the registry contributor
+ */
+ public String getName();
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExecutableExtensionFactory.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExecutableExtensionFactory.java
index f8f858033..d54527bcb 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExecutableExtensionFactory.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExecutableExtensionFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation 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
@@ -32,9 +32,7 @@ import org.eclipse.core.runtime.CoreException;
* Given that factories are instantiated as executable extensions, they must provide a 0-argument public constructor.
* Like any other executable extension, they can configured by implementing {@link org.eclipse.core.runtime.IExecutableExtension} interface.
* </p>
- *
* @see org.eclipse.core.runtime.IConfigurationElement
- * @since org.eclipse.equinox.registry 1.0
*/
public interface IExecutableExtensionFactory {
/**
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtension.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtension.java
index 9a12b3bf1..00ccf4bfc 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtension.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtension.java
@@ -61,10 +61,30 @@ public interface IExtension {
* @throws InvalidRegistryObjectException if this extension is no longer valid
* @see IExtensionRegistry
* @since 3.0
+ *
+ * @deprecated As namespace is no longer restricted to the contributor name,
+ * use {@link #getNamespaceIdentifier()} to obtain namespace name or {@link #getContributor()}
+ * to get the name of the contributor of this registry element
*/
public String getNamespace() throws InvalidRegistryObjectException;
/**
+ * Returns the namespace name for this extension.
+ * @return the namespace name for this extension
+ * @throws InvalidRegistryObjectException if this extension is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public String getNamespaceIdentifier() throws InvalidRegistryObjectException;
+
+ /**
+ * Returns the contributor of the extension.
+ * @return the contributor for this extension
+ * @throws InvalidRegistryObjectException if this extension is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public IContributor getContributor() throws InvalidRegistryObjectException;
+
+ /**
* Returns the unique identifier of the extension point
* to which this extension should be contributed.
*
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionPoint.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionPoint.java
index e83449709..cbc92212b 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionPoint.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionPoint.java
@@ -62,10 +62,30 @@ public interface IExtensionPoint {
* @throws InvalidRegistryObjectException if this extension point is no longer valid
* @see IExtensionRegistry
* @since 3.0
+ *
+ * @deprecated As namespace is no longer restricted to the contributor name,
+ * use {@link #getNamespaceIdentifier()} to obtain namespace name or {@link #getContributor()}
+ * to get the name of the contributor of this registry element
*/
public String getNamespace() throws InvalidRegistryObjectException;
/**
+ * Returns the namespace name for this extension point.
+ * @return the namespace name for this extension point
+ * @throws InvalidRegistryObjectException if this extension point is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public String getNamespaceIdentifier() throws InvalidRegistryObjectException;
+
+ /**
+ * Returns the contributor of the extension point.
+ * @return the contributor for this extension point
+ * @throws InvalidRegistryObjectException if this extension point is no longer valid
+ * @since org.eclipse.equinox.registry 3.2
+ */
+ public IContributor getContributor() throws InvalidRegistryObjectException;
+
+ /**
* Returns the extension with the given unique identifier configured into
* this extension point, or <code>null</code> if there is no such extension.
* Since an extension might not have an identifier, some extensions
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionRegistry.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionRegistry.java
index d79d9c844..aa7267038 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionRegistry.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IExtensionRegistry.java
@@ -256,10 +256,16 @@ public interface IExtensionRegistry {
* <p>
* This method is an access controlled method. Proper token (master token or user token) should
* be passed as an argument.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
* </p>
* @param is stream open on the XML file. The XML file can contain an extension
* poin(s) or/and extension(s) described in the format similar to plugin.xml
- * @param contributorId ID of the supplier of this contribution
+ * @param contributor the contributor making this contribution.
* @param persist indicates if contribution should be stored in the registry cache. If false,
* contribution is not persisted in the registry cache and is lost on Eclipse restart
* @param name optional name of the contribution. Used for error reporting; might be null
@@ -271,40 +277,57 @@ public interface IExtensionRegistry {
* @return - true: the contribution was successfully processed; false - error in
* the processing of the contribution
* @throws IllegalArgumentException if incorrect token is passed
+ *
+ * @see IContributor
+ * @since org.eclipse.equinox.registry 3.2
*/
- public boolean addContribution(InputStream is, String contributorId, boolean persist, String name, ResourceBundle translationBundle, Object token) throws IllegalArgumentException;
+ public boolean addContribution(InputStream is, IContributor contributor, boolean persist, String name, ResourceBundle translationBundle, Object token) throws IllegalArgumentException;
/**
* Removes extension.
- *
+ * <p>
+ * This method is an access controlled method. Proper token (master token or user token) should
+ * be passed as an argument.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
* @param extension extension to be removed
* @param token the key used to check permissions. Two registry keys are set in the registry
* constructor {@link RegistryFactory#createRegistry(org.eclipse.core.runtime.spi.RegistryStrategy, Object, Object)}:
* master token and a user token. Master token allows all operations; user token only
* allows non-persisted registry elements to be modified.
- * <p>
- * This method is an access controlled method. Proper token (master token or user token) should
- * be passed as an argument.
- * </p>
* @return true if the extension was successfully removed
* @throws IllegalArgumentException if incorrect token is passed
+ *
+ * @since org.eclipse.equinox.registry 3.2
*/
public boolean removeExtension(IExtension extension, Object token) throws IllegalArgumentException;
/**
* Removes extension point.
- *
+ * <p>
+ * This method is an access controlled method. Proper token (master token or user token) should
+ * be passed as an argument.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
* @param extensionPoint extension point to be removed
* @param token the key used to check permissions. Two registry keys are set in the registry
* constructor {@link RegistryFactory#createRegistry(org.eclipse.core.runtime.spi.RegistryStrategy, Object, Object)}:
* master token and a user token. Master token allows all operations; user token only
* allows non-persisted registry elements to be modified.
- * <p>
- * This method is an access controlled method. Proper token (master token or user token) should
- * be passed as an argument.
- * </p>
* @return true if the extension point was successfully removed
* @throws IllegalArgumentException if incorrect token is passed
+ *
+ * @since org.eclipse.equinox.registry 3.2
*/
public boolean removeExtensionPoint(IExtensionPoint extensionPoint, Object token) throws IllegalArgumentException;
@@ -318,6 +341,8 @@ public interface IExtensionRegistry {
* @see RegistryFactory#createRegistry(org.eclipse.core.runtime.spi.RegistryStrategy, Object, Object)
* @param token master token for the registry
* @throws IllegalArgumentException if incorrect token is passed
+ *
+ * @since org.eclipse.equinox.registry 3.2
*/
public void stop(Object token) throws IllegalArgumentException;
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IRegistryProvider.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IRegistryProvider.java
deleted file mode 100644
index de462fb3f..000000000
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/IRegistryProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.runtime;
-
-/**
- * Implement this interface to specify the default extension registry.
- *
- * @see RegistryFactory#getRegistry()
- * @see RegistryUtils#setRegistryProvider(IRegistryProvider)
- *
- * <b>This is an experimental API. It might change in future.</b>
- *
- * @since org.eclipse.equinox.registry 1.0
- */
-public interface IRegistryProvider {
-
- /**
- * Returns the "default" extension registry.
- * @return an extension registry
- */
- public IExtensionRegistry getRegistry();
-}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryFactory.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryFactory.java
index bf877a83a..b91c69a75 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryFactory.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryFactory.java
@@ -10,17 +10,22 @@
*******************************************************************************/
package org.eclipse.core.runtime;
-import org.eclipse.core.internal.registry.ExtensionRegistry;
-import org.eclipse.core.runtime.spi.RegistryStrategy;
+import java.io.File;
+import org.eclipse.core.internal.registry.*;
+import org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI;
+import org.eclipse.core.runtime.spi.*;
/**
* Use this class to create or obtain an extension registry.
- *
+ * <p>
* This class is not intended to be subclassed or instantiated.
- *
- * @since org.eclipse.equinox.registry 1.0
+ * </p>
+ * @since org.eclipse.equinox.registry 3.2
*/
public final class RegistryFactory {
+
+ private static IRegistryProvider defaultRegistryProvider;
+
/**
* Creates an extension registry.
*
@@ -44,6 +49,50 @@ public final class RegistryFactory {
* @return existing extension registry or null
*/
public static IExtensionRegistry getRegistry() {
- return RegistryUtils.getRegistryFromProvider();
+ if (defaultRegistryProvider == null)
+ return null;
+ return defaultRegistryProvider.getRegistry();
+ }
+
+ /**
+ * Creates registry strategy that can be used in an OSGi container. It uses OSGi contributions and contributors
+ * for the registry processing and takes advantage of additional mechanisms available through
+ * the OSGi library.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @param storageDir - file system directory to store cache files; might be null
+ * @param cacheReadOnly - true: cache is read only; false: cache is read/write
+ * @param token - control token for the registry
+ */
+ public static RegistryStrategy createOSGiStrategy(File storageDir, boolean cacheReadOnly, Object token) {
+ return new RegistryStrategyOSGI(storageDir, cacheReadOnly, token);
+ }
+
+ /**
+ * Use this method to specify the default registry provider. The default registry provider
+ * is immutable in the sense that it can be set only once during the application runtime.
+ * Attempts to change the default registry provider will cause CoreException.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @see RegistryFactory#getRegistry()
+ * @param provider - extension registry provider
+ * @throws CoreException - default registry provider was already set for this application
+ */
+ public static void setDefaultRegistryProvider(IRegistryProvider provider) throws CoreException {
+ if (defaultRegistryProvider != null) {
+ Status status = new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, RegistryMessages.registry_default_exists, null);
+ throw new CoreException(status);
+ }
+ defaultRegistryProvider = provider;
}
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryUtils.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryUtils.java
deleted file mode 100644
index 5731912d9..000000000
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/RegistryUtils.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.runtime;
-
-import java.io.File;
-import org.eclipse.core.internal.registry.IRegistryConstants;
-import org.eclipse.core.internal.registry.RegistryMessages;
-import org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI;
-import org.eclipse.core.runtime.spi.RegistryStrategy;
-import org.osgi.framework.Bundle;
-
-/**
- * Collection of utility methods related to the extension registry
- * functionality.
- *
- * This class is not intended to be subclassed or instantiated.
- *
- * @since org.eclipse.equinox.registry 1.0
- */
-public final class RegistryUtils {
-
- private static IRegistryProvider defaultRegistryProvider;
-
- /**
- * Creates registry strategy that can be used in OSGi world. It provides the following functionality:
- * - Event scheduling is done using Eclipse job scheduling mechanism
- * - Translation is done with Equinox ResourceTranslator
- * - Uses OSGi bundle model for namespace resolution
- * - Uses bunlde-based class loaders to create executable extensions
- * - Registry is filled with information stored in plugin.xml / fragment.xml files of OSGi bundles
- * with the XML parser is obtained via an OSGi service
- * - Performs registry validation based on the time stamps of the plugin.xml / fragment.xml files
- *
- * @param storageDir - file system directory to store cache files; might be null
- * @param cacheReadOnly - true: cache is read only; false: cache is read/write
- * @param token - control token for the registry
- */
- public static RegistryStrategy createOSGiStrategy(File storageDir, boolean cacheReadOnly, Object token) {
- return new RegistryStrategyOSGI(storageDir, cacheReadOnly, token);
- }
-
- /**
- * Returns Id corresponding to the OSGi bundle.
- * @see IExtensionRegistry#addContribution
- * @param bundle - OSGi bundle
- * @return Id used for the OSGi bundle
- */
- public static String getContributorId(Bundle bundle) {
- return RegistryStrategyOSGI.getId(bundle);
- }
-
- /**
- * Returns the existing extension registry specified by the registry provider.
- * May return null is the provider has not been set or registry was not created.
- *
- * @return existing extension registry or null
- */
- public static IExtensionRegistry getRegistryFromProvider() {
- if (defaultRegistryProvider == null)
- return null;
- return defaultRegistryProvider.getRegistry();
- }
-
- /**
- * Use this method to specify the default registry provider. The default registry provider
- * is immutable in the sense that it can be set only once during the application runtime.
- * Attempts to change the default registry provider will cause CoreException.
- *
- * @see RegistryFactory#getRegistry()
- *
- * <b>This is an experimental API. It might change in future.</b>
- *
- * @param provider - extension registry provider
- * @throws CoreException - default registry provider was already set for this application
- */
- public static void setRegistryProvider(IRegistryProvider provider) throws CoreException {
- if (defaultRegistryProvider != null) {
- Status status = new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, RegistryMessages.registry_default_exists, null);
- throw new CoreException(status);
- }
- defaultRegistryProvider = provider;
- }
-}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/ExtensionTracker.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/ExtensionTracker.java
index 486fc2a64..b7cf074c2 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/ExtensionTracker.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/ExtensionTracker.java
@@ -276,7 +276,7 @@ public class ExtensionTracker implements IExtensionTracker, IRegistryChangeListe
public static IFilter createNamespaceFilter(final String id) {
return new IFilter() {
public boolean matches(IExtensionPoint target) {
- return id.equals(target.getNamespace());
+ return id.equals(target.getNamespaceIdentifier());
}
};
}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/IFilter.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/IFilter.java
index 1dc0203db..ddd12717b 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/IFilter.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/dynamichelpers/IFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation 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
@@ -15,10 +15,10 @@ import org.eclipse.core.runtime.IExtensionPoint;
/**
* A filter compares the given object to some pattern and returns true
* if the two match and false otherwise..
- *
- * The API can be implemented by clients, however factory methods are
+ *<p>
+ * This interface may be implemented by clients, however factory methods are
* available on IExtensionTracker.
- *
+ * </p>
* @since 3.1
*/
public interface IFilter {
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/IRegistryProvider.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/IRegistryProvider.java
new file mode 100644
index 000000000..0c391004f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/IRegistryProvider.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.runtime.spi;
+
+import org.eclipse.core.runtime.IExtensionRegistry;
+
+/**
+ * Implement this interface to specify the default extension registry.
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @see org.eclipse.core.runtime.RegistryFactory#getRegistry()
+ * @see org.eclipse.core.runtime.RegistryFactory#setRegistryProvider(IRegistryProvider)
+ * @since org.eclipse.equinox.registry 3.2
+ */
+public interface IRegistryProvider {
+
+ /**
+ * Returns the "default" extension registry.
+ *
+ * @return an extension registry
+ */
+ public IExtensionRegistry getRegistry();
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryContributor.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryContributor.java
new file mode 100644
index 000000000..203060755
--- /dev/null
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryContributor.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.runtime.spi;
+
+import org.eclipse.core.runtime.IContributor;
+
+/**
+ * This class describes a registry contributor - an entity that supplies information
+ * to the extension registry. Depending on the registry strategy, contributor might delegate
+ * some of its functionality to a "host" contributor. For instance, OSGi registry strategy
+ * uses "host" contributor to delegate some functionality from fragments to plugins.
+ * <p>
+ * This class can be instantiated by the Service Providers.
+ * This class can not be extended.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @since org.eclipse.equinox.registry 3.2
+ */
+public final class RegistryContributor implements IContributor {
+
+ /**
+ * Actual ID of the contributor (e.g., "12"). IDs are expected to be unique in the workspace.
+ */
+ private String actualContributorId;
+
+ /**
+ * Actual name of the contributor (e.g., "org.eclipse.core.runtime.fragment").
+ */
+ private String actualContributorName;
+
+ /**
+ * ID associated with the entity "in charge" of the contributor (e.g., "1"). IDs are expected
+ * to be unique in the workspace. If contributor does not rely on a host, this value should be
+ * the same as the actual contributor Id..
+ */
+ private String hostId;
+
+ /**
+ * Name of the entity "in charge" of the contributor (e.g. "org.eclipse.core.runtime").
+ * If contributor does not rely on a host, this value should be the same as the actual
+ * contributor name.
+ */
+ private String hostName;
+
+ /**
+ * Public constructor.
+ *
+ * @param actualId actual ID of the contributor (e.g., "12"). IDs are expected to be unique in the workspace.
+ * @param actualName actual name of the contributor (e.g., "org.eclipse.core.runtime.fragment")
+ * @param hostId id associated with the entity "in charge" of the contributor (e.g., "1"). IDs are expected
+ * to be unique in the workspace. If contributor does not rely on a host, pass null.
+ * @param hostName name of the entity "in charge" of the contributor (e.g., "org.eclipse.core.runtime").
+ * If contributor does not rely on a host, pass null.
+ */
+ public RegistryContributor(String actualId, String actualName, String hostId, String hostName) {
+ this.actualContributorId = actualId;
+ this.actualContributorName = actualName;
+ if (hostId != null) {
+ this.hostId = hostId;
+ this.hostName = hostName;
+ } else {
+ this.hostId = actualId;
+ this.hostName = actualName;
+ }
+ }
+
+ /**
+ * Provides actual id associated with the registry contributor (e.g., "12"). IDs are expected
+ * to be unique in the workspace.
+ *
+ * @return actual id of the registry contributor
+ */
+ public String getActualId() {
+ return actualContributorId;
+ }
+
+ /**
+ * Provides actual name of the registry contributor (e.g., "org.eclipe.core.runtime.fragment").
+ *
+ * @return actual name of the registry contributor
+ */
+ public String getActualName() {
+ return actualContributorName;
+ }
+
+ /**
+ * Provides id associated with the entity "in charge" of the contributor (e.g., "1"). IDs are expected
+ * to be unique in the workspace. If contributor does not rely on a host, this value should be
+ * the same as the actual contributor Id.
+ *
+ * @return id of the registry contributor
+ */
+ public String getId() {
+ return hostId;
+ }
+
+ /**
+ * Provides name of the entity "in charge" of the contributor (e.g., "org.eclipse.core.runtime").
+ * If contributor does not rely on a host, this value should be the same as the actual contributor name.
+ *
+ * @return name of the registry contributor
+ */
+ public String getName() {
+ return hostName;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return actualContributorName + "[" + actualContributorId + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryStrategy.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryStrategy.java
index 7229eb177..dbc040b63 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryStrategy.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/runtime/spi/RegistryStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation 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
@@ -22,17 +22,24 @@ import org.eclipse.osgi.util.NLS;
* This is the basic registry strategy. It describes how registry does logging,
* message translation, namespace resolution, extra start/stop processing, event scheduling,
* caching, and debugging.
- *
+ * <p>
* In this strategy:
- * - Clients can add information into the registry
- * - Caching is enabled and doesn't use state or time stamp validation; no alternative cache location is supplied
- * - Logging is done onto System.out
- * - All registry contributors are assumed to reside in separate namespaces
- * - Standard Java class loading is used to create executable extensions
- *
- * This class can be overridden and/or instantiated.
- *
- * @since org.eclipse.equinox.registry 1.0
+ * </p><p><ul>
+ * <li>Clients can add information into the registry</li>
+ * <li>Caching is enabled and doesn't use state or time stamp validation; no alternative cache location is supplied</li>
+ * <li>Logging is done onto System.out</li>
+ * <li>Registry contributors properties are determined by the toString() value of the defining objects</li>
+ * <li>Standard Java class loading is used to create executable extensions</li>
+ * </ul></p><p>
+ * This class can be overridden and/or instantiated by clients.
+ * </p><p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost certainly
+ * be broken (repeatedly) as the API evolves.
+ * </p>
+ * @since org.eclipse.equinox.registry 3.2
*/
public class RegistryStrategy {
@@ -125,81 +132,39 @@ public class RegistryStrategy {
}
/**
- * Returns Id of the namespace owner that given contributor resides in.
- *
- * Override this method to supply namespace resolution capabilities to
- * the extension registry. If this interface is not overridden, each contributor
- * is assumed to be in its own namespace (namespaceOwnerId is the same as contributorId);
- * namespace name is assumed to be a String form of the contributorId.
- *
- * It is assumed that namespaces organize contributors into groups. Or, more formally:
- *
- * 1) each contributor resides in a namespace
- * 2) each namespace is owned by some contributor
- * 3) many contributors can reside in a single namespace
- *
- * @param contributorId - Id of the contributor in question
- * @return - Id of the namespace owner
- */
- public String getNamespaceOwnerId(String contributorId) {
- return contributorId;
- }
-
- /**
- * Returns name of the namespace that given contributor resides in.
- * @see #getNamespaceOwnerId(String)
- *
- * @param contributorId - Id of the contributor in question
- * @return - namespace name
- */
- public String getNamespace(String contributorId) {
- return contributorId;
- }
-
- /**
- * Returns Ids of all contributors residing in a given namespace
- * @see #getNamespaceOwnerId(String)
- *
- * @param namespace - namespace name
- * @return - array of contributor Ids residing in the namespace
- */
- public String[] getNamespaceContributors(String namespace) {
- return new String[] {namespace};
- }
-
- /**
* Creates an executable extension. Override this method to supply an alternative processing
* for the creation of executable extensions.
- *
+ * <p>
+ * This method recieves the contributor of the executable extension and, possibly,
+ * an optional contributor name (if specified by the executable extension).
+ * </p><p>
* In this implementation registry attempts to instantiate the class specified using
* standard Java reflection mechanism; it assumes that constructor of such class has no arguments.
- *
+ * </p>
* @see IConfigurationElement#createExecutableExtension(String)
*
- * @param contributorName - name of the extension supplier
- * @param namespaceOwnerId - Id of the namespace owner
- * @param namespaceName - name of the extension point namespace
+ * @param contributor - contributor of this executable extension
* @param className - name of the class to be instantiated
- * @param initData - initializer data (@see IExecutableExtension); might be null
- * @param propertyName - name of the configuration element containing class information
- * @param theConfElement - the configuration element containing executable extension
+ * @param overridenContributorName - optionally executable extension can request a specific contributor
+ * to be used; might be null
* @return - the object created; might be null
* @throws CoreException
+ * @see IExecutableExtension
*/
- public Object createExecutableExtension(String contributorName, String namespaceOwnerId, String namespaceName, String className, Object initData, String propertyName, IConfigurationElement theConfElement) throws CoreException {
+ public Object createExecutableExtension(RegistryContributor contributor, String className, String overridenContributorName) throws CoreException {
Object result = null;
Class classInstance = null;
try {
classInstance = Class.forName(className);
} catch (ClassNotFoundException e1) {
- String message = NLS.bind(RegistryMessages.exExt_findClassError, getNamespace(namespaceOwnerId), className);
+ String message = NLS.bind(RegistryMessages.exExt_findClassError, contributor.getActualName(), className);
throw new CoreException(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, message, e1));
}
try {
result = classInstance.newInstance();
} catch (Exception e) {
- String message = NLS.bind(RegistryMessages.exExt_instantiateClassError, getNamespace(namespaceOwnerId), className);
+ String message = NLS.bind(RegistryMessages.exExt_instantiateClassError, contributor.getActualName(), className);
throw new CoreException(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, message, e));
}
return result;
@@ -352,5 +317,4 @@ public class RegistryStrategy {
theXMLParserFactory = SAXParserFactory.newInstance();
return theXMLParserFactory;
}
-
}

Back to the top