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