2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.binding.dom.codec.osgi.impl;
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.framework.BundleContext;
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;
22 @Component(immediate = true)
23 public final class BindingClassLoadingStrategy implements ClassLoadingStrategy {
24 private static final Logger LOG = LoggerFactory.getLogger(BindingClassLoadingStrategy.class);
27 YangParserFactory factory = null;
29 private ModuleInfoBundleTracker bundleTracker = null;
30 private ModuleInfoBackedContext moduleInfoBackedContext = null;
33 void activate(final BundleContext ctx) {
34 LOG.info("Binding-DOM codec starting");
36 moduleInfoBackedContext = ModuleInfoBackedContext.create("binding-dom-codec", factory,
37 // FIXME: This is the fallback strategy, it should not be needed
38 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
40 final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
41 moduleInfoBackedContext);
43 LOG.debug("Starting Binding-DOM codec bundle tracker");
44 bundleTracker = new ModuleInfoBundleTracker(ctx, registry);
47 LOG.info("Binding-DOM codec started");
52 LOG.info("Binding-DOM codec stopping");
53 LOG.debug("Stopping Binding-DOM codec bundle tracker");
54 bundleTracker.close();
55 moduleInfoBackedContext = null;
57 LOG.info("Binding-DOM codec stopped");
61 public Class<?> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
62 return moduleInfoBackedContext.loadClass(fullyQualifiedName);