Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2020-09-21 04:31:51 +0000
committerEike Stepper2020-09-21 04:31:51 +0000
commitf829ad36d692cc8f6c7db9e5eed03399ab74c5d7 (patch)
tree3d7b33a5e0becd11fb6c10c2c1663a0de6f69bc6 /plugins/org.eclipse.emf.cdo.common/src
parent540e0ee87a2b89e592e8ff7db32119f518f1a589 (diff)
downloadcdo-f829ad36d692cc8f6c7db9e5eed03399ab74c5d7.tar.gz
cdo-f829ad36d692cc8f6c7db9e5eed03399ab74c5d7.tar.xz
cdo-f829ad36d692cc8f6c7db9e5eed03399ab74c5d7.zip
[567097] Provide org.eclipse.emf.cdo.common.util.ResourceSetConfigurer
https://bugs.eclipse.org/bugs/show_bug.cgi?id=567097
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ResourceSetConfigurer.java167
1 files changed, 100 insertions, 67 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ResourceSetConfigurer.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ResourceSetConfigurer.java
index 9d8f7d738b..df21a13308 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ResourceSetConfigurer.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ResourceSetConfigurer.java
@@ -10,14 +10,19 @@
*/
package org.eclipse.emf.cdo.common.util;
+import org.eclipse.emf.cdo.internal.common.bundle.OM;
+
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.factory.ProductCreationException;
import org.eclipse.net4j.util.lifecycle.IDeactivateable;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -32,71 +37,6 @@ public interface ResourceSetConfigurer
/**
* @author Eike Stepper
*/
- public static final class ResourceSetConfiguration implements IDeactivateable
- {
- private final ResourceSet resourceSet;
-
- private final Object context;
-
- private final IManagedContainer container;
-
- private final Map<String, Object> configurerResults = new HashMap<>();
-
- private ResourceSetConfiguration(ResourceSet resourceSet, Object context, IManagedContainer container)
- {
- this.resourceSet = resourceSet;
- this.context = context;
- this.container = container;
- }
-
- public ResourceSet getResourceSet()
- {
- return resourceSet;
- }
-
- public Object getContext()
- {
- return context;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public Map<String, Object> getConfigurerResults()
- {
- return configurerResults;
- }
-
- @Override
- public Exception deactivate()
- {
- Exception exception = null;
-
- try
- {
- for (Object configurerResult : configurerResults.values())
- {
- Exception ex = LifecycleUtil.deactivate(configurerResult);
- if (ex != null && exception == null)
- {
- exception = ex;
- }
- }
- }
- finally
- {
- configurerResults.clear();
- }
-
- return exception;
- }
- }
-
- /**
- * @author Eike Stepper
- */
public static abstract class Factory extends org.eclipse.net4j.util.factory.Factory
{
public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.common.ResourceSetConfigurers";
@@ -129,7 +69,6 @@ public interface ResourceSetConfigurer
public ResourceSetConfiguration configureResourceSet(ResourceSet resourceSet, Object context, IManagedContainer container)
{
ResourceSetConfiguration configuration = new ResourceSetConfiguration(resourceSet, context, container);
- Map<String, Object> configurerResults = configuration.getConfigurerResults();
for (String type : container.getFactoryTypes(Factory.PRODUCT_GROUP))
{
@@ -138,7 +77,7 @@ public interface ResourceSetConfigurer
Object configurerResult = configurer.configureResourceSet(resourceSet, context, container);
if (configurerResult != null)
{
- configurerResults.put(type, configurerResult);
+ configuration.configurerResults.put(type, configurerResult);
}
}
@@ -149,5 +88,99 @@ public interface ResourceSetConfigurer
{
return configureResourceSet(resourceSet, context, IPluginContainer.INSTANCE);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class ResourceSetConfiguration extends AdapterImpl implements IDeactivateable
+ {
+ private final ResourceSet resourceSet;
+
+ private final Object context;
+
+ private final IManagedContainer container;
+
+ private final Map<String, Object> configurerResults = new HashMap<>();
+
+ private ResourceSetConfiguration(ResourceSet resourceSet, Object context, IManagedContainer container)
+ {
+ this.resourceSet = resourceSet;
+ this.context = context;
+ this.container = container;
+
+ resourceSet.eAdapters().add(this);
+ }
+
+ public ResourceSet getResourceSet()
+ {
+ return resourceSet;
+ }
+
+ public Object getContext()
+ {
+ return context;
+ }
+
+ public IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ public Map<String, Object> getConfigurerResults()
+ {
+ return Collections.unmodifiableMap(configurerResults);
+ }
+
+ @Override
+ public Exception deactivate()
+ {
+ resourceSet.eAdapters().remove(this);
+
+ Exception exception = null;
+
+ try
+ {
+ for (Object configurerResult : configurerResults.values())
+ {
+ Exception ex = LifecycleUtil.deactivate(configurerResult);
+ if (ex != null)
+ {
+ OM.LOG.error(ex);
+
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ configurerResults.clear();
+ }
+
+ return exception;
+ }
+
+ @Override
+ public boolean isAdapterForType(Object type)
+ {
+ return type == ResourceSetConfiguration.class;
+ }
+
+ public static ResourceSetConfiguration of(ResourceSet resourceSet)
+ {
+ return (ResourceSetConfiguration)EcoreUtil.getAdapter(resourceSet.eAdapters(), ResourceSetConfiguration.class);
+ }
+ }
}
}

Back to the top