Expose default module instances into OSGi
[controller.git] / opendaylight / md-sal / sal-binding-config / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModuleFactory.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
9
10 import org.opendaylight.controller.config.api.DependencyResolver;
11 import org.osgi.framework.BundleContext;
12
13 import static com.google.common.base.Preconditions.checkArgument;
14
15 /**
16  *
17  */
18 public class RuntimeMappingModuleFactory extends
19         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModuleFactory {
20
21     public static final String SINGLETON_NAME = "runtime-mapping-singleton";
22
23     @Override
24     public RuntimeMappingModule instantiateModule(String instanceName, DependencyResolver dependencyResolver, RuntimeMappingModule  oldModule, AutoCloseable oldInstance, BundleContext bundleContext) {
25         checkArgument(SINGLETON_NAME.equals(instanceName),"Illegal instance name '" + instanceName + "', only allowed name is " + SINGLETON_NAME);
26         RuntimeMappingModule module = super.instantiateModule(instanceName, dependencyResolver, oldModule, oldInstance, bundleContext);
27         // FIXME bundle context should not be passed around
28         module.setBundleContext(bundleContext);
29         return module;
30     }
31
32     @Override
33     public RuntimeMappingModule  instantiateModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) {
34         checkArgument(SINGLETON_NAME.equals(instanceName),"Illegal instance name '" + instanceName + "', only allowed name is " + SINGLETON_NAME);
35         RuntimeMappingModule module = super.instantiateModule(instanceName, dependencyResolver, bundleContext);
36         // FIXME bundle context should not be passed around
37         module.setBundleContext(bundleContext);
38         return module;
39     }
40 }