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 org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
17 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
19
20 /**
21  * A {@link YangTextSource} cached from a remote service.
22  */
23 // FIXME: subclass StringYangTextSource and cleanup addToStringAttributes()
24 public final class CachedYangTextSchemaSource extends YangTextSource {
25     private final @NonNull SourceIdentifier sourceId;
26     private final @NonNull RemoteDeviceId id;
27     private final @NonNull String symbolicName;
28     private final @NonNull String schemaString;
29
30     public CachedYangTextSchemaSource(final RemoteDeviceId id, final SourceIdentifier sourceId,
31             final String symbolicName, final String schemaString) {
32         this.id = requireNonNull(id);
33         this.sourceId = requireNonNull(sourceId);
34         this.symbolicName = requireNonNull(symbolicName);
35         this.schemaString = requireNonNull(schemaString);
36     }
37
38     @Override
39     public Reader openStream() {
40         return new StringReader(schemaString);
41     }
42
43     @Override
44     public SourceIdentifier sourceId() {
45         return sourceId;
46     }
47
48     @Override
49     public String symbolicName() {
50         return symbolicName;
51     }
52
53     @Override
54     protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
55         return toStringHelper.add("device", id);
56     }
57 }