Promote SchemaSourceRepresentation
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / source / DelegatedYangTextSource.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 com.google.common.io.CharSource;
14 import java.io.IOException;
15 import java.io.Reader;
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 final class DelegatedYangTextSource extends YangTextSource implements Delegator<CharSource> {
21     private final @NonNull CharSource delegate;
22
23     DelegatedYangTextSource(final SourceIdentifier sourceId, final CharSource delegate) {
24         super(sourceId);
25         this.delegate = requireNonNull(delegate);
26     }
27
28     @Override
29     public CharSource getDelegate() {
30         return delegate;
31     }
32
33     @Override
34     public Reader openStream() throws IOException {
35         return delegate.openStream();
36     }
37
38     @Override
39     public String symbolicName() {
40         return "[" + delegate.toString() + "]";
41     }
42
43     @Override
44     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
45         return super.addToStringAttributes(toStringHelper).add("delegate", delegate);
46     }
47 }