import org.opendaylight.netconf.sal.rest.api.RestConnector;
import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler;
import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl;
+import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl;
+import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl;
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.
@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.");
- final SchemaContextHandler schemaContextHandler = restApp.getSchemaContextHandler();
- final DOMMountPointServiceHandler domMountPointServiceHandler = restApp.getDOMMountPointServiceHandler();
+ final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl();
+ final SchemaContextHandler schemaCtxHandler = new SchemaContextHandlerImpl();
domMountPointServiceHandler.setDOMMountPointService(session.getService(DOMMountPointService.class));
+ final Draft11ServicesWrapperImpl wrapperServices = Draft11ServicesWrapperImpl.getInstance();
+ this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
- this.listenerRegistration = schemaService.registerSchemaContextListener(schemaContextHandler);
- }
-
- 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);
+ wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler);
}
@Override
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl;
-import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl;
import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl;
-import org.osgi.framework.FrameworkUtil;
-public class RestconfApplication extends Application implements RestconfApplicationService {
-
- private final SchemaContextHandler schemaContextHandler;
- private final DOMMountPointServiceHandler domMountPointServiceHandler;
-
- public RestconfApplication() {
- this.schemaContextHandler = new SchemaContextHandlerImpl();
- this.domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl();
- FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(RestconfApplicationService.class.getName(),
- this, null);
- }
+public class RestconfApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
@Override
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
- singletons.add(this.schemaContextHandler);
- singletons.add(new Draft11ServicesWrapperImpl(this.schemaContextHandler, this.domMountPointServiceHandler));
+ singletons.add(Draft11ServicesWrapperImpl.getInstance());
return singletons;
}
-
- @Override
- public SchemaContextHandler getSchemaContextHandler() {
- return this.schemaContextHandler;
- }
-
- @Override
- public DOMMountPointServiceHandler getDOMMountPointServiceHandler() {
- return this.domMountPointServiceHandler;
- }
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.rest;
-
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.osgi.framework.BundleContext;
-
-/**
- * Interface for register RestconfApplication service via {@link BundleContext}.
- *
- */
-public interface RestconfApplicationService {
-
- /**
- * Get {@link SchemaContextHandler} via service. Actually use by
- * {@link RestConnectorProvider} to register {@link SchemaContextListener}
- * of {@link SchemaContextHandler}.
- *
- * @return {@link SchemaContextHandler}
- */
- SchemaContextHandler getSchemaContextHandler();
-
- /**
- * Get {@link DOMMountPointServiceHandler} via service. Actually use by
- * {@link RestConnectorProvider} to set {@link DOMMountPointService}.
- *
- * @return {@link DOMMountPointServiceHandler}
- */
- DOMMountPointServiceHandler getDOMMountPointServiceHandler();
-}
import org.opendaylight.restconf.rest.api.services.RestconfStreamsService;
import org.opendaylight.restconf.rest.api.services.schema.RestconfSchemaService;
import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
* Implementation of {@link Draft11ServicesWrapper}
*/
public class Draft11ServicesWrapperImpl implements Draft11ServicesWrapper {
- private final RestconfModulesService delegRestModService;
- private final RestconfOperationsService delegRestOpsService;
- private final RestconfStreamsService delegRestStrsService;
- private final RestconfSchemaService delegRestSchService;
+ private RestconfModulesService delegRestModService;
+ private RestconfOperationsService delegRestOpsService;
+ private RestconfStreamsService delegRestStrsService;
+ private RestconfSchemaService delegRestSchService;
- /**
- * Creating delegates to all implemented services
- *
- * @param schemaContextHandler
- * - for handling {@link SchemaContext}
- * @param domMountPointServiceHandler
- * - for handling {@link DOMMountPointServiceHandler}
- */
- public Draft11ServicesWrapperImpl(final SchemaContextHandler schemaContextHandler,
- final DOMMountPointServiceHandler domMountPointServiceHandler) {
- this.delegRestModService = new RestconfModulesServiceImpl(schemaContextHandler, domMountPointServiceHandler);
- this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaContextHandler, domMountPointServiceHandler);
- this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaContextHandler);
- this.delegRestSchService = new RestconfSchemaServiceImpl(schemaContextHandler, domMountPointServiceHandler);
+ private Draft11ServicesWrapperImpl() {
}
@Override
return this.delegRestSchService.getSchema(mountAndModuleId);
}
+ public static Draft11ServicesWrapperImpl getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ private static class InstanceHolder {
+ public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
+ }
+
+ public void setHandlers(final SchemaContextHandler schemaCtxHandler,
+ final DOMMountPointServiceHandler domMountPointServiceHandler) {
+ this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
+ }
+
}