Add DatabindContext and its wiring 03/103203/8
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 10 Nov 2022 18:43:28 +0000 (19:43 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Nov 2022 09:50:51 +0000 (10:50 +0100)
We are acquiring EffectiveModelContext and codecs left and right. Add
DatabindContext, which is an immutable view of these and a service to
maintain them in the global view.

This allows us to eliminate references to SchemaContextHandler, hence it
is no longer a central point.

Change-Id: Iab15f628832008b8a818a48746af9e76781958cb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
47 files changed:
restconf/restconf-nb/pom.xml
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/AbstractNormalizedNodeBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/JsonStreamWriterWithDisabledValidation.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/StreamWriterWithDisabledValidation.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/XmlStreamWriterWithDisabledValidation.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractPatchBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java
restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java

index d083de81dcda5f5c2bd5599912b0573f7b389fd6..d9fab06a2c8962a0220b182f2c54b8e3e1fa5156 100644 (file)
       <optional>true</optional>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.opendaylight.netconf</groupId>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>rfc8528-data-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>rfc8528-data-util</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-model-api</artifactId>
index 2893b4945ad60aa91c4e06748d58573f88e29552..a0c51d1306b4d2c01eb9e4b9e0e643dd86d70f4d 100644 (file)
@@ -14,7 +14,7 @@ import java.util.List;
 import java.util.Set;
 import javax.ws.rs.core.Application;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyWriter;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
@@ -31,13 +31,13 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlPatchStatu
  * Abstract Restconf Application.
  */
 abstract class AbstractRestconfApplication extends Application {
-    private final SchemaContextHandler schemaContextHandler;
+    private final DatabindProvider databindProvider;
     private final DOMMountPointService mountPointService;
     private final List<Object> services;
 
-    AbstractRestconfApplication(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointService mountPointService, final List<Object> services) {
-        this.schemaContextHandler = requireNonNull(schemaContextHandler);
+    AbstractRestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService,
+            final List<Object> services) {
+        this.databindProvider = requireNonNull(databindProvider);
         this.mountPointService = requireNonNull(mountPointService);
         this.services = requireNonNull(services);
     }
@@ -54,11 +54,11 @@ abstract class AbstractRestconfApplication extends Application {
     public final Set<Object> getSingletons() {
         return ImmutableSet.<Object>builderWithExpectedSize(services.size() + 5)
             .addAll(services)
-            .add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService))
-            .add(new JsonPatchBodyReader(schemaContextHandler, mountPointService))
-            .add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService))
-            .add(new XmlPatchBodyReader(schemaContextHandler, mountPointService))
-            .add(new RestconfDocumentedExceptionMapper(schemaContextHandler))
+            .add(new JsonNormalizedNodeBodyReader(databindProvider, mountPointService))
+            .add(new JsonPatchBodyReader(databindProvider, mountPointService))
+            .add(new XmlNormalizedNodeBodyReader(databindProvider, mountPointService))
+            .add(new XmlPatchBodyReader(databindProvider, mountPointService))
+            .add(new RestconfDocumentedExceptionMapper(databindProvider))
             .build();
     }
 }
index deec9d9375e07c1454c78493363eced9aa76e875..129dfaa633a9cc78d15ef0df277ad8ccc76de640 100644 (file)
@@ -11,7 +11,7 @@ import java.util.List;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataStreamService;
 
 /**
@@ -20,8 +20,8 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataStrea
 @Singleton
 public class DataStreamApplication extends AbstractRestconfApplication {
     @Inject
-    public DataStreamApplication(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointService mountPointService, final RestconfDataStreamService dataStreamService) {
-        super(schemaContextHandler, mountPointService, List.of(dataStreamService));
+    public DataStreamApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService,
+            final RestconfDataStreamService dataStreamService) {
+        super(databindProvider, mountPointService, List.of(dataStreamService));
     }
 }
index c869343d986aca9484fb3524d9f0fe4bfe0d105b..383926b31967d6814ee2613babf977e31372a259 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
@@ -28,29 +28,28 @@ import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 
 @Singleton
 public class RestconfApplication extends AbstractRestconfApplication {
-    private RestconfApplication(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService streamSubscription,
-            final DOMDataBroker dataBroker, final DOMRpcService rpcService, final DOMActionService actionService,
+    private RestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService,
+            final RestconfStreamsSubscriptionService streamSubscription, final DOMDataBroker dataBroker,
+            final DOMRpcService rpcService, final DOMActionService actionService,
             final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
             final Configuration configuration) {
-        super(schemaContextHandler, mountPointService, List.of(
+        super(databindProvider, mountPointService, List.of(
             streamSubscription,
-            new RestconfDataServiceImpl(schemaContextHandler, dataBroker, mountPointService, streamSubscription,
+            new RestconfDataServiceImpl(databindProvider, dataBroker, mountPointService, streamSubscription,
                 actionService, configuration),
             new RestconfInvokeOperationsServiceImpl(rpcService),
-            new RestconfOperationsServiceImpl(schemaContextHandler, mountPointService),
+            new RestconfOperationsServiceImpl(databindProvider, mountPointService),
             new RestconfSchemaServiceImpl(domSchemaService, mountPointService),
-            new RestconfImpl(schemaContextHandler)));
+            new RestconfImpl(databindProvider)));
     }
 
     @Inject
-    public RestconfApplication(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointService mountPointService, final DOMDataBroker dataBroker,
-            final DOMRpcService rpcService, final DOMActionService actionService,
-            final DOMNotificationService notificationService,
-            final DOMSchemaService domSchemaService, final Configuration configuration) {
-        this(schemaContextHandler, mountPointService,
-            new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, schemaContextHandler,
+    public RestconfApplication(final DatabindProvider databindProvider, final DOMMountPointService mountPointService,
+            final DOMDataBroker dataBroker, final DOMRpcService rpcService, final DOMActionService actionService,
+            final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
+            final Configuration configuration) {
+        this(databindProvider, mountPointService,
+            new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
                 configuration),
             dataBroker, rpcService, actionService, notificationService, domSchemaService, configuration);
     }
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindContext.java
new file mode 100644 (file)
index 0000000..6ed4fcc
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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
+ */
+package org.opendaylight.restconf.nb.rfc8040.databind;
+
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
+import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
+import org.opendaylight.yangtools.yang.data.codec.xml.XmlCodecFactory;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+
+/**
+ * An immutable context holding a consistent view of things related to data bind operations.
+ */
+public record DatabindContext(
+        @NonNull MountPointContext mountContext,
+        @NonNull JSONCodecFactory jsonCodecs,
+        @NonNull XmlCodecFactory xmlCodecs) {
+    public DatabindContext {
+        requireNonNull(mountContext);
+        requireNonNull(jsonCodecs);
+        requireNonNull(xmlCodecs);
+    }
+
+    public static @NonNull DatabindContext ofModel(final EffectiveModelContext modelContext) {
+        return ofMountPoint(new EmptyMountPointContext(modelContext));
+    }
+
+    public static @NonNull DatabindContext ofMountPoint(final MountPointContext mountContext) {
+        return new DatabindContext(mountContext,
+            JSONCodecFactorySupplier.RFC7951.getShared(mountContext.getEffectiveModelContext()),
+            XmlCodecFactory.create(mountContext));
+    }
+
+    public @NonNull EffectiveModelContext modelContext() {
+        return mountContext.getEffectiveModelContext();
+    }
+}
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/DatabindProvider.java
new file mode 100644 (file)
index 0000000..88cd3a2
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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
+ */
+package org.opendaylight.restconf.nb.rfc8040.databind;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A service providing access to a {@link DatabindContext}.
+ */
+@NonNullByDefault
+public interface DatabindProvider {
+    /**
+     * Acquire current {@link DatabindContext}.
+     *
+     * @return Current {@link DatabindContext}
+     */
+    DatabindContext currentContext();
+}
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/DOMDatabindProvider.java
new file mode 100644 (file)
index 0000000..38caf7b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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
+ */
+package org.opendaylight.restconf.nb.rfc8040.databind.mdsal;
+
+import static com.google.common.base.Verify.verifyNotNull;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+
+/**
+ * A {@link DatabindProvider} monitoring a {@link DOMSchemaService}.
+ */
+@Singleton
+@Component(service = DatabindProvider.class)
+public final class DOMDatabindProvider implements DatabindProvider, EffectiveModelContextListener, AutoCloseable {
+    private final Registration reg;
+
+    private volatile DatabindContext currentContext;
+
+    @Inject
+    @Activate
+    public DOMDatabindProvider(@Reference final DOMSchemaService schemaService) {
+        currentContext = DatabindContext.ofModel(schemaService.getGlobalContext());
+        reg = schemaService.registerSchemaContextListener(this);
+    }
+
+    @Override
+    public DatabindContext currentContext() {
+        return verifyNotNull(currentContext, "Provider already closed");
+    }
+
+    @Override
+    public void onModelContextUpdated(final EffectiveModelContext newModelContext) {
+        final var local = currentContext;
+        if (local != null && local.modelContext() != newModelContext) {
+            currentContext = DatabindContext.ofModel(newModelContext);
+        }
+    }
+
+    @PreDestroy
+    @Deactivate
+    @Override
+    public void close() {
+        reg.close();
+        currentContext = null;
+    }
+}
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/mdsal/package-info.java
new file mode 100644 (file)
index 0000000..537fb89
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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
+ */
+/**
+ * Package holding data binding components implemented on top of MD-SAL APIs.
+ */
+package org.opendaylight.restconf.nb.rfc8040.databind.mdsal;
\ No newline at end of file
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/package-info.java
new file mode 100644 (file)
index 0000000..b21c3f7
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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
+ */
+/**
+ * Package holding concepts related to data binding.
+ */
+package org.opendaylight.restconf.nb.rfc8040.databind;
\ No newline at end of file
index 56454db073aea37c4ed7bd3acf5d14d95b48add0..b8444132fd7503f51113a924fe9814868afb4300 100644 (file)
@@ -137,7 +137,8 @@ public class SchemaContextHandler implements EffectiveModelContextListener, Auto
         }
     }
 
-    public EffectiveModelContext get() {
+    @VisibleForTesting
+    EffectiveModelContext get() {
         return schemaContext;
     }
 
index df32403ee822a9113dda8ccfb8db044d362d084d..72ceafb08503920f0e5bc0bcb1fb9f16fe4e6d07 100644 (file)
@@ -11,7 +11,7 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 
@@ -19,9 +19,9 @@ import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
  * Common superclass for readers producing {@link NormalizedNodePayload}.
  */
 abstract class AbstractNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider<NormalizedNodePayload> {
-    AbstractNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler,
+    AbstractNormalizedNodeBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     public final void injectParams(final UriInfo uriInfo, final Request request) {
index 8d42c494db0e396acbddd4cd76ce49579ca512a7..66962650a569127ea270ca9e30f3ad73c7dd1c5a 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -51,9 +51,9 @@ import org.slf4j.LoggerFactory;
 public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
 
-    public JsonNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler,
+    public JsonNormalizedNodeBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
index bc192d7759e586a850cfdeb261c7bec08db6afc9..49a5498c48ddfd4733967750c3421f2d662e054f 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -57,9 +57,9 @@ import org.xml.sax.SAXException;
 public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
 
-    public XmlNormalizedNodeBodyReader(final SchemaContextHandler schemaContextHandler,
+    public XmlNormalizedNodeBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
index 982ff3abc9d052eea5b1296f866bef2200041ca8..e5e4d5ce672c94a540ed6b80e73ece54251cdf43 100644 (file)
@@ -10,12 +10,11 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors;
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Errors;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
 import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory;
 
@@ -32,15 +31,14 @@ final class JsonStreamWriterWithDisabledValidation extends StreamWriterWithDisab
     /**
      * Creation of the custom JSON stream-writer.
      *
-     * @param schemaContextHandler Handler that holds actual schema context.
-     * @param outputWriter         Output stream that is used for creation of JSON writers.
+     * @param databindContext {@link DatabindContext} to use
+     * @param outputWriter    Output stream that is used for creation of JSON writers.
      */
-    JsonStreamWriterWithDisabledValidation(final SchemaContextHandler schemaContextHandler,
+    JsonStreamWriterWithDisabledValidation(final DatabindContext databindContext,
             final OutputStreamWriter outputWriter) {
         jsonWriter = JsonWriterFactory.createJsonWriter(outputWriter, DEFAULT_INDENT_SPACES_NUM);
-        final var inference = errorsContainerInference(schemaContextHandler);
-        jsonNodeStreamWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
-            JSONCodecFactorySupplier.RFC7951.getShared(inference.getEffectiveModelContext()),
+        final var inference = errorsContainerInference(databindContext);
+        jsonNodeStreamWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter(databindContext.jsonCodecs(),
             inference, IETF_RESTCONF_URI, jsonWriter);
     }
 
index 5823da3cdb146a9a8ea09fbb64a7f53d20127ffc..536e163269e9a8a8299a1b910d31576ca68fd641 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors;
 
 import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.$YangModuleInfoImpl.qnameOf;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -33,7 +34,7 @@ import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.Errors;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.errors.Error;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -63,17 +64,18 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
     private static final QName ERROR_PATH_QNAME = qnameOf("error-path");
     static final QName ERROR_INFO_QNAME = qnameOf("error-info");
 
+    private final DatabindProvider databindProvider;
+
     @Context
     private HttpHeaders headers;
-    private final SchemaContextHandler schemaContextHandler;
 
     /**
      * Initialization of the exception mapper.
      *
-     * @param schemaContextHandler Handler that provides actual schema context.
+     * @param databindProvider A {@link DatabindProvider}
      */
-    public RestconfDocumentedExceptionMapper(final SchemaContextHandler schemaContextHandler) {
-        this.schemaContextHandler = schemaContextHandler;
+    public RestconfDocumentedExceptionMapper(final DatabindProvider databindProvider) {
+        this.databindProvider = requireNonNull(databindProvider);
     }
 
     @Override
@@ -170,7 +172,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
              OutputStreamWriter streamStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
         ) {
             return writeNormalizedNode(errorsContainer, outputStream,
-                new JsonStreamWriterWithDisabledValidation(schemaContextHandler, streamStreamWriter));
+                new JsonStreamWriterWithDisabledValidation(databindProvider.currentContext(), streamStreamWriter));
         } catch (IOException e) {
             throw new IllegalStateException("Cannot close some of the output JSON writers", e);
         }
@@ -185,7 +187,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
     private String serializeErrorsContainerToXml(final ContainerNode errorsContainer) {
         try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
             return writeNormalizedNode(errorsContainer, outputStream,
-                new XmlStreamWriterWithDisabledValidation(schemaContextHandler, outputStream));
+                new XmlStreamWriterWithDisabledValidation(databindProvider.currentContext(), outputStream));
         } catch (IOException e) {
             throw new IllegalStateException("Cannot close some of the output XML writers", e);
         }
index 652a83cb78b7f762b72f37639744ab15eccb08dd..8bb1282edf4d9998be95f7686e54f1b893494db7 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors;
 
 import java.io.IOException;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Errors;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.ForwardingNormalizedNodeStreamWriter;
@@ -76,8 +76,8 @@ abstract class StreamWriterWithDisabledValidation extends ForwardingNormalizedNo
      */
     abstract void endNodeWithDisabledValidation() throws IOException;
 
-    static final Inference errorsContainerInference(final SchemaContextHandler schemaContextHandler) {
-        final var stack = SchemaInferenceStack.of(schemaContextHandler.get());
+    static final Inference errorsContainerInference(final DatabindContext databindContext) {
+        final var stack = SchemaInferenceStack.of(databindContext.modelContext());
         stack.enterGrouping(Errors.QNAME);
         return stack.toInference();
     }
index fbf2a09a88cfd19360a393a8966ac2fab23c8268..dcee7a32d13716e2e62ca555bf7160150a50d554 100644 (file)
@@ -15,7 +15,7 @@ import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter;
@@ -37,11 +37,10 @@ final class XmlStreamWriterWithDisabledValidation extends StreamWriterWithDisabl
     /**
      * Creation of the custom XML stream-writer.
      *
-     * @param schemaContextHandler Handler that holds actual schema context.
-     * @param outputStream         Output stream that is used for creation of JSON writers.
+     * @param databindContext {@link DatabindContext} to use
+     * @param outputStream    Output stream that is used for creation of JSON writers.
      */
-    XmlStreamWriterWithDisabledValidation(final SchemaContextHandler schemaContextHandler,
-            final OutputStream outputStream) {
+    XmlStreamWriterWithDisabledValidation(final DatabindContext databindContext, final OutputStream outputStream) {
         try {
             xmlWriter = XML_FACTORY.createXMLStreamWriter(outputStream, StandardCharsets.UTF_8.name());
         } catch (final XMLStreamException | FactoryConfigurationError e) {
@@ -49,7 +48,7 @@ final class XmlStreamWriterWithDisabledValidation extends StreamWriterWithDisabl
         }
 
         xmlNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter,
-            errorsContainerInference(schemaContextHandler));
+            errorsContainerInference(databindContext));
     }
 
     @Override
index 3f12e5a3f6763adc11c4375f3ae076f9a0811267..7ea419e28de1d895168f86dbd279d052e40dd55f 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 
 /**
@@ -19,9 +19,9 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentif
  * @author Robert Varga
  */
 abstract class AbstractPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider<PatchContext> {
-    protected AbstractPatchBodyReader(final SchemaContextHandler schemaContextHandler,
+    protected AbstractPatchBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     @Override
index 95190882a7c97fa0f3c520dd3663bdc4c58165c8..aac27e18e8eea43f85602f2776d2c5410de0d936 100644 (file)
@@ -36,7 +36,7 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -62,9 +62,9 @@ import org.slf4j.LoggerFactory;
 public class JsonPatchBodyReader extends AbstractPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(JsonPatchBodyReader.class);
 
-    public JsonPatchBodyReader(final SchemaContextHandler schemaContextHandler,
+    public JsonPatchBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
index 109c6a77f02c38b463af56dd7c8984c881ea66cd..0059023a61d33241c3723db25ba2e5296cce93ef 100644 (file)
@@ -30,7 +30,7 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -62,9 +62,9 @@ import org.xml.sax.SAXException;
 public class XmlPatchBodyReader extends AbstractPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlPatchBodyReader.class);
 
-    public XmlPatchBodyReader(final SchemaContextHandler schemaContextHandler,
+    public XmlPatchBodyReader(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        super(schemaContextHandler, mountPointService);
+        super(databindProvider, mountPointService);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
index ebf27749669a14508a6e97fe235fa289bc6881a7..369715ab9d06a5b5d959be37a41be225a7f3e9ed 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi;
 
+import static java.util.Objects.requireNonNull;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -23,7 +25,7 @@ import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
@@ -35,12 +37,12 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     @Context
     private Request request;
 
-    private final SchemaContextHandler schemaContextHandler;
+    private final DatabindProvider databindProvider;
     private final DOMMountPointService mountPointService;
 
-    protected AbstractIdentifierAwareJaxRsProvider(final SchemaContextHandler schemaContextHandler,
+    protected AbstractIdentifierAwareJaxRsProvider(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        this.schemaContextHandler = schemaContextHandler;
+        this.databindProvider = requireNonNull(databindProvider);
         this.mountPointService = mountPointService;
     }
 
@@ -94,7 +96,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     }
 
     protected EffectiveModelContext getSchemaContext() {
-        return schemaContextHandler.get();
+        return databindProvider.currentContext().modelContext();
     }
 
     protected DOMMountPointService getMountPointService() {
index 129f45afb8eaf0dd0ce467efb45c9b3e4cd2c06b..7c560bc5fd593eb1f49f5b11c21b14a25014599c 100644 (file)
@@ -50,8 +50,8 @@ import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.ReadDataParams;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
@@ -100,18 +100,18 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     private static final QName NETCONF_BASE_QNAME = SchemaContext.NAME;
 
     private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
-    private final SchemaContextHandler schemaContextHandler;
+    private final DatabindProvider databindProvider;
     private final MdsalRestconfStrategy restconfStrategy;
     private final DOMMountPointService mountPointService;
     private final SubscribeToStreamUtil streamUtils;
     private final DOMActionService actionService;
     private final DOMDataBroker dataBroker;
 
-    public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler,
+    public RestconfDataServiceImpl(final DatabindProvider databindProvider,
             final DOMDataBroker dataBroker, final DOMMountPointService  mountPointService,
             final RestconfStreamsSubscriptionService delegRestconfSubscrService,
             final DOMActionService actionService, final Configuration configuration) {
-        this.schemaContextHandler = requireNonNull(schemaContextHandler);
+        this.databindProvider = requireNonNull(databindProvider);
         this.dataBroker = requireNonNull(dataBroker);
         restconfStrategy = new MdsalRestconfStrategy(dataBroker);
         this.mountPointService = requireNonNull(mountPointService);
@@ -130,7 +130,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     public Response readData(final String identifier, final UriInfo uriInfo) {
         final ReadDataParams readParams = QueryParams.newReadDataParams(uriInfo);
 
-        final EffectiveModelContext schemaContextRef = schemaContextHandler.get();
+        final EffectiveModelContext schemaContextRef = databindProvider.currentContext().modelContext();
         final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(
                 identifier, schemaContextRef, Optional.of(mountPointService));
         final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
@@ -246,8 +246,8 @@ public class RestconfDataServiceImpl implements RestconfDataService {
 
     @Override
     public Response deleteData(final String identifier) {
-        final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(
-                identifier, schemaContextHandler.get(), Optional.of(mountPointService));
+        final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
+            databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
 
         final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
         final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
index d0b58c84ef4e9f34e154a89814cf18fa6b9ccf4e..3e5b0d02a7110f5c60f6fae305e35fefa85e6033 100644 (file)
@@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull;
 import javax.ws.rs.Path;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf;
@@ -25,15 +25,15 @@ import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 public class RestconfImpl implements RestconfService {
     private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern();
 
-    private final SchemaContextHandler schemaContextHandler;
+    private final DatabindProvider databindProvider;
 
-    public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
-        this.schemaContextHandler = requireNonNull(schemaContextHandler);
+    public RestconfImpl(final DatabindProvider databindProvider) {
+        this.databindProvider = requireNonNull(databindProvider);
     }
 
     @Override
     public NormalizedNodePayload getLibraryVersion() {
-        final EffectiveModelContext context = schemaContextHandler.get();
+        final EffectiveModelContext context = databindProvider.currentContext().modelContext();
 
         final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
         // FIXME: use rc:data instantiation once the stack supports it
index ce95a84fb45125bde34dc31a40325d905a49ad20..09ce731ed367cdaedf8b6be4b640471a51378ae7 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
@@ -40,7 +40,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,29 +51,29 @@ import org.slf4j.LoggerFactory;
 public class RestconfOperationsServiceImpl implements RestconfOperationsService {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfOperationsServiceImpl.class);
 
-    private final SchemaContextHandler schemaContextHandler;
+    private final DatabindProvider databindProvider;
     private final DOMMountPointService mountPointService;
 
     /**
-     * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
+     * Set {@link DatabindProvider} for getting actual {@link EffectiveModelContext}.
      *
-     * @param schemaContextHandler handling schema context
-     * @param mountPointService handling dom mount point service
+     * @param databindProvider a {@link DatabindProvider}
+     * @param mountPointService a {@link DOMMountPointService}
      */
-    public RestconfOperationsServiceImpl(final SchemaContextHandler schemaContextHandler,
+    public RestconfOperationsServiceImpl(final DatabindProvider databindProvider,
             final DOMMountPointService mountPointService) {
-        this.schemaContextHandler = requireNonNull(schemaContextHandler);
+        this.databindProvider = requireNonNull(databindProvider);
         this.mountPointService = requireNonNull(mountPointService);
     }
 
     @Override
     public String getOperationsJSON() {
-        return OperationsContent.JSON.bodyFor(schemaContextHandler.get());
+        return OperationsContent.JSON.bodyFor(databindProvider.currentContext().modelContext());
     }
 
     @Override
     public String getOperationsXML() {
-        return OperationsContent.XML.bodyFor(schemaContextHandler.get());
+        return OperationsContent.XML.bodyFor(databindProvider.currentContext().modelContext());
     }
 
     @Override
@@ -88,7 +87,7 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
         }
 
         final InstanceIdentifierContext mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
-            schemaContextHandler.get(), Optional.of(mountPointService));
+            databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
         final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
         final var entry = contextForModelContext(modelContext(mountPoint), mountPoint);
         return NormalizedNodePayload.of(entry.getKey(), entry.getValue());
index 2e619e3d34d404d4721e20c7d57e5d5a9627a46b..0f15f9f776f25c1dd27826d9bae20fa31c8ac881 100644 (file)
@@ -14,11 +14,9 @@ import javax.ws.rs.Path;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * Implementation of {@link RestconfSchemaService}.
@@ -30,7 +28,7 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService {
     private final DOMYangTextSourceProvider sourceProvider;
 
     /**
-     * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
+     * Default constructor.
      *
      * @param schemaService a {@link DOMSchemaService}
      * @param mountPointService a {@link DOMMountPointService}
index 76504f64171ab2e0ad836089a24f17ededbb4d3e..6a99a52c45e7954dd6c0d1db84ac667cd1fe2bd4 100644 (file)
@@ -15,15 +15,15 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,15 +47,13 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      *
      * @param dataBroker {@link DOMDataBroker}
      * @param notificationService {@link DOMNotificationService}
-     * @param schemaHandler
-     *             handler of {@link SchemaContext}
-     * @param configuration
-     *             configuration for restconf {@link Configuration}}
+     * @param databindProvider a {@link DatabindProvider}
+     * @param configuration configuration for RESTCONF {@link Configuration}}
      */
     public RestconfStreamsSubscriptionServiceImpl(final DOMDataBroker dataBroker,
-            final DOMNotificationService notificationService, final SchemaContextHandler schemaHandler,
+            final DOMNotificationService notificationService, final DatabindProvider databindProvider,
             final Configuration configuration) {
-        handlersHolder = new HandlersHolder(dataBroker, notificationService, schemaHandler);
+        handlersHolder = new HandlersHolder(dataBroker, notificationService, databindProvider);
         streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents()
                 : SubscribeToStreamUtil.webSockets();
     }
@@ -76,7 +74,8 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
         }
 
         // prepare node with value of location
-        return NormalizedNodePayload.ofLocation(prepareIIDSubsStreamOutput(handlersHolder.getSchemaHandler()),
+        return NormalizedNodePayload.ofLocation(
+            prepareIIDSubsStreamOutput(handlersHolder.getDatabindProvider().currentContext().modelContext()),
             LOCATION_NODEID, response);
     }
 
@@ -86,9 +85,9 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      * @param schemaHandler Schema context handler.
      * @return InstanceIdentifier of Location leaf.
      */
-    private static InstanceIdentifierContext prepareIIDSubsStreamOutput(final SchemaContextHandler schemaHandler) {
+    private static InstanceIdentifierContext prepareIIDSubsStreamOutput(final EffectiveModelContext modelContext) {
         return InstanceIdentifierContext.ofStack(
-            SchemaInferenceStack.ofDataTreePath(schemaHandler.get(), NOTIFI_QNAME, LOCATION_QNAME));
+            SchemaInferenceStack.ofDataTreePath(modelContext, NOTIFI_QNAME, LOCATION_QNAME));
     }
 
     /**
@@ -98,13 +97,13 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
     public static final class HandlersHolder {
         private final DOMDataBroker dataBroker;
         private final DOMNotificationService notificationService;
-        private final SchemaContextHandler schemaHandler;
+        private final DatabindProvider databindProvider;
 
         private HandlersHolder(final DOMDataBroker dataBroker, final DOMNotificationService notificationService,
-                final SchemaContextHandler schemaHandler) {
+                final DatabindProvider databindProvider) {
             this.dataBroker = dataBroker;
             this.notificationService = notificationService;
-            this.schemaHandler = schemaHandler;
+            this.databindProvider = databindProvider;
         }
 
         /**
@@ -126,12 +125,12 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
         }
 
         /**
-         * Get {@link SchemaContextHandler}.
+         * Get {@link DatabindProvider}.
          *
          * @return the schemaHandler
          */
-        public SchemaContextHandler getSchemaHandler() {
-            return schemaHandler;
+        public DatabindProvider getDatabindProvider() {
+            return databindProvider;
         }
     }
 }
index 2019aff332720709ecd41264b09e136b4e768b74..acbc80e70b6bd107cbf56ac7d1aa59a510b3ab68 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
@@ -128,12 +128,13 @@ abstract class SubscribeToStreamUtil {
                 String.format("Stream with name %s was not found.", streamName),
                 ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT));
 
-        final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get();
+        final EffectiveModelContext schemaContext = handlersHolder.getDatabindProvider().currentContext()
+            .modelContext();
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
         notificationListenerAdapter.setQueryParams(notificationQueryParams);
         notificationListenerAdapter.listen(handlersHolder.getNotificationServiceHandler());
         final DOMDataBroker dataBroker = handlersHolder.getDataBroker();
-        notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getSchemaHandler());
+        notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getDatabindProvider());
         final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
                     notificationListenerAdapter.getSchemaPath().lastNodeIdentifier(),
                     schemaContext.getNotifications(), notificationListenerAdapter.getStart(),
@@ -181,12 +182,12 @@ abstract class SubscribeToStreamUtil {
         listener.setQueryParams(notificationQueryParams);
 
         final DOMDataBroker dataBroker = handlersHolder.getDataBroker();
-        final SchemaContextHandler schemaHandler = handlersHolder.getSchemaHandler();
+        final DatabindProvider schemaHandler = handlersHolder.getDatabindProvider();
         listener.setCloseVars(dataBroker, schemaHandler);
         listener.listen(dataBroker, LogicalDatastoreType.valueOf(datastoreParam));
 
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
-        final EffectiveModelContext schemaContext = schemaHandler.get();
+        final EffectiveModelContext schemaContext = schemaHandler.currentContext().modelContext();
         final String serializedPath = IdentifierCodec.serialize(listener.getPath(), schemaContext);
 
         final MapEntryNode mapToStreams =
index 3a2fc930c79086b4ceafe5bda0a58ab1d9a6ff67..babb22171321d4ffc144ab3d7b3f923936444415 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.slf4j.Logger;
@@ -41,7 +41,7 @@ abstract class AbstractNotificationsData {
 
     private final String localName;
 
-    protected SchemaContextHandler schemaHandler;
+    protected DatabindProvider databindProvider;
     private DOMDataBroker dataBroker;
 
     AbstractNotificationsData(final QName lastQName) {
@@ -52,13 +52,13 @@ abstract class AbstractNotificationsData {
      * Data broker for delete data in DS on close().
      *
      * @param dataBroker creating new write transaction for delete data on close
-     * @param schemaHandler for formatting notifications
+     * @param databindProvider for formatting notifications
      */
     @SuppressWarnings("checkstyle:hiddenField")
     // FIXME: this is pure lifecycle nightmare just because ...
-    public void setCloseVars(final DOMDataBroker dataBroker, final SchemaContextHandler schemaHandler) {
+    public void setCloseVars(final DOMDataBroker dataBroker, final DatabindProvider databindProvider) {
         this.dataBroker = dataBroker;
-        this.schemaHandler = schemaHandler;
+        this.databindProvider = databindProvider;
     }
 
     /**
index 4177ca19a67318316a9a49aa9265c4971dba5d3d..e4fb25796a7bff6e5d6a0f62f22be6a448056abb 100644 (file)
@@ -69,8 +69,8 @@ public class ListenerAdapter extends AbstractCommonSubscriber<YangInstanceIdenti
 
         final Optional<String> maybeData;
         try {
-            maybeData = formatter().eventData(schemaHandler.get(), dataTreeCandidates, now, getLeafNodesOnly(),
-                    isSkipNotificationData());
+            maybeData = formatter().eventData(databindProvider.currentContext().modelContext(), dataTreeCandidates, now,
+                getLeafNodesOnly(), isSkipNotificationData());
         } catch (final Exception e) {
             LOG.error("Failed to process notification {}",
                     dataTreeCandidates.stream().map(Object::toString).collect(Collectors.joining(",")), e);
index 120ac8d78ebad10de0a78d7a2416cb93f30b41f1..fac2efe5a3414f190490114e7faa39630704ccf3 100644 (file)
@@ -56,8 +56,8 @@ public final class NotificationListenerAdapter extends AbstractCommonSubscriber<
 
         final Optional<String> maybeOutput;
         try {
-            maybeOutput = formatter().eventData(schemaHandler.get(), notification, now, getLeafNodesOnly(),
-                    isSkipNotificationData());
+            maybeOutput = formatter().eventData(databindProvider.currentContext().modelContext(), notification, now,
+                getLeafNodesOnly(), isSkipNotificationData());
         } catch (Exception e) {
             LOG.error("Failed to process notification {}", notification, e);
             return;
index 8929b4c333c43890756639513949e1d8b41fc9c0..4089f6f904b8168decdfca5ed619f32927af059f 100644 (file)
   </bean>
 
   <bean id="dataStreamApplication" class="org.opendaylight.restconf.nb.rfc8040.DataStreamApplication">
-    <argument ref="schemaContextHandler"/>
+    <argument ref="databindProvider"/>
     <argument ref="dOMMountPointService"/>
     <argument ref="restconfDataStreamServiceImpl"/>
   </bean>
   <bean id="restconfApplication" class="org.opendaylight.restconf.nb.rfc8040.RestconfApplication">
-    <argument ref="schemaContextHandler"/>
+    <argument ref="databindProvider"/>
     <argument ref="dOMMountPointService"/>
     <argument ref="dOMDataBroker"/>
     <argument ref="dOMRpcService"/>
@@ -75,6 +75,7 @@
     <argument ref="scheduledThreadPool"/>
     <argument ref="configuration"/>
   </bean>
+  <reference id="databindProvider" interface="org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider"/>
   <reference id="customFilterAdapterConfiguration" interface="org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration"/>
   <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer"/>
   <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer"/>
index 1fe3692b49e39a653c30acff57a5a00494acf2ca..230dec0a03c8d9cb834b940c586bedfac77fe416 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
@@ -36,11 +34,6 @@ import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -250,16 +243,4 @@ public final class TestUtils {
                 "some interface"))
             .build();
     }
-
-    public static SchemaContextHandler newSchemaContextHandler(final EffectiveModelContext schemaContext) {
-        DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
-        DOMDataTreeWriteTransaction mockTx = mock(DOMDataTreeWriteTransaction.class);
-        doReturn(CommitInfo.emptyFluentFuture()).when(mockTx).commit();
-        doReturn(mockTx).when(mockDataBroker).newWriteOnlyTransaction();
-
-        SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker,
-            mock(DOMSchemaService.class));
-        schemaContextHandler.onModelContextUpdated(schemaContext);
-        return schemaContextHandler;
-    }
 }
index 7680495c453adbfab3c2f05325816793a96d458c..04c9455ab0f752d14fd92fc5b08ba046cdf4578e 100644 (file)
@@ -51,7 +51,7 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
     public XmlBodyReaderMountPointTest() throws Exception {
         super(schemaContext);
-        xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        xmlBodyReader = new XmlNormalizedNodeBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index c537e6cc460119a29785faa1d224565480416fea..78f64857ea94f4a7f3a5826fad8247a7d93c5fb9 100644 (file)
@@ -30,7 +30,7 @@ import org.junit.runners.Parameterized.Parameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -38,7 +38,6 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.skyscreamer.jsonassert.JSONAssert;
 
@@ -54,13 +53,10 @@ public class RestconfDocumentedExceptionMapperTest {
 
     @BeforeClass
     public static void setupExceptionMapper() {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(
+        final var schemaContext = YangParserTestUtils.parseYangResources(
                 RestconfDocumentedExceptionMapperTest.class, "/restconf/impl/ietf-restconf@2017-01-26.yang",
                 "/instanceidentifier/yang/instance-identifier-patch-module.yang");
-        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
-        doReturn(schemaContext).when(schemaContextHandler).get();
-
-        exceptionMapper = new RestconfDocumentedExceptionMapper(schemaContextHandler);
+        exceptionMapper = new RestconfDocumentedExceptionMapper(() -> DatabindContext.ofModel(schemaContext));
     }
 
     /**
index 9673a4b504f8574a34baad23a2a392cce411592b..28e3f408ddf5a3a2da2d7bcd61e15d12ae78f67a 100644 (file)
@@ -29,7 +29,7 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
     public JsonPatchBodyReaderMountPointTest() throws Exception {
         super(schemaContext);
-        jsonToPatchBodyReader = new JsonPatchBodyReader(schemaContextHandler, mountPointService);
+        jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index d9f42d9978f6247a0f53a38c25545f5c8ba58551..7c557b1dd744625264c4f0d98a65626b4e115f69 100644 (file)
@@ -29,7 +29,7 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
 
     public JsonPatchBodyReaderTest() throws Exception {
         super(schemaContext);
-        jsonToPatchBodyReader = new JsonPatchBodyReader(schemaContextHandler, mountPointService);
+        jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index 54a355e421f8e95e5885d51bc3e2ad9521f67b88..1ab05af6afbee052556331747d34914588f7a8c2 100644 (file)
@@ -30,7 +30,7 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
     public XmlPatchBodyReaderMountPointTest() throws Exception {
         super(schemaContext);
-        xmlToPatchBodyReader = new XmlPatchBodyReader(schemaContextHandler, mountPointService);
+        xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index 96e16d71ebbffa2df60f84ad5975d38d8acc6bef..71a7bee0bf61dc0668f631424f55ea4c537a25df 100644 (file)
@@ -27,7 +27,7 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
 
     public XmlPatchBodyReaderTest() throws Exception {
         super(schemaContext);
-        xmlToPatchBodyReader = new XmlPatchBodyReader(schemaContextHandler, mountPointService);
+        xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index fe32b1c69cb4ba8e0a5160be567797c583cc1f1e..f9aa84238de09b675e05da19a366a29bc6c20688 100644 (file)
@@ -32,8 +32,8 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.TestUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -43,17 +43,18 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public abstract class AbstractBodyReaderTest {
     protected final MediaType mediaType;
-    protected final SchemaContextHandler schemaContextHandler;
+    protected final DatabindProvider databindProvider;
     protected final DOMMountPointService mountPointService;
 
     protected AbstractBodyReaderTest(final EffectiveModelContext schemaContext) throws NoSuchFieldException,
             IllegalAccessException {
         mediaType = getMediaType();
 
-        schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
+        final var databindContext = DatabindContext.ofModel(schemaContext);
+        databindProvider = () -> databindContext;
 
         mountPointService = mock(DOMMountPointService.class);
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+        final var mountPoint = mock(DOMMountPoint.class);
         doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
         doReturn(Optional.of(FixedDOMSchemaService.of(schemaContext))).when(mountPoint)
             .getService(DOMSchemaService.class);
index bea7f8d017b5a9215db4c067d940597b783e728f..5301f659a4e1858389dbf8088425debabeb22a7f 100644 (file)
@@ -50,7 +50,7 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
 
     public JsonBodyReaderTest() throws Exception {
         super(schemaContext);
-        jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        jsonBodyReader = new JsonNormalizedNodeBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index 90db4c358db9ed7e5a0cf502f3b6241dd6c15a3a..c37274920b7f6c862c06bd72ea1272f98b718ff9 100644 (file)
@@ -62,7 +62,7 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
 
     public XmlBodyReaderTest() throws Exception {
         super(schemaContext);
-        xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        xmlBodyReader = new XmlNormalizedNodeBodyReader(databindProvider, mountPointService);
     }
 
     @Override
index 9b362ca00e980f23e1b6151e442bfd20e138115f..e1402a9207bf68222057334c7ea5b71841ca7ef2 100644 (file)
@@ -24,11 +24,10 @@ import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
@@ -61,18 +60,15 @@ public class Netconf799Test {
             TestRestconfUtils.loadFiles("/instanceidentifier/yang"));
 
         final DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
-        final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker,
-            mock(DOMSchemaService.class));
-        schemaContextHandler.onModelContextUpdated(contextRef);
 
         final DOMActionService actionService = mock(DOMActionService.class);
         doReturn(Futures.immediateFuture(new SimpleDOMActionResult(
             Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build())))
             .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
 
-        final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker,
-            mock(DOMMountPointService.class), mock(RestconfStreamsSubscriptionService.class),
-            actionService, mock(Configuration.class));
+        final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl(
+            () -> DatabindContext.ofModel(contextRef), mockDataBroker, mock(DOMMountPointService.class),
+            mock(RestconfStreamsSubscriptionService.class), actionService, mock(Configuration.class));
 
         final var nodeAndStack = DataSchemaContextTree.from(contextRef).enterPath(ACTION_YII).orElseThrow();
         final var node = nodeAndStack.node().getDataSchemaNode();
index 61897a1b16846a28e73c3bfacaf349bef6046916..5b37353bfdec8e88da75945f9f835e317bc53f0b 100644 (file)
@@ -59,7 +59,7 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
@@ -182,23 +182,16 @@ public class RestconfDataServiceImplTest {
                 .node(baseQName)
                 .build();
 
-        contextRef =
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
+        contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
 
-        doReturn(CommitInfo.emptyFluentFuture()).when(write).commit();
         doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
 
         DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
         doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
         doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
-        doReturn(write).when(mockDataBroker).newWriteOnlyTransaction();
 
-        final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(
-                mockDataBroker, mock(DOMSchemaService.class));
-
-        schemaContextHandler.onModelContextUpdated(contextRef);
-        dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mountPointService,
-                delegRestconfSubscrService, actionService, configuration);
+        dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(contextRef), mockDataBroker,
+                mountPointService, delegRestconfSubscrService, actionService, configuration);
         doReturn(Optional.of(mountPoint)).when(mountPointService)
                 .getMountPoint(any(YangInstanceIdentifier.class));
         doReturn(Optional.of(FixedDOMSchemaService.of(contextRef))).when(mountPoint)
index 63aa890a82f746a0c0b7332e8fc3527e0d909775..d980ce819e4689c770ef24629c5aae233a561a53 100644 (file)
@@ -12,8 +12,7 @@ import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.TestUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@@ -21,9 +20,8 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 public class RestconfImplTest {
     @Test
     public void restImplTest() throws Exception {
-        final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(
-            YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl")));
-        final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
+        final var context = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl"));
+        final RestconfImpl restconfImpl = new RestconfImpl(() -> DatabindContext.ofModel(context));
         final NormalizedNodePayload libraryVersion = restconfImpl.getLibraryVersion();
         final LeafNode<?> value = (LeafNode<?>) libraryVersion.getData();
         assertEquals(IetfYangLibrary.REVISION.toString(), value.body());
index e65a8cdbba9550c9864a078bc6f7bf8efcf1fd49..dbf41112073e008a3dd167cb131b3b8143171e58 100644 (file)
@@ -16,16 +16,15 @@ import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.TestUtils;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RestconfOperationsServiceTest {
     @Test
     public void getOperationsTest() throws IOException {
-        final var oper = new RestconfOperationsServiceImpl(
-            TestUtils.newSchemaContextHandler(
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"))),
+        final var context = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
+        final var oper = new RestconfOperationsServiceImpl(() -> DatabindContext.ofModel(context),
             mock(DOMMountPointService.class));
 
         assertEquals("{\n"
index d7d85aed16ae6a55c093ba044959e1117f265521..6f52bdbdf8729433e0236397667efd3f8d410105 100644 (file)
@@ -32,10 +32,10 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
@@ -49,6 +49,7 @@ import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -67,7 +68,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     private Configuration configurationWs;
     private Configuration configurationSse;
 
-    private SchemaContextHandler schemaHandler;
+    private EffectiveModelContext modelContext;
+    private DatabindProvider databindProvider;
 
     @Before
     public void setUp() throws FileNotFoundException, URISyntaxException {
@@ -75,8 +77,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         doReturn(wTx).when(dataBroker).newWriteOnlyTransaction();
         doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
 
-        schemaHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class));
-
         DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
         doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService)
                 .registerDataTreeChangeListener(any(), any());
@@ -88,8 +88,9 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         // FIXME: just mock UriInfo here
         doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder();
         doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath();
-        schemaHandler.onModelContextUpdated(
-            YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
+
+        modelContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications"));
+        databindProvider = () -> DatabindContext.ofModel(modelContext);
         configurationWs = new Configuration(0, 100, 10, false);
         configurationSse = new Configuration(0, 100, 10, true);
     }
@@ -112,12 +113,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamSSE() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationSse);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationSse);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("http://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
@@ -129,12 +130,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamWS() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("ws://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
@@ -145,8 +146,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamMissingDatastoreInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final var errors = assertThrows(RestconfDocumentedException.class,
             () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", uriInfo))
             .getErrors();
@@ -160,8 +161,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamMissingScopeInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final var errors = assertThrows(RestconfDocumentedException.class,
             () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
                 uriInfo)).getErrors();
index 48a33593addd5fecdd10fcc4ab8f795f42fcd8d2..7f7e0ef8bc709e4e723c47b0f09550b7298eaf1b 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.streams.listeners;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
 
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.io.IOException;
@@ -34,12 +33,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam;
 import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam;
 import org.opendaylight.restconf.nb.rfc8040.StartTimeParam;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.yang.gen.v1.augment.instance.identifier.patch.module.rev220218.PatchCont1Builder;
 import org.opendaylight.yang.gen.v1.augment.instance.identifier.patch.module.rev220218.patch.cont.patch.choice1.PatchCase1Builder;
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont;
@@ -96,12 +95,11 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     private DataBroker dataBroker;
     private DOMDataBroker domDataBroker;
-    private SchemaContextHandler schemaContextHandler;
+    private DatabindProvider databindProvider;
 
     @BeforeClass
     public static void beforeClass() {
-        SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory(
-                "/instanceidentifier/yang");
+        SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/instanceidentifier/yang");
     }
 
     @AfterClass
@@ -113,9 +111,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void setUp() throws Exception {
         dataBroker = getDataBroker();
         domDataBroker = getDomBroker();
-
-        schemaContextHandler = new SchemaContextHandler(domDataBroker, mock(DOMSchemaService.class));
-        schemaContextHandler.onModelContextUpdated(SCHEMA_CONTEXT);
+        databindProvider = () -> DatabindContext.ofModel(SCHEMA_CONTEXT);
     }
 
     class ListenerAdapterTester extends ListenerAdapter {
@@ -208,7 +204,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testJsonNotifsLeaves() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
             true, false);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         final DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
@@ -256,7 +252,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testJsonNotifs() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
             false, false);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         final DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
@@ -288,7 +284,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testJsonNotifsWithoutData() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
             false, true);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
@@ -318,7 +314,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testXmlNotifications() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
             false, false);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
@@ -348,7 +344,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testXmlSkipData() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
             false, true);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
@@ -378,7 +374,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     public void testXmlLeavesOnly() throws Exception {
         ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
             true, false);
-        adapter.setCloseVars(domDataBroker, schemaContextHandler);
+        adapter.setCloseVars(domDataBroker, databindProvider);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);