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
9 package org.opendaylight.controller.config.manager.impl.osgi.mapping;
11 import org.opendaylight.yangtools.concepts.ObjectRegistration;
12 import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
13 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
14 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
18 import java.util.Hashtable;
21 * Update SchemaContext service in Service Registry each time new YangModuleInfo is added or removed.
23 public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, AutoCloseable {
25 private final ModuleInfoRegistry moduleInfoRegistry;
26 private final ServiceRegistration<SchemaContextProvider> osgiReg;
28 public RefreshingSCPModuleInfoRegistry(ModuleInfoRegistry moduleInfoRegistry,
29 SchemaContextProvider schemaContextProvider, BundleContext bundleContext) {
30 this.moduleInfoRegistry = moduleInfoRegistry;
31 osgiReg = bundleContext.registerService(SchemaContextProvider.class, schemaContextProvider, new Hashtable<String, String>());
34 private void updateService() {
35 osgiReg.setProperties(null); // send modifiedService event
39 public ObjectRegistration<YangModuleInfo> registerModuleInfo(YangModuleInfo yangModuleInfo) {
40 ObjectRegistration<YangModuleInfo> yangModuleInfoObjectRegistration = moduleInfoRegistry.registerModuleInfo(yangModuleInfo);
41 ObjectRegistrationWrapper wrapper = new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration);
52 private class ObjectRegistrationWrapper implements ObjectRegistration<YangModuleInfo> {
53 private final ObjectRegistration<YangModuleInfo> inner;
55 private ObjectRegistrationWrapper(ObjectRegistration<YangModuleInfo> inner) {
60 public YangModuleInfo getInstance() {
61 return inner.getInstance();
65 public void close() throws Exception {
67 updateService();// send modify event when a bundle disappears
72 public String toString() {
73 return inner.toString();