Fix NPE when trying to download restconf provided yang files
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / services / simple / impl / RestconfSchemaServiceImpl.java
index e19e9db38945b78de8b1e349d102f30dfdfcd1c3..e93c66827cd9a9d45328ede5f4fed1087eb4f5d1 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.simple.impl;
 
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -21,8 +22,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final DOMMountPointServiceHandler domMountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private DOMMountPointServiceHandler domMountPointServiceHandler;
+    private DOMYangTextSourceProvider sourceProvider;
 
     /**
      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}
@@ -34,15 +36,30 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService {
      *             handling dom mount point service
      */
     public RestconfSchemaServiceImpl(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointServiceHandler domMountPointServiceHandler) {
+                                     final DOMMountPointServiceHandler domMountPointServiceHandler,
+                                     final DOMYangTextSourceProvider sourceProvider) {
         this.schemaContextHandler = schemaContextHandler;
         this.domMountPointServiceHandler = domMountPointServiceHandler;
+        this.sourceProvider = sourceProvider;
     }
 
     @Override
     public SchemaExportContext getSchema(final String identifier) {
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
-                this.domMountPointServiceHandler.get());
+                this.domMountPointServiceHandler.get(), sourceProvider);
+    }
+
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            } else if (object instanceof DOMYangTextSourceProvider) {
+                sourceProvider = (DOMYangTextSourceProvider) object;
+            }
+        }
     }
 }