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.config.yang.md.sal.binding.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.Hashtable;
12 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
13 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
14 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
15 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
16 import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.ServiceReference;
24 public final class RuntimeMappingModule extends AbstractRuntimeMappingModule {
26 private BundleContext bundleContext;
28 public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
30 super(identifier, dependencyResolver);
33 public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
34 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
35 final RuntimeMappingModule oldModule, final java.lang.AutoCloseable oldInstance) {
36 super(identifier, dependencyResolver, oldModule, oldInstance);
40 public void validate() {
42 Preconditions.checkNotNull(bundleContext);
43 // Add custom validation for module attributes here.
47 public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) {
52 public java.lang.AutoCloseable createInstance() {
53 final GeneratedClassLoadingStrategy classLoading = getGlobalClassLoadingStrategy();
54 BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
55 BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(classLoading, codecRegistry);
56 bundleContext.registerService(SchemaContextListener.class, instance, new Hashtable<String,String>());
60 private GeneratedClassLoadingStrategy getGlobalClassLoadingStrategy() {
61 ServiceReference<GeneratedClassLoadingStrategy> ref = bundleContext.getServiceReference(GeneratedClassLoadingStrategy.class);
62 return bundleContext.getService(ref);
65 public void setBundleContext(final BundleContext bundleContext) {
66 this.bundleContext = bundleContext;