11317e11d7c84eadaa50520a3f4b7cc1b7403378
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / stmt / parser / retest / RetestUtils.java
1 package org.opendaylight.yangtools.binding.generator.util.stmt.parser.retest;
2
3 import java.util.Collection;
4
5 import java.io.FileNotFoundException;
6 import java.io.FileInputStream;
7 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
8 import java.io.File;
9 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
10 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
12 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
13 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
15
16 public class RetestUtils {
17
18     private RetestUtils() {
19         throw new UnsupportedOperationException("Utility class");
20     }
21
22     public static SchemaContext parseYangSources(StatementStreamSource... sources)
23             throws SourceException, ReactorException {
24
25         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
26                 .newBuild();
27         reactor.addSources(sources);
28
29         return reactor.buildEffective();
30     }
31
32     public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException {
33
34         StatementStreamSource[] sources = new StatementStreamSource[files.length];
35
36         for(int i = 0; i<files.length; i++) {
37             sources[i] = new YangStatementSourceImpl(new FileInputStream(files[i]));
38         }
39
40         return parseYangSources(sources);
41     }
42
43     public static SchemaContext parseYangSources(Collection<File> files) throws SourceException, ReactorException, FileNotFoundException {
44         return parseYangSources(files.toArray(new File[files.size()]));
45     }
46 }