diff --git a/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml b/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml index 593a0993e..5be571efd 100644 --- a/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml @@ -1,5 +1,5 @@ - + diff --git a/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java b/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java index 0f5cce01c..0210accb8 100644 --- a/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java @@ -52,22 +52,22 @@ @SuppressWarnings("restriction") @Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + FeaturesPackage.eNAME, EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "features_xmi" }) -public class FeatureDomainRegistry extends BaseDomainRegistry +public final class FeatureDomainRegistry extends BaseDomainRegistry implements FeatureRegistry, EditingDomainRegistry { private final Map sets = new HashMap<>(); private final Map features = new HashMap<>(); private final Map> versions = new HashMap<>(); - private EventAdmin events; + private final List events = new ArrayList<>(); @Reference public void bindEventAdmin(EventAdmin admin) { - this.events = admin; + this.events.add(admin); } - public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { - this.events = null; + public void unbindEventAdmin(EventAdmin admin) { + this.events.remove(admin); } @Override @@ -81,15 +81,13 @@ public void unbindGear(OperatorGearSupplier supplier) { super.unbindGear(supplier); } - @Override @Activate - public void activate(Map properties) { + public void load(Map properties) { super.activate(properties); } @Deactivate - @Override - public void deactivate(Map properties) { + public void unload(Map properties) { versions.values().forEach(Map::clear); versions.clear(); features.clear(); @@ -153,7 +151,7 @@ void registerFeatureSet(FeatureSet fs) { Platform.getLog(getClass()) .warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, fs)); } - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_CREATE, fs).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_CREATE, fs).get()); fs.getFeatures().forEach(this::registerFeature); } @@ -163,7 +161,7 @@ void registerFeature(Feature feature) { Platform.getLog(getClass()) .warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, feature)); } - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_CREATE, feature).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_CREATE, feature).get()); feature.getFeatureVersions().forEach(fv -> registerFeatureVersion(feature, fv)); } @@ -175,13 +173,13 @@ void registerFeatureVersion(Feature feature, FeatureVersion version) { Platform.getLog(getClass()) .warn(NLS.bind(FeaturesCoreMessages.FeatureDomain_instance_duplication_message, existing, version)); } - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_CREATE, version).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_CREATE, version).get()); } void unregisterFeatureSet(String id) { FeatureSet removed = sets.remove(id); if (removed != null) { - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_DELETE, removed).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_SET_DELETE, removed).get()); removed.getFeatures().stream().map(Feature::getIdentifier).forEach(this::unregisterFeature); } } @@ -189,7 +187,7 @@ void unregisterFeatureSet(String id) { void unregisterFeature(String id) { Feature removed = features.remove(id); if (removed != null) { - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_DELETE, removed).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_DELETE, removed).get()); removed.getFeatureVersions().forEach(fv -> unregisterFeatureVersion(id, fv.getVersion())); } } @@ -199,7 +197,7 @@ void unregisterFeatureVersion(String featureId, String version) { if (map != null) { FeatureVersion removed = map.remove(version); if (removed != null) { - events.postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_DELETE, removed).get()); + events().postEvent(new EquinoxEvent(FeatureRegistryEvents.FEATURE_VERSION_DELETE, removed).get()); } if (map.isEmpty()) { versions.remove(version); @@ -207,6 +205,10 @@ void unregisterFeatureVersion(String featureId, String version) { } } + private EventAdmin events() { + return events.stream().findAny().get(); + } + @Override public EClass getContentClassifier() { return FeaturesPackage.eINSTANCE.getFeatureSet();