2 * Copyright (c) 2016 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
8 package org.opendaylight.yangtools.sal.binding.yang.types;
11 import java.io.FileInputStream;
12 import java.io.FileNotFoundException;
13 import java.io.InputStream;
14 import java.util.Collection;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
24 public class TestUtils {
27 throw new UnsupportedOperationException("Utility class");
30 public static SchemaContext parseYangSources(StatementStreamSource... sources)
31 throws SourceException, ReactorException {
33 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
35 reactor.addSources(sources);
37 return reactor.buildEffective();
40 public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException {
42 StatementStreamSource[] sources = new StatementStreamSource[files.length];
44 for(int i = 0; i<files.length; i++) {
45 sources[i] = new YangStatementSourceImpl(new FileInputStream(files[i]));
48 return parseYangSources(sources);
51 public static SchemaContext parseYangSources(Collection<File> files) throws SourceException, ReactorException, FileNotFoundException {
52 return parseYangSources(files.toArray(new File[files.size()]));
56 public static SchemaContext parseYangStreams(List<InputStream> streams)
57 throws SourceException, ReactorException {
59 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
61 return reactor.buildEffective(streams);