Merge "Refactor Additional header for netconf hello message."
[controller.git] / opendaylight / md-sal / sal-restconf-broker / src / main / java / org / opendaylight / controller / sal / restconf / broker / osgi / Activator.java
1 /*
2  * Copyright (c) 2013 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.sal.restconf.broker.osgi;
9
10 import java.util.Hashtable;
11 import javassist.ClassPool;
12 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
13 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
17
18 public class Activator implements BundleActivator {
19
20     private ServiceRegistration<BindingIndependentMappingService> mappingReg;
21
22     @Override
23     public void start(BundleContext context) throws Exception {
24         RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
25         service.setPool(new ClassPool());
26         service.init();
27         startRuntimeMappingService(service, context);
28     }
29
30     private void startRuntimeMappingService(RuntimeGeneratedMappingServiceImpl service, BundleContext context) {
31         Hashtable<String, String> properties = new Hashtable<String, String>();
32         mappingReg = context.registerService(BindingIndependentMappingService.class, service, properties);
33     }
34
35     @Override
36     public void stop(BundleContext context) throws Exception {
37         if(mappingReg != null) {
38             mappingReg.unregister();
39         }
40     }
41 }