Resolve Bug:448 - Remove yang-store api and impl.
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / mapping / CodecRegistryProvider.java
diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/CodecRegistryProvider.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/CodecRegistryProvider.java
new file mode 100644 (file)
index 0000000..9d0fbd8
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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();
+    }
+}