Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Merks2023-02-26 09:21:08 +0000
committerEd Merks2023-02-26 09:21:08 +0000
commit3295732ab0a2d3a4cfa31daa80993b5014e03f96 (patch)
tree4095a881897ce8dc92b01cbcc67df66a5305b1fd /plugins/org.eclipse.emf.ecore/src/org/eclipse/emf
parentc684ed1637394ce3b2fb87a18e19f2fe72c90dfe (diff)
downloadorg.eclipse.emf-master.tar.gz
org.eclipse.emf-master.tar.xz
org.eclipse.emf-master.zip
[581598] ContentHandlerRegistryReader eagerly loads registered classesHEADmaster
Diffstat (limited to 'plugins/org.eclipse.emf.ecore/src/org/eclipse/emf')
-rw-r--r--plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/ContentHandlerRegistryReader.java80
1 files changed, 61 insertions, 19 deletions
diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/ContentHandlerRegistryReader.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/ContentHandlerRegistryReader.java
index 45829e412..76efef4f8 100644
--- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/ContentHandlerRegistryReader.java
+++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/ContentHandlerRegistryReader.java
@@ -11,7 +11,10 @@
package org.eclipse.emf.ecore.plugin;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -20,6 +23,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.emf.common.CommonPlugin;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ContentHandler;
@@ -46,7 +50,7 @@ class ContentHandlerRegistryReader extends RegistryReader
private static final Map<String, List<ContentHandler>> CONTRIBUTION_MAP = new HashMap<String, List<ContentHandler>>();
@Override
- protected boolean readElement(IConfigurationElement element, boolean add)
+ protected boolean readElement(final IConfigurationElement element, boolean add)
{
if (element.getName().equals(TAG_HANDLER))
{
@@ -55,7 +59,7 @@ class ContentHandlerRegistryReader extends RegistryReader
{
priority = Integer.parseInt(element.getAttribute(ATT_PRIORITY));
}
- String contributorClassName = element.getAttribute(ATT_CLASS);
+ final String contributorClassName = element.getAttribute(ATT_CLASS);
if (contributorClassName == null)
{
logMissingAttribute(element, ATT_CLASS);
@@ -65,31 +69,69 @@ class ContentHandlerRegistryReader extends RegistryReader
String contributorName = element.getContributor().getName();
if (add)
{
- try
+ class Delegate implements ContentHandler
{
- @SuppressWarnings("unchecked")
- Class<ContentHandler> contributorHandlerClass = (Class<ContentHandler>)CommonPlugin.loadClass(element.getNamespaceIdentifier(), contributorClassName);
- Map<String, String> parameters = new HashMap<String, String>();
- for (IConfigurationElement parameter : element.getChildren("parameter"))
+ private volatile ContentHandler delegate;
+
+ private ContentHandler getDelegate()
{
- parameters.put(parameter.getAttribute("name"), parameter.getAttribute("value"));
+ if (delegate == null)
+ {
+ synchronized (this)
+ {
+ if (delegate == null)
+ {
+ try
+ {
+ @SuppressWarnings("unchecked")
+ Class<ContentHandler> contributorHandlerClass = (Class<ContentHandler>)CommonPlugin.loadClass(element.getNamespaceIdentifier(), contributorClassName);
+ Map<String, String> parameters = new HashMap<String, String>();
+ for (IConfigurationElement parameter : element.getChildren("parameter"))
+ {
+ parameters.put(parameter.getAttribute("name"), parameter.getAttribute("value"));
+ }
+ delegate = parameters.isEmpty()
+ ? contributorHandlerClass.getDeclaredConstructor().newInstance() : contributorHandlerClass.getConstructor(Map.class).newInstance(parameters);
+ }
+ catch (Exception exception)
+ {
+ delegate = this;
+ EcorePlugin.INSTANCE.log(exception);
+ }
+ }
+ }
+ }
+ return delegate;
}
- ContentHandler contentHandler =
- parameters.isEmpty() ?
- contributorHandlerClass.getDeclaredConstructor().newInstance() :
- contributorHandlerClass.getConstructor(Map.class).newInstance(parameters);
- ContentHandler.Registry.INSTANCE.put(priority, contentHandler);
- List<ContentHandler> contributions = CONTRIBUTION_MAP.get(contributorName);
- if (contributions == null)
+
+ public boolean canHandle(URI uri)
{
- CONTRIBUTION_MAP.put(contributorName, contributions = new ArrayList<ContentHandler>());
+ ContentHandler delegate = getDelegate();
+ return delegate != this && delegate.canHandle(uri);
+ }
+
+ public Map<String, ?> contentDescription(URI uri, InputStream inputStream, Map<?, ?> options, Map<Object, Object> context) throws IOException
+ {
+ ContentHandler delegate = getDelegate();
+ if (delegate != this)
+ {
+ return delegate.contentDescription(uri, inputStream, options, context);
+ }
+ else
+ {
+ return Collections.emptyMap();
+ }
}
- contributions.add(contentHandler);
}
- catch (Exception exception)
+
+ ContentHandler contentHandler = new Delegate();
+ ContentHandler.Registry.INSTANCE.put(priority, contentHandler);
+ List<ContentHandler> contributions = CONTRIBUTION_MAP.get(contributorName);
+ if (contributions == null)
{
- EcorePlugin.INSTANCE.log(exception);
+ CONTRIBUTION_MAP.put(contributorName, contributions = new ArrayList<ContentHandler>());
}
+ contributions.add(contentHandler);
return true;
}
else

Back to the top