Do not provide SourceIdentifiers from extensions
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / source / ResourceYinTextSource.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.net.URL;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.concepts.Delegator;
18 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
19
20 /**
21  * A resource-backed {@link YinTextSource}.
22  */
23 final class ResourceYinTextSource extends YinTextSource implements Delegator<URL> {
24     private final @NonNull URL url;
25
26     ResourceYinTextSource(final SourceIdentifier sourceId, final URL url) {
27         super(sourceId);
28         this.url = requireNonNull(url);
29     }
30
31     @Override
32     public URL getDelegate() {
33         return url;
34     }
35
36     @Override
37     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
38         return super.addToStringAttributes(toStringHelper).add("url", url);
39     }
40
41     @Override
42     public InputStream openStream() throws IOException {
43         return url.openStream();
44     }
45
46     @Override
47     public String symbolicName() {
48         return url.toString();
49     }
50 }