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