2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.impl.osgi.mapping;
10 import javassist.ClassPool;
11 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
12 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
13 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceRegistration;
17 import java.util.Hashtable;
19 public class RuntimeGeneratedMappingServiceActivator implements AutoCloseable {
21 private static final ClassPool CLASS_POOL = ClassPool.getDefault();
23 private ServiceRegistration<SchemaServiceListener> listenerReg;
24 private ServiceRegistration<BindingIndependentMappingService> mappingReg;
25 private ModuleInfoBundleTracker moduleInfoBundleTracker;
27 public RuntimeGeneratedMappingServiceActivator(ModuleInfoBundleTracker moduleInfoBundleTracker) {
28 this.moduleInfoBundleTracker = moduleInfoBundleTracker;
31 public RuntimeGeneratedMappingServiceImpl startRuntimeMappingService(BundleContext context) {
32 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl(moduleInfoBundleTracker.getModuleInfoLoadingStrategy());
33 service.setPool(CLASS_POOL);
35 startRuntimeMappingService(service, context);
39 private void startRuntimeMappingService(RuntimeGeneratedMappingServiceImpl service, BundleContext context) {
40 Hashtable<String, String> properties = new Hashtable<String, String>();
41 listenerReg = context.registerService(SchemaServiceListener.class, service, properties);
42 mappingReg = context.registerService(BindingIndependentMappingService.class, service, properties);
47 public void close() throws Exception {
48 mappingReg.unregister();
49 listenerReg.unregister();