Bug 5526 - Added new servlet to the web.xml for new restconf
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / rest / RestConnectorProvider.java
index 7b2a3b65ad576bad346593c72378429a376d58c8..5cca1deca7d558fcd2b2c24e3ce58488445dc5dc 100644 (file)
@@ -16,6 +16,9 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
 
 /**
  * Provider for restconf draft11.
@@ -28,6 +31,16 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose
     @Override
     public void onSessionInitiated(final ProviderSession session) {
         final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class));
+        final RestconfApplication restApp = getObjectFromBundleContext(RestconfApplication.class,
+                RestconfApplicationService.class.getName());
+        Preconditions.checkNotNull(restApp, "RestconfApplication service doesn't exist.");
+        this.listenerRegistration = schemaService.registerSchemaContextListener(restApp.getSchemaContextHandler());
+    }
+
+    private <T> T getObjectFromBundleContext(final Class<T> type, final String serviceRefName) {
+        final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
+        final ServiceReference<?> serviceReference = bundleContext.getServiceReference(serviceRefName);
+        return (T) bundleContext.getService(serviceReference);
     }
 
     @Override