Do not provide SourceIdentifiers from extensions
[yangtools.git] / yang / yang-repo-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / YinTextFileSchemaSource.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.repo.api;
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 java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.yangtools.concepts.Delegator;
20
21 /**
22  * A {@link YinTextSchemaSource} backed by a file.
23  *
24  * @author Robert Varga
25  */
26 final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<Path> {
27     private final @NonNull Path path;
28
29     YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull Path path) {
30         super(identifier);
31         this.path = requireNonNull(path);
32     }
33
34     @Override
35     public Path getDelegate() {
36         return path;
37     }
38
39     @Override
40     public InputStream openStream() throws IOException {
41         return Files.newInputStream(path);
42     }
43
44     @Override
45     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
46         return super.addToStringAttributes(toStringHelper).add("path", path);
47     }
48
49     @Override
50     public Optional<String> getSymbolicName() {
51         return Optional.of(path.toString());
52     }
53 }