Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / osgi / Activator.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.yangtools.yang.data.impl.osgi;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
12 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
13 import org.osgi.framework.BundleActivator;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceRegistration;
16
17 /**
18  * YANG data implementation activator. Publishes a {@link DataTreeFactory} implementation on bundle start.
19  *
20  * @author Robert Varga
21  */
22 public final class Activator implements BundleActivator {
23     private ServiceRegistration<@NonNull DataTreeFactory> registration;
24
25     @Override
26     public void start(final BundleContext context) throws Exception {
27         registration = context.registerService(DataTreeFactory.class, new InMemoryDataTreeFactory(), null);
28     }
29
30     @Override
31     public void stop(final BundleContext context) throws Exception {
32         if (registration != null) {
33             registration.unregister();
34             registration = null;
35         }
36     }
37 }