Bug 6868: If-feature argument may be boolean expression
[yangtools.git] / yang / yang-test-util / src / main / java / org / opendaylight / yangtools / yang / test / util / YangParserTestUtils.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.test.util;
10
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import java.io.File;
14 import java.io.FileFilter;
15 import java.io.FileNotFoundException;
16 import java.io.InputStream;
17 import java.net.URI;
18 import java.net.URISyntaxException;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Set;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
27 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
29 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
30 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
32 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
33
34 /**
35  * Utility class which provides convenience methods for producing effective schema context based on the supplied
36  * yang/yin sources or paths to these sources
37  */
38 @Beta
39 public final class YangParserTestUtils {
40
41     private static final FileFilter YANG_FILE_FILTER = file -> {
42         final String name = file.getName().toLowerCase();
43         return name.endsWith(".yang") && file.isFile();
44     };
45
46     private YangParserTestUtils() {
47         throw new UnsupportedOperationException("Utility class should not be instantiated.");
48     }
49
50     /**
51      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
52      * default mode and all YANG features are supported.
53      *
54      * @param sources YANG sources to be parsed
55      *
56      * @return effective schema context
57      *
58      * @throws ReactorException if there is an error in one of the parsed YANG sources
59      *
60      * @deprecated Migration method only, do not use.
61      */
62     @Deprecated
63     public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
64         return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
65     }
66
67     /**
68      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
69      * default mode.
70      *
71      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
72      * @param sources YANG sources to be parsed
73      *
74      * @return effective schema context
75      * @throws ReactorException if there is an error in one of the parsed YANG sources
76      *
77      * @deprecated Migration method only, do not use.
78      */
79     @Deprecated
80     public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
81             final YangStatementSourceImpl... sources) throws ReactorException {
82         return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
83     }
84
85     /**
86      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
87      *
88      * @param statementParserMode mode of statement parser
89      * @param sources YANG sources to be parsed
90      *
91      * @return effective schema context
92      * @throws ReactorException if there is an error in one of the parsed YANG sources
93      *
94      * @deprecated Migration method only, do not use.
95      */
96     @Deprecated
97     public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
98             final YangStatementSourceImpl... sources) throws ReactorException {
99         return parseYangSources(null, statementParserMode, sources);
100     }
101
102     /**
103      * Creates a new effective schema context containing the specified YANG sources.
104      *
105      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
106      * @param statementParserMode mode of statement parser
107      * @param sources YANG sources to be parsed
108      *
109      * @return effective schema context
110      *
111      * @throws ReactorException if there is an error in one of the parsed YANG sources
112      */
113     public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
114             final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
115                     throws ReactorException {
116         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
117                 statementParserMode, supportedFeatures);
118         reactor.addSources(sources);
119
120         return reactor.buildEffective();
121     }
122
123     /**
124      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
125      * default mode and all YANG features are supported.
126      *
127      * @param files YANG files to be parsed
128      *
129      * @return effective schema context
130      *
131      * @throws ReactorException if there is an error in one of the parsed YANG sources
132      * @throws FileNotFoundException if one of the specified files does not exist
133      */
134     public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
135         return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
136     }
137
138     /**
139      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
140      * default mode.
141      *
142      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
143      * @param files YANG files to be parsed
144      *
145      * @return effective schema context
146      *
147      * @throws ReactorException if there is an error in one of the parsed YANG sources
148      * @throws FileNotFoundException if one of the specified files does not exist
149      */
150     public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
151             throws ReactorException, FileNotFoundException {
152         return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
153     }
154
155     /**
156      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
157      *
158      * @param statementParserMode mode of statement parser
159      * @param files YANG files to be parsed
160      *
161      * @return effective schema context
162      *
163      * @throws ReactorException if there is an error in one of the parsed YANG sources
164      * @throws FileNotFoundException if one of the specified files does not exist
165      */
166     public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
167             throws ReactorException, FileNotFoundException {
168         return parseYangSources(null, statementParserMode, files);
169     }
170
171     /**
172      * Creates a new effective schema context containing the specified YANG sources.
173      *
174      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
175      * @param statementParserMode mode of statement parser
176      * @param files YANG files to be parsed
177      *
178      * @return effective schema context
179      *
180      * @throws ReactorException if there is an error in one of the parsed YANG sources
181      * @throws FileNotFoundException if one of the specified files does not exist
182      */
183     public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
184             final StatementParserMode statementParserMode, final File... files) throws ReactorException,
185             FileNotFoundException {
186         final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
187         for (int i = 0; i < files.length; i++) {
188             sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
189         }
190
191         return parseYangSources(supportedFeatures, statementParserMode, sources);
192     }
193
194     /**
195      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
196      * default mode and all YANG features are supported.
197      *
198      * @param files collection of YANG files to be parsed
199      *
200      * @return effective schema context
201      *
202      * @throws ReactorException if there is an error in one of the parsed YANG sources
203      * @throws FileNotFoundException if one of the specified files does not exist
204      */
205     public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
206             FileNotFoundException {
207         return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
208     }
209
210     /**
211      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
212      * default mode.
213      *
214      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
215      * @param files collection of YANG files to be parsed
216      *
217      * @return effective schema context
218      *
219      * @throws ReactorException if there is an error in one of the parsed YANG sources
220      * @throws FileNotFoundException if one of the specified files does not exist
221      */
222     public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
223             throws ReactorException, FileNotFoundException {
224         return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
225     }
226
227     /**
228      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
229      *
230      * @param statementParserMode mode of statement parser
231      * @param files collection of YANG files to be parsed
232      *
233      * @return effective schema context
234      *
235      * @throws ReactorException if there is an error in one of the parsed YANG sources
236      * @throws FileNotFoundException if one of the specified files does not exist
237      */
238     public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
239             throws ReactorException, FileNotFoundException {
240         return parseYangSources(files, null, statementParserMode);
241     }
242
243     /**
244      * Creates a new effective schema context containing the specified YANG sources.
245      *
246      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
247      * @param statementParserMode mode of statement parser
248      * @param files collection of YANG files to be parsed
249      *
250      * @return effective schema context
251      *
252      * @throws ReactorException if there is an error in one of the parsed YANG sources
253      * @throws FileNotFoundException if one of the specified files does not exist
254      */
255     public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
256             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
257         return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
258     }
259
260     /**
261      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
262      * default mode and all YANG features are supported.
263      *
264      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
265      *
266      * @return effective schema context
267      *
268      * @throws ReactorException if there is an error in one of the parsed YANG sources
269      * @throws FileNotFoundException if the specified directory does not exist
270      * @throws URISyntaxException if the specified directory does not exist
271      */
272     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
273             FileNotFoundException, URISyntaxException {
274         return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
275     }
276
277     /**
278      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
279      * default mode.
280      *
281      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
282      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
283      *
284      * @return effective schema context
285      *
286      * @throws ReactorException if there is an error in one of the parsed YANG sources
287      * @throws FileNotFoundException if the specified directory does not exist
288      * @throws URISyntaxException if the specified directory does not exist
289      */
290     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
291             final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
292             URISyntaxException {
293         return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
294     }
295
296     /**
297      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
298      *
299      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
300      * @param statementParserMode mode of statement parser
301      *
302      * @return effective schema context
303      *
304      * @throws ReactorException if there is an error in one of the parsed YANG sources
305      * @throws FileNotFoundException if the specified directory does not exist
306      * @throws URISyntaxException if the specified directory does not exist
307      */
308     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
309             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
310             URISyntaxException {
311         return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
312     }
313
314     /**
315      * Creates a new effective schema context containing the specified YANG sources.
316      *
317      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
318      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
319      * @param statementParserMode mode of statement parser
320      *
321      * @return effective schema context
322      *
323      * @throws ReactorException if there is an error in one of the parsed YANG sources
324      * @throws FileNotFoundException if the specified directory does not exist
325      * @throws URISyntaxException if the specified directory does not exist
326      */
327     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
328             final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
329                     throws ReactorException, FileNotFoundException, URISyntaxException {
330         final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
331         final File dir = new File(directoryPath);
332
333         return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
334     }
335
336     /**
337      * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
338      * default mode and all YANG features are supported.
339      *
340      * @param yangSourcePath relative path to the YANG file to be parsed
341      *
342      * @return effective schema context
343      *
344      * @throws ReactorException if there is an error in the parsed YANG source
345      * @throws FileNotFoundException if the specified file does not exist
346      * @throws URISyntaxException if the specified file does not exist
347      */
348     public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
349             FileNotFoundException, URISyntaxException {
350         return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
351     }
352
353     /**
354      * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
355      * default mode.
356      *
357      * @param yangSourcePath relative path to the YANG file to be parsed
358      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG model are resolved
359      *
360      * @return effective schema context
361      *
362      * @throws ReactorException if there is an error in the parsed YANG source
363      * @throws FileNotFoundException if the specified file does not exist
364      * @throws URISyntaxException if the specified file does not exist
365      */
366     public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
367             throws ReactorException, FileNotFoundException, URISyntaxException {
368         return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
369     }
370
371     /**
372      * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
373      *
374      * @param yangSourcePath relative path to the YANG file to be parsed
375      * @param statementParserMode mode of statement parser
376      *
377      * @return effective schema context
378      *
379      * @throws ReactorException if there is an error in the parsed YANG source
380      * @throws FileNotFoundException if the specified file does not exist
381      * @throws URISyntaxException if the specified file does not exist
382      */
383     public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
384             throws ReactorException, FileNotFoundException, URISyntaxException {
385         return parseYangSource(yangSourcePath, null, statementParserMode);
386     }
387
388     /**
389      * Creates a new effective schema context containing the specified YANG source.
390      *
391      * @param yangSourcePath relative path to the YANG file to be parsed
392      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG model are resolved
393      * @param statementParserMode mode of statement parser
394      *
395      * @return effective schema context
396      *
397      * @throws ReactorException if there is an error in the parsed YANG source
398      * @throws FileNotFoundException if the specified file does not exist
399      * @throws URISyntaxException if the specified file does not exist
400      */
401     public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
402             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
403             URISyntaxException {
404         final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
405         final File sourceFile = new File(sourcePath);
406         return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
407     }
408
409     /**
410      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
411      * default mode and all YANG features are supported.
412      *
413      * @param yangDirs relative paths to the directories containing YANG files to be parsed
414      * @param yangFiles relative paths to the YANG files to be parsed
415      *
416      * @return effective schema context
417      *
418      * @throws ReactorException if there is an error in one of the parsed YANG sources
419      * @throws FileNotFoundException if one of the specified directories or files does not exist
420      * @throws URISyntaxException if one of the specified directories or files does not exist
421      */
422     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
423             throws FileNotFoundException, ReactorException, URISyntaxException {
424         return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
425     }
426
427     /**
428      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
429      * default mode.
430      *
431      * @param yangDirs relative paths to the directories containing YANG files to be parsed
432      * @param yangFiles relative paths to the YANG files to be parsed
433      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
434      *
435      * @return effective schema context
436      *
437      * @throws ReactorException if there is an error in one of the parsed YANG sources
438      * @throws FileNotFoundException if one of the specified directories or files does not exist
439      * @throws URISyntaxException if one of the specified directories or files does not exist
440      */
441     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
442             final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
443             URISyntaxException {
444         return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
445     }
446
447     /**
448      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
449      *
450      * @param yangDirs relative paths to the directories containing YANG files to be parsed
451      * @param yangFiles relative paths to the YANG files to be parsed
452      * @param statementParserMode mode of statement parser
453      *
454      * @return effective schema context
455      *
456      * @throws ReactorException if there is an error in one of the parsed YANG sources
457      * @throws FileNotFoundException if one of the specified directories or files does not exist
458      * @throws URISyntaxException if one of the specified directories or files does not exist
459      */
460     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
461             final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
462             URISyntaxException {
463         return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
464     }
465
466     /**
467      * Creates a new effective schema context containing the specified YANG sources.
468      *
469      * @param yangDirs relative paths to the directories containing YANG files to be parsed
470      * @param yangFiles relative paths to the YANG files to be parsed
471      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
472      * @param statementParserMode mode of statement parser
473      *
474      * @return effective schema context
475      *
476      * @throws ReactorException if there is an error in one of the parsed YANG sources
477      * @throws FileNotFoundException if one of the specified directories or files does not exist
478      * @throws URISyntaxException if one of the specified directories or files does not exist
479      */
480     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
481             final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
482             throws FileNotFoundException, ReactorException, URISyntaxException {
483         final List<File> allYangFiles = new ArrayList<>();
484         for (final String yangDir : yangDirs) {
485             allYangFiles.addAll(getYangFiles(yangDir));
486         }
487
488         for (final String yangFile : yangFiles) {
489             final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
490             allYangFiles.add(new File(filePath));
491         }
492
493         return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
494     }
495
496     private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
497         final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
498         final File dir = new File(directoryPath);
499
500         return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
501     }
502
503     /**
504      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
505      * default mode and all YANG features are supported.
506      *
507      * @param filePaths relative paths to the YANG files to be parsed
508      *
509      * @return effective schema context
510      *
511      * @throws ReactorException if there is an error in one of the parsed YANG sources
512      */
513     public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
514         return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
515     }
516
517     /**
518      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
519      * default mode.
520      *
521      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
522      * @param filePaths relative paths to the YANG files to be parsed
523      *
524      * @return effective schema context
525      *
526      * @throws ReactorException if there is an error in one of the parsed YANG sources
527      */
528     public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
529             throws ReactorException {
530         return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
531     }
532
533     /**
534      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
535      *
536      * @param statementParserMode mode of statement parser
537      * @param filePaths relative paths to the YANG files to be parsed
538      *
539      * @return effective schema context
540      *
541      * @throws ReactorException if there is an error in one of the parsed YANG sources
542      */
543     public static SchemaContext parseYangSources(final List<String> filePaths,
544             final StatementParserMode statementParserMode) throws ReactorException {
545         return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
546     }
547
548     /**
549      * Creates a new effective schema context containing the specified YANG sources.
550      *
551      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
552      * @param statementParserMode mode of statement parser
553      * @param filePaths relative paths to the YANG files to be parsed
554      *
555      * @return effective schema context
556      *
557      * @throws ReactorException if there is an error in one of the parsed YANG sources
558      */
559     public static SchemaContext parseYangSources(final List<String> filePaths,
560             final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
561                     throws ReactorException {
562         final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
563
564         for (int i = 0; i < filePaths.size(); i++) {
565             sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
566         }
567
568         return parseYangSources(supportedFeatures, statementParserMode, sources);
569     }
570
571     /**
572      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
573      * default mode and all YANG features are supported.
574      *
575      * @param streams input streams containing YANG sources to be parsed
576      *
577      * @return effective schema context
578      *
579      * @throws ReactorException if there is an error in one of the parsed YANG sources
580      */
581     public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
582         return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
583     }
584
585     /**
586      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
587      * default mode.
588      *
589      * @param streams input streams containing YANG sources to be parsed
590      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
591      *
592      * @return effective schema context
593      *
594      * @throws ReactorException if there is an error in one of the parsed YANG sources
595      */
596     public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
597             throws ReactorException {
598         return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
599     }
600
601     /**
602      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
603      *
604      * @param streams input streams containing YANG sources to be parsed
605      * @param statementParserMode mode of statement parser
606      *
607      * @return effective schema context
608      *
609      * @throws ReactorException if there is an error in one of the parsed YANG sources
610      */
611     public static SchemaContext parseYangStreams(final List<InputStream> streams, final StatementParserMode statementParserMode)
612             throws ReactorException {
613         return parseYangStreams(streams, null, statementParserMode);
614     }
615
616     /**
617      * Creates a new effective schema context containing the specified YANG sources.
618      *
619      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
620      * @param statementParserMode mode of statement parser
621      * @param streams input streams containing YANG sources to be parsed
622      *
623      * @return effective schema context
624      *
625      * @throws ReactorException if there is an error in one of the parsed YANG sources
626      */
627     public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
628             final StatementParserMode statementParserMode) throws ReactorException {
629         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
630                 statementParserMode, supportedFeatures);
631         return reactor.buildEffective(streams);
632     }
633
634     /**
635      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
636      * default mode and all YANG features are supported.
637      *
638      * @param clazz Resource lookup base
639      * @param resources Resource names to be looked up
640      *
641      * @return effective schema context
642      *
643      * @throws ReactorException if there is an error in one of the parsed YANG sources
644      */
645     public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
646             throws ReactorException {
647         final List<InputStream> streams = new ArrayList<>(resources.length);
648         for (final String r : resources) {
649             final InputStream is = clazz.getResourceAsStream(r);
650             Preconditions.checkArgument(is != null, "Resource %s not found", r);
651             streams.add(is);
652         }
653
654         return parseYangStreams(streams);
655     }
656
657     /**
658      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
659      * default mode and all YANG features are supported.
660      *
661      * @param streams input streams containing YANG sources to be parsed
662      *
663      * @return effective schema context
664      *
665      * @throws ReactorException if there is an error in one of the parsed YANG sources
666      */
667     public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
668         return parseYangStreams(Arrays.asList(streams));
669     }
670
671     /**
672      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
673      * default mode.
674      *
675      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
676      * @param streams input streams containing YANG sources to be parsed
677      *
678      * @return effective schema context
679      *
680      * @throws ReactorException if there is an error in one of the parsed YANG sources
681      */
682     public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
683             final InputStream... streams) throws ReactorException {
684         return parseYangStreams(Arrays.asList(streams), supportedFeatures);
685     }
686
687     /**
688      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
689      *
690      * @param statementParserMode mode of statement parser
691      * @param streams input streams containing YANG sources to be parsed
692      *
693      * @return effective schema context
694      *
695      * @throws ReactorException if there is an error in one of the parsed YANG sources
696      */
697     public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
698             final InputStream... streams) throws ReactorException {
699         return parseYangStreams(Arrays.asList(streams), statementParserMode);
700     }
701
702     /**
703      * Creates a new effective schema context containing the specified YANG sources.
704      *
705      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
706      * @param statementParserMode mode of statement parser
707      * @param streams input streams containing YANG sources to be parsed
708      *
709      * @return effective schema context
710      *
711      * @throws ReactorException if there is an error in one of the parsed YANG sources
712      */
713     public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
714             final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
715         return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
716     }
717
718     /**
719      * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
720      * default mode and all YANG features are supported.
721      *
722      * @param sources YIN sources to be parsed
723      *
724      * @return effective schema context
725      *
726      * @throws ReactorException if there is an error in one of the parsed YIN sources
727      */
728     public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
729         return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
730     }
731
732     /**
733      * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
734      * default mode.
735      *
736      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN models are resolved
737      * @param sources YIN sources to be parsed
738      *
739      * @return effective schema context
740      * @throws ReactorException if there is an error in one of the parsed YIN sources
741      */
742     public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
743             final YinStatementStreamSource... sources) throws ReactorException {
744         return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
745     }
746
747     /**
748      * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
749      *
750      * @param statementParserMode mode of statement parser
751      * @param sources YIN sources to be parsed
752      *
753      * @return effective schema context
754      *
755      * @throws ReactorException if there is an error in one of the parsed YIN sources
756      */
757     public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
758             final YinStatementStreamSource... sources) throws ReactorException {
759         return parseYinSources(null, statementParserMode, sources);
760     }
761
762     /**
763      * Creates a new effective schema context containing the specified YIN sources.
764      *
765      * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN models are resolved
766      * @param statementParserMode mode of statement parser
767      * @param sources YIN sources to be parsed
768      *
769      * @return effective schema context
770      *
771      * @throws ReactorException if there is an error in one of the parsed YIN sources
772      */
773     public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
774             final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
775                     throws ReactorException {
776         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
777                 statementParserMode, supportedFeatures);
778         reactor.addSources(sources);
779
780         return reactor.buildEffective();
781     }
782 }