Remove BindingRuntimeContext{Listener,Service}
[mdsal.git] / binding / mdsal-binding-dom-codec-osgi / src / main / java / org / opendaylight / mdsal / binding / dom / codec / osgi / impl / BindingClassLoadingStrategy.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, 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.mdsal.binding.dom.codec.osgi.impl;
9
10 import org.opendaylight.binding.runtime.api.ClassLoadingStrategy;
11 import org.opendaylight.binding.runtime.spi.GeneratedClassLoadingStrategy;
12 import org.opendaylight.binding.runtime.spi.ModuleInfoBackedContext;
13 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
14 import org.osgi.service.component.ComponentContext;
15 import org.osgi.service.component.annotations.Activate;
16 import org.osgi.service.component.annotations.Component;
17 import org.osgi.service.component.annotations.Deactivate;
18 import org.osgi.service.component.annotations.Reference;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Component(immediate = true)
23 public final class BindingClassLoadingStrategy implements ClassLoadingStrategy {
24     private static final Logger LOG = LoggerFactory.getLogger(BindingClassLoadingStrategy.class);
25
26     @Reference
27     YangParserFactory factory = null;
28
29     private ModuleInfoBundleTracker bundleTracker = null;
30     private ModuleInfoBackedContext moduleInfoBackedContext = null;
31
32     @Activate
33     void activate(final ComponentContext ctx) {
34         LOG.info("Binding-DOM codec starting");
35
36         moduleInfoBackedContext = ModuleInfoBackedContext.create("binding-dom-codec", factory,
37             // FIXME: This is the fallback strategy, it should not be needed
38             GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
39
40         final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
41                 moduleInfoBackedContext);
42
43         LOG.debug("Starting Binding-DOM codec bundle tracker");
44         bundleTracker = new ModuleInfoBundleTracker(ctx.getBundleContext(), registry);
45         bundleTracker.open();
46
47         LOG.info("Binding-DOM codec started");
48     }
49
50     @Deactivate
51     void deactivate() {
52         LOG.info("Binding-DOM codec stopping");
53         LOG.debug("Stopping Binding-DOM codec bundle tracker");
54         bundleTracker.close();
55         moduleInfoBackedContext = null;
56         bundleTracker = null;
57         LOG.info("Binding-DOM codec stopped");
58     }
59
60     @Override
61     public Class<?> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
62         return moduleInfoBackedContext.loadClass(fullyQualifiedName);
63     }
64 }