2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
11 import com.google.common.base.Throwables;
12 import com.google.common.collect.ForwardingObject;
13 import com.google.common.io.ByteSource;
14 import com.google.common.io.ByteStreams;
15 import com.google.common.io.Files;
17 import java.io.InputStream;
18 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
19 import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
20 import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
21 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer;
23 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
24 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
26 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
29 * This class represents implementation of StatementStreamSource
30 * in order to emit YIN statements using supplied StatementWriter.
32 * @deprecated Scheduled for removal. Use {@link YinStatementStreamSource} instead.
35 public final class YinStatementSourceImpl extends ForwardingObject implements StatementStreamSource {
36 private final StatementStreamSource delegate;
38 private YinStatementSourceImpl(final YinDomSchemaSource source) {
39 this.delegate = YinStatementStreamSource.create(source);
43 public StatementStreamSource delegate() {
47 public YinStatementSourceImpl(final InputStream inputStream) {
48 this(newStreamSource(inputStream));
51 private static YinDomSchemaSource newStreamSource(final InputStream inputStream) {
52 final SourceIdentifier id = YinTextSchemaSource.identifierFromFilename(inputStream.toString());
55 final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource(id,
56 ByteSource.wrap(ByteStreams.toByteArray(inputStream)));
57 return YinTextToDomTransformer.TRANSFORMATION.apply(text).get();
58 } catch (Exception e) {
59 throw Throwables.propagate(e);
63 private static YinDomSchemaSource newStreamSource(final String fileName, final boolean isAbsolute) {
67 file = new File(fileName);
69 file = new File(YinStatementSourceImpl.class.getResource(fileName).toURI());
72 final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource(
73 YinTextSchemaSource.identifierFromFilename(file.getName()), Files.asByteSource(file));
75 return YinTextToDomTransformer.TRANSFORMATION.apply(text).get();
76 } catch (Exception e) {
77 throw Throwables.propagate(e);
81 public YinStatementSourceImpl(final String fileName, final boolean isAbsolute) {
82 this(newStreamSource(fileName, isAbsolute));
86 public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
87 delegate.writePreLinkage(writer, stmtDef);
91 public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
92 final PrefixToModule preLinkagePrefixes) {
93 delegate.writeLinkage(writer, stmtDef, preLinkagePrefixes);
98 public void writeLinkageAndStatementDefinitions(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
99 final PrefixToModule prefixes) {
100 delegate.writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes);
104 public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
105 final PrefixToModule prefixes) {
106 delegate().writeFull(writer, stmtDef, prefixes);