86077842a0ac6c6b2631db1eb91b142832a06d84
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / DelegatedYangTextSchemaSource.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 com.google.common.io.ByteSource;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.util.Optional;
17 import org.opendaylight.yangtools.concepts.Delegator;
18
19 final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<ByteSource> {
20     private final ByteSource delegate;
21
22     DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
23         super(identifier);
24         this.delegate = requireNonNull(delegate);
25     }
26
27     @Override
28     public ByteSource getDelegate() {
29         return delegate;
30     }
31
32     @Override
33     public InputStream openStream() throws IOException {
34         return delegate.openStream();
35     }
36
37     @Override
38     public Optional<String> getSymbolicName() {
39         return Optional.of(delegate.toString());
40     }
41
42     @Override
43     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
44         return toStringHelper.add("delegate", delegate);
45     }
46 }