Fix ModuleInfoSnapshotResolver
[mdsal.git] / binding / mdsal-binding-runtime-spi / src / main / java / org / opendaylight / mdsal / binding / runtime / spi / ModuleInfoSnapshotResolver.java
index 458a7bc141e70afa095acfb118180c701627267f..fd30bb6ac01eaadf2e4c03b69bb8f330d1d35162 100644 (file)
@@ -29,21 +29,20 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.concepts.Mutable;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataRoot;
 import org.opendaylight.yangtools.yang.binding.YangFeature;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.binding.contract.Naming;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
@@ -113,9 +112,8 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
         return ctxResolver.registerSupportedFeatures(BindingReflections.getQNameModule(module), features);
     }
 
-    public synchronized List<ObjectRegistration<YangModuleInfo>> registerModuleInfos(
-            final Iterable<? extends YangModuleInfo> moduleInfos) {
-        final var ret = new ArrayList<ObjectRegistration<YangModuleInfo>>();
+    public synchronized List<Registration> registerModuleInfos(final Iterable<? extends YangModuleInfo> moduleInfos) {
+        final var ret = new ArrayList<Registration>();
         for (var moduleInfo : moduleInfos) {
             ret.add(register(requireNonNull(moduleInfo)));
         }
@@ -123,12 +121,12 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
     }
 
     @Holding("this")
-    private ObjectRegistration<YangModuleInfo> register(final @NonNull YangModuleInfo moduleInfo) {
+    private Registration register(final @NonNull YangModuleInfo moduleInfo) {
         final var regInfos = flatDependencies(moduleInfo).stream()
             .map(this::registerModuleInfo)
             .collect(ImmutableList.toImmutableList());
 
-        return new AbstractObjectRegistration<>(moduleInfo) {
+        return new AbstractRegistration() {
             @Override
             protected void removeRegistration() {
                 unregister(regInfos);
@@ -169,7 +167,7 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
     public synchronized @NonNull ModuleInfoSnapshot takeSnapshot() {
         final var effectiveModel = ctxResolver.getEffectiveModelContext().orElseThrow();
         final var local = currentSnapshot;
-        if (local != null && local.getEffectiveModelContext().equals(effectiveModel)) {
+        if (local != null && local.modelContext().equals(effectiveModel)) {
             return local;
         }
 
@@ -177,10 +175,10 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
     }
 
     @Holding("this")
-    private @NonNull ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
+    private @NonNull ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext modelContext) {
         // Alright, now let's find out which sources got captured
         final var sources = new HashSet<SourceIdentifier>();
-        for (var entry : effectiveModel.getModuleStatements().entrySet()) {
+        for (var entry : modelContext.getModuleStatements().entrySet()) {
             final var revision = entry.getKey().getRevision().orElse(null);
             final var module = entry.getValue();
 
@@ -199,12 +197,10 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
             final var reg = regs.get(0);
             final var info = reg.info;
             moduleInfos.put(source, info);
-            final var infoClass = info.getClass();
-            classLoaders.put(Naming.getModelRootPackageName(infoClass.getPackage().getName()),
-                infoClass.getClassLoader());
+            classLoaders.put(Naming.getRootPackageName(info.getName().getModule()), info.getClass().getClassLoader());
         }
 
-        final var next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
+        final var next = new DefaultModuleInfoSnapshot(modelContext, moduleInfos, classLoaders);
         currentSnapshot = next;
         return next;
     }
@@ -225,19 +221,18 @@ public final class ModuleInfoSnapshotResolver implements Mutable {
         }
     }
 
-    static @NonNull YangTextSchemaSource toYangTextSource(final YangModuleInfo moduleInfo) {
-        return YangTextSchemaSource.delegateForCharSource(sourceIdentifierFrom(moduleInfo),
-            moduleInfo.getYangTextCharSource());
+    static @NonNull YangTextSource toYangTextSource(final YangModuleInfo moduleInfo) {
+        return new DelegatedYangTextSource(sourceIdentifierFrom(moduleInfo), moduleInfo.getYangTextCharSource());
     }
 
-    private static @NonNull YangTextSchemaSource toYangTextSource(final SourceIdentifier identifier,
+    private static @NonNull YangTextSource toYangTextSource(final SourceIdentifier identifier,
             final YangModuleInfo moduleInfo) {
-        return YangTextSchemaSource.delegateForCharSource(identifier, moduleInfo.getYangTextCharSource());
+        return new DelegatedYangTextSource(identifier, moduleInfo.getYangTextCharSource());
     }
 
     private static SourceIdentifier sourceIdentifierFrom(final YangModuleInfo moduleInfo) {
         final var name = moduleInfo.getName();
-        return new SourceIdentifier(name.getLocalName(), name.getRevision().map(Revision::toString).orElse(null));
+        return new SourceIdentifier(name.getLocalName(), name.getRevision().orElse(null));
     }
 
     private static @NonNull List<@NonNull YangModuleInfo> flatDependencies(final YangModuleInfo moduleInfo) {