2 * Copyright (c) 2024 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.client.mdsal.api;
10 import static java.util.Objects.requireNonNull;
13 import java.util.stream.Stream;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.yangtools.concepts.Registration;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
19 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
20 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
21 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
24 * A set of sources provided through a single provider. A NETCONF device can have several of these.
26 * @param representation the {@link SourceRepresentation} of provided sources
27 * @param provider the {@link SchemaSourceProvider} providing the sources
28 * @param sources provided sources
31 public record ProvidedSources<T extends SourceRepresentation>(
32 Class<T> representation,
33 SchemaSourceProvider<T> provider,
34 // FIXME: NETCONF-840: use SourceIdentifier
36 public ProvidedSources {
37 representation = requireNonNull(representation);
38 provider = requireNonNull(provider);
39 sources = Set.copyOf(sources);
42 public Stream<Registration> registerWith(final SchemaSourceRegistry registry, final int cost) {
43 return sources.stream()
44 .map(qname -> new SourceIdentifier(qname.getLocalName(), qname.getRevision().orElse(null)))
45 .map(sourceId -> registry.registerSchemaSource(provider,
46 PotentialSchemaSource.create(sourceId, representation, cost)));