/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.config.manager.impl.osgi.mapping;

import javassist.ClassPool;
import org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil;
import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
import org.osgi.framework.BundleContext;

/**
 * Creates and initializes {@link RuntimeGeneratedMappingServiceImpl}, which is used to get {@link CodecRegistry}.
 * Also maintains service registrations of {@link RuntimeGeneratedMappingServiceImpl}.
 */
// TODO move to yang runtime
public class CodecRegistryProvider implements AutoCloseable {
    private static final ClassPool CLASS_POOL = ClassPool.getDefault();

    private final RuntimeGeneratedMappingServiceImpl service;
    private final AutoCloseable registration;

    public CodecRegistryProvider(ClassLoadingStrategy classLoadingStrategy, BundleContext context) {
        service = new RuntimeGeneratedMappingServiceImpl(classLoadingStrategy);
        service.setPool(CLASS_POOL);
        service.init();
        registration = OsgiRegistrationUtil.registerService(context, service,
                SchemaServiceListener.class, BindingIndependentMappingService.class);
    }

    public CodecRegistry getCodecRegistry() {
        return service.getCodecRegistry();
    }

    @Override
    public void close() throws Exception {
        registration.close();
    }
}

@@ -400,16 +400,17 @@
 ssPool;%0A
+%0A
 import o
@@ -1451,16 +1451,22 @@
 rovider(
+final 
 ClassLoa
@@ -1499,16 +1499,22 @@
 trategy,
+ final
  BundleC
@@ -1588,16 +1588,28 @@
 iceImpl(
+CLASS_POOL, 
 classLoa
@@ -1627,69 +1627,8 @@
 y);%0A
-        service.setPool(CLASS_POOL);%0A        service.init();%0A
     

remove the use of Javassist.init()