Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / ConfigSubsystemFacadeFactory.java
1 /*
2  * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.facade.xml;
10
11 import com.google.common.collect.Sets;
12 import java.util.Set;
13 import org.opendaylight.controller.config.facade.xml.osgi.YangStoreService;
14 import org.opendaylight.controller.config.util.ConfigRegistryClient;
15 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
16 import org.opendaylight.controller.config.util.capability.Capability;
17 import org.opendaylight.controller.config.util.capability.YangModuleCapability;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
20
21 public class ConfigSubsystemFacadeFactory {
22
23     private final ConfigRegistryClient cfgRegClient;
24     private final ConfigRegistryJMXClient cfgRegClientNoNotifications;
25     private final YangStoreService yangStoreService;
26
27     public ConfigSubsystemFacadeFactory(final ConfigRegistryClient cfgRegClient,
28             final ConfigRegistryJMXClient jmxClientNoNotifications, final YangStoreService yangStoreService) {
29         this.cfgRegClient = cfgRegClient;
30         this.cfgRegClientNoNotifications = jmxClientNoNotifications;
31         this.yangStoreService = yangStoreService;
32     }
33
34     /**
35      * Create new instance of ConfigSubsystemFacade. Each instance works with a
36      * dedicated transaction provider, making the instances suitable for
37      * facade-per-client use.
38      */
39     public ConfigSubsystemFacade createFacade(final String id) {
40         return new ConfigSubsystemFacade(cfgRegClient, cfgRegClientNoNotifications, yangStoreService, id);
41     }
42
43     public YangStoreService getYangStoreService() {
44         return yangStoreService;
45     }
46
47     public Set<Capability> getCurrentCapabilities() {
48         Set<Module> modules = yangStoreService.getModules();
49         final Set<Capability> capabilities = Sets.newHashSet();
50         for (Module module : modules) {
51             capabilities.add(new YangModuleCapability(module, yangStoreService.getModuleSource(
52                 RevisionSourceIdentifier.create(module.getName(), module.getRevision()))));
53         }
54         return capabilities;
55     }
56 }