2 * Copyright (c) 2014 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.sal.binding.osgi;
10 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
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.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
18 import java.util.Hashtable;
20 public class Activator implements BundleActivator {
22 private ServiceRegistration<?> reg;
23 private ServiceRegistration<SchemaServiceListener> listenerReg;
24 private ServiceRegistration<BindingIndependentMappingService> mappingReg;
27 public void start(BundleContext context) throws Exception {
28 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
29 service.setPool(SingletonHolder.CLASS_POOL);
31 startRuntimeMappingService(service, context);
34 private void startRuntimeMappingService(RuntimeGeneratedMappingServiceImpl service, BundleContext context) {
35 Hashtable<String, String> properties = new Hashtable<String, String>();
36 listenerReg = context.registerService(SchemaServiceListener.class, service, properties);
37 mappingReg = context.registerService(BindingIndependentMappingService.class, service, properties);
42 public void stop(BundleContext context) throws Exception {
43 if(listenerReg != null) {
44 listenerReg.unregister();
46 if(mappingReg != null) {
47 mappingReg.unregister();