2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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
8 package org.opendaylight.netconf.sal.connect.netconf;
10 import static java.util.Objects.requireNonNull;
12 import java.util.List;
14 import java.util.stream.Collectors;
15 import org.opendaylight.yangtools.concepts.Registration;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
19 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
20 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
21 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
22 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
25 * Contains RequiredSources - sources from capabilities.
27 final class DeviceSources {
28 private final Set<QName> requiredSources;
29 private final Set<QName> providedSources;
30 private final SchemaSourceProvider<YangTextSchemaSource> sourceProvider;
32 DeviceSources(final Set<QName> requiredSources, final Set<QName> providedSources,
33 final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
34 this.requiredSources = requireNonNull(requiredSources);
35 this.providedSources = requireNonNull(providedSources);
36 this.sourceProvider = requireNonNull(sourceProvider);
39 Set<QName> getRequiredSourcesQName() {
40 return requiredSources;
43 Set<QName> getProvidedSourcesQName() {
44 return providedSources;
47 List<SourceIdentifier> getRequiredSources() {
48 return requiredSources.stream().map(DeviceSources::toSourceId).collect(Collectors.toList());
51 List<Registration> register(final SchemaSourceRegistry schemaRegistry) {
52 return providedSources.stream()
53 .map(DeviceSources::toSourceId)
54 .map(sourceId -> schemaRegistry.registerSchemaSource(sourceProvider,
55 PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class,
56 PotentialSchemaSource.Costs.REMOTE_IO.getValue())))
57 .collect(Collectors.toUnmodifiableList());
60 private static SourceIdentifier toSourceId(final QName input) {
61 return new SourceIdentifier(input.getLocalName(), input.getRevision().map(Revision::toString).orElse(null));