Do not provide SourceIdentifiers from extensions
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / source / YinTextFileSource.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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 com.google.common.base.MoreObjects.ToStringHelper;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.nio.file.Files;
16 import java.nio.file.Path;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.concepts.Delegator;
19 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
20
21 /**
22  * A {@link YinTextSource} backed by a file.
23  */
24 final class YinTextFileSource extends YinTextSource implements Delegator<Path> {
25     private final @NonNull Path path;
26
27     YinTextFileSource(final @NonNull SourceIdentifier sourceId, final @NonNull Path path) {
28         super(sourceId);
29         this.path = requireNonNull(path);
30     }
31
32     @Override
33     public Path getDelegate() {
34         return path;
35     }
36
37     @Override
38     public InputStream openStream() throws IOException {
39         return Files.newInputStream(path);
40     }
41
42     @Override
43     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
44         return super.addToStringAttributes(toStringHelper).add("path", path);
45     }
46
47     @Override
48     public String symbolicName() {
49         return path.toString();
50     }
51 }