Propagate delegate.toString() as symbolic name
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / ResourceYangTextSchemaSource.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.repo.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.net.URL;
17 import java.util.Optional;
18 import org.opendaylight.yangtools.concepts.Delegator;
19
20 /**
21  * A resource-backed {@link YinTextSchemaSource}.
22  */
23 @Beta
24 // FIXME: YANGTOOLS-849: 3.0.0: hide this class
25 public final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
26     private final URL url;
27
28     ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url) {
29         super(identifier);
30         this.url = requireNonNull(url);
31     }
32
33     @Override
34     public URL getDelegate() {
35         return url;
36     }
37
38     @Override
39     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
40         return toStringHelper.add("url", url);
41     }
42
43     @Override
44     public InputStream openStream() throws IOException {
45         return url.openStream();
46     }
47
48     @Override
49     public Optional<String> getSymbolicName() {
50         return Optional.of(url.toString());
51     }
52 }