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 java.util.Hashtable;
12 import org.opendaylight.yangtools.concepts.ObjectRegistration;
13 import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
14 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceRegistration;
20 * Update SchemaContext service in Service Registry each time new YangModuleInfo is added or removed.
22 public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, AutoCloseable {
24 private final ModuleInfoRegistry moduleInfoRegistry;
25 private final ServiceRegistration<SchemaContextProvider> osgiReg;
27 public RefreshingSCPModuleInfoRegistry(ModuleInfoRegistry moduleInfoRegistry,
28 SchemaContextProvider schemaContextProvider, BundleContext bundleContext) {
29 this.moduleInfoRegistry = moduleInfoRegistry;
30 osgiReg = bundleContext.registerService(SchemaContextProvider.class, schemaContextProvider, new Hashtable<String, String>());
33 private void updateService() {
34 osgiReg.setProperties(null); // send modifiedService event
38 public ObjectRegistration<YangModuleInfo> registerModuleInfo(YangModuleInfo yangModuleInfo) {
39 ObjectRegistration<YangModuleInfo> yangModuleInfoObjectRegistration = moduleInfoRegistry.registerModuleInfo(yangModuleInfo);
40 ObjectRegistrationWrapper wrapper = new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration);
51 private class ObjectRegistrationWrapper implements ObjectRegistration<YangModuleInfo> {
52 private final ObjectRegistration<YangModuleInfo> inner;
54 private ObjectRegistrationWrapper(ObjectRegistration<YangModuleInfo> inner) {
59 public YangModuleInfo getInstance() {
60 return inner.getInstance();
64 public void close() throws Exception {
66 updateService();// send modify event when a bundle disappears
71 public String toString() {
72 return inner.toString();