Bump upstreams
[netconf.git] / plugins / netconf-client-mdsal / src / main / java / org / opendaylight / netconf / client / mdsal / CachedYangTextSchemaSource.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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 package org.opendaylight.netconf.client.mdsal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import java.io.Reader;
14 import java.io.StringReader;
15 import java.util.Optional;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
19
20 /**
21  * A {@link YangTextSchemaSource} cached from a remote service.
22  */
23 public final class CachedYangTextSchemaSource extends YangTextSchemaSource {
24     private final RemoteDeviceId id;
25     private final String schemaString;
26     private final String symbolicName;
27
28     public CachedYangTextSchemaSource(final RemoteDeviceId id, final SourceIdentifier sourceIdentifier,
29             final String symbolicName, final String schemaString) {
30         super(sourceIdentifier);
31         this.symbolicName = requireNonNull(symbolicName);
32         this.id = requireNonNull(id);
33         this.schemaString = requireNonNull(schemaString);
34     }
35
36     @Override
37     protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
38         return toStringHelper.add("device", id);
39     }
40
41     @Override
42     public Reader openStream() {
43         return new StringReader(schemaString);
44     }
45
46     @Override
47     public Optional<String> getSymbolicName() {
48         return Optional.of(symbolicName);
49     }
50 }