Do not provide SourceIdentifiers from extensions
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / source / StringYangTextSource.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.yangtools.yang.model.spi.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Reader;
13 import java.io.StringReader;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
17
18 /**
19  * A {@link YangTextSource} with content readily available.
20  */
21 public class StringYangTextSource extends YangTextSource {
22     private final @Nullable String symbolicName;
23     private final @NonNull String content;
24
25     public StringYangTextSource(final SourceIdentifier sourceId, final String content) {
26         this(sourceId, content, null);
27     }
28
29     public StringYangTextSource(final SourceIdentifier sourceId, final String content,
30             final @Nullable String symbolicName) {
31         super(sourceId);
32         this.content = requireNonNull(content);
33         this.symbolicName = symbolicName;
34     }
35
36     @Override
37     public final String symbolicName() {
38         return symbolicName;
39     }
40
41     @Override
42     public final Reader openStream() {
43         return new StringReader(content);
44     }
45 }