59160e9ed8d71bf5711968d2ec35d1324dd70418
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / DelegatedYinTextSchemaSource.java
1 /*
2  * Copyright (c) 2018 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 DelegatedYinTextSchemaSource extends YinTextSchemaSource
20         implements Delegator<ByteSource> {
21     private final ByteSource delegate;
22
23     DelegatedYinTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
24         super(identifier);
25         this.delegate = requireNonNull(delegate);
26     }
27
28     @Override
29     public ByteSource getDelegate() {
30         return delegate;
31     }
32
33     @Override
34     public InputStream openStream() throws IOException {
35         return delegate.openStream();
36     }
37
38     @Override
39     public Optional<String> getSymbolicName() {
40         return Optional.of(delegate.toString());
41     }
42
43     @Override
44     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
45         return toStringHelper.add("delegate", delegate);
46     }
47 }