2 * Copyright (c) 2013 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.manager.impl.osgi.mapping;
10 import javassist.ClassPool;
11 import org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil;
12 import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
13 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
14 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
15 import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
17 import org.osgi.framework.BundleContext;
20 * Creates and initializes {@link RuntimeGeneratedMappingServiceImpl}, which is used to get {@link CodecRegistry}.
21 * Also maintains service registrations of {@link RuntimeGeneratedMappingServiceImpl}.
23 // TODO move to yang runtime
24 public class CodecRegistryProvider implements AutoCloseable {
25 private static final ClassPool CLASS_POOL = ClassPool.getDefault();
27 private final RuntimeGeneratedMappingServiceImpl service;
28 private final AutoCloseable registration;
30 public CodecRegistryProvider(final ClassLoadingStrategy classLoadingStrategy, final BundleContext context) {
31 service = new RuntimeGeneratedMappingServiceImpl(CLASS_POOL, classLoadingStrategy);
32 registration = OsgiRegistrationUtil.registerService(context, service,
33 SchemaContextListener.class, BindingIndependentMappingService.class);
36 public CodecRegistry getCodecRegistry() {
37 return service.getCodecRegistry();
41 public void close() throws Exception {