Bug 7159: Add yang-test-util artifact
[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 java.io.File;
13 import java.io.FileFilter;
14 import java.io.FileNotFoundException;
15 import java.io.InputStream;
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.function.Predicate;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
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     public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
61         return parseYangSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
62     }
63
64     /**
65      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
66      * default mode.
67      *
68      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
69      * @param sources YANG sources to be parsed
70      *
71      * @return effective schema context
72      * @throws ReactorException if there is an error in one of the parsed YANG sources
73      */
74     public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
75             final YangStatementSourceImpl... sources) throws ReactorException {
76         return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
77     }
78
79     /**
80      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
81      *
82      * @param statementParserMode mode of statement parser
83      * @param sources YANG sources to be parsed
84      *
85      * @return effective schema context
86      * @throws ReactorException if there is an error in one of the parsed YANG sources
87      */
88     public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
89             final YangStatementSourceImpl... sources) throws ReactorException {
90         return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
91     }
92
93     /**
94      * Creates a new effective schema context containing the specified YANG sources.
95      *
96      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
97      * @param statementParserMode mode of statement parser
98      * @param sources YANG sources to be parsed
99      *
100      * @return effective schema context
101      *
102      * @throws ReactorException if there is an error in one of the parsed YANG sources
103      */
104     public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
105             final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources) throws ReactorException {
106         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
107                 statementParserMode, isFeatureSupported);
108         reactor.addSources(sources);
109
110         return reactor.buildEffective();
111     }
112
113     /**
114      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
115      * default mode and all YANG features are supported.
116      *
117      * @param files YANG files to be parsed
118      *
119      * @return effective schema context
120      *
121      * @throws ReactorException if there is an error in one of the parsed YANG sources
122      * @throws FileNotFoundException if one of the specified files does not exist
123      */
124     public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
125         return parseYangSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, files);
126     }
127
128     /**
129      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
130      * default mode.
131      *
132      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
133      * @param files YANG files to be parsed
134      *
135      * @return effective schema context
136      *
137      * @throws ReactorException if there is an error in one of the parsed YANG sources
138      * @throws FileNotFoundException if one of the specified files does not exist
139      */
140     public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported, final File... files)
141             throws ReactorException, FileNotFoundException {
142         return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, files);
143     }
144
145     /**
146      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
147      *
148      * @param statementParserMode mode of statement parser
149      * @param files YANG files to be parsed
150      *
151      * @return effective schema context
152      *
153      * @throws ReactorException if there is an error in one of the parsed YANG sources
154      * @throws FileNotFoundException if one of the specified files does not exist
155      */
156     public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
157             throws ReactorException, FileNotFoundException {
158         return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, files);
159     }
160
161     /**
162      * Creates a new effective schema context containing the specified YANG sources.
163      *
164      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
165      * @param statementParserMode mode of statement parser
166      * @param files YANG files to be parsed
167      *
168      * @return effective schema context
169      *
170      * @throws ReactorException if there is an error in one of the parsed YANG sources
171      * @throws FileNotFoundException if one of the specified files does not exist
172      */
173     public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
174             final StatementParserMode statementParserMode, final File... files) throws ReactorException,
175             FileNotFoundException {
176         final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
177         for (int i = 0; i < files.length; i++) {
178             sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
179         }
180
181         return parseYangSources(isFeatureSupported, statementParserMode, sources);
182     }
183
184     /**
185      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
186      * default mode and all YANG features are supported.
187      *
188      * @param files collection of YANG files to be parsed
189      *
190      * @return effective schema context
191      *
192      * @throws ReactorException if there is an error in one of the parsed YANG sources
193      * @throws FileNotFoundException if one of the specified files does not exist
194      */
195     public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
196             FileNotFoundException {
197         return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
198     }
199
200     /**
201      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
202      * default mode.
203      *
204      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
205      * @param files collection of YANG files to be parsed
206      *
207      * @return effective schema context
208      *
209      * @throws ReactorException if there is an error in one of the parsed YANG sources
210      * @throws FileNotFoundException if one of the specified files does not exist
211      */
212     public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported)
213             throws ReactorException, FileNotFoundException {
214         return parseYangSources(files, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
215     }
216
217     /**
218      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
219      *
220      * @param statementParserMode mode of statement parser
221      * @param files collection of YANG files to be parsed
222      *
223      * @return effective schema context
224      *
225      * @throws ReactorException if there is an error in one of the parsed YANG sources
226      * @throws FileNotFoundException if one of the specified files does not exist
227      */
228     public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
229             throws ReactorException, FileNotFoundException {
230         return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
231     }
232
233     /**
234      * Creates a new effective schema context containing the specified YANG sources.
235      *
236      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
237      * @param statementParserMode mode of statement parser
238      * @param files collection of YANG files to be parsed
239      *
240      * @return effective schema context
241      *
242      * @throws ReactorException if there is an error in one of the parsed YANG sources
243      * @throws FileNotFoundException if one of the specified files does not exist
244      */
245     public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported,
246             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
247         return parseYangSources(isFeatureSupported, statementParserMode, files.toArray(new File[files.size()]));
248     }
249
250     /**
251      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
252      * default mode and all YANG features are supported.
253      *
254      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
255      *
256      * @return effective schema context
257      *
258      * @throws ReactorException if there is an error in one of the parsed YANG sources
259      * @throws FileNotFoundException if the specified directory does not exist
260      * @throws URISyntaxException if the specified directory does not exist
261      */
262     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
263             FileNotFoundException, URISyntaxException {
264         return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
265     }
266
267     /**
268      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
269      * default mode.
270      *
271      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
272      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
273      *
274      * @return effective schema context
275      *
276      * @throws ReactorException if there is an error in one of the parsed YANG sources
277      * @throws FileNotFoundException if the specified directory does not exist
278      * @throws URISyntaxException if the specified directory does not exist
279      */
280     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
281             final Predicate<QName> isFeatureSupported) throws ReactorException, FileNotFoundException, URISyntaxException {
282         return parseYangSources(yangSourcesDirectoryPath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
283     }
284
285     /**
286      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
287      *
288      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
289      * @param statementParserMode mode of statement parser
290      *
291      * @return effective schema context
292      *
293      * @throws ReactorException if there is an error in one of the parsed YANG sources
294      * @throws FileNotFoundException if the specified directory does not exist
295      * @throws URISyntaxException if the specified directory does not exist
296      */
297     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
298             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException, URISyntaxException {
299         return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
300     }
301
302     /**
303      * Creates a new effective schema context containing the specified YANG sources.
304      *
305      * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
306      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
307      * @param statementParserMode mode of statement parser
308      *
309      * @return effective schema context
310      *
311      * @throws ReactorException if there is an error in one of the parsed YANG sources
312      * @throws FileNotFoundException if the specified directory does not exist
313      * @throws URISyntaxException if the specified directory does not exist
314      */
315     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
316             final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode) throws ReactorException,
317             FileNotFoundException, URISyntaxException {
318         final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
319         final File dir = new File(directoryPath);
320
321         return parseYangSources(isFeatureSupported, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
322     }
323
324     /**
325      * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
326      * default mode and all YANG features are supported.
327      *
328      * @param yangSourcePath relative path to the YANG file to be parsed
329      *
330      * @return effective schema context
331      *
332      * @throws ReactorException if there is an error in the parsed YANG source
333      * @throws FileNotFoundException if the specified file does not exist
334      * @throws URISyntaxException if the specified file does not exist
335      */
336     public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
337             FileNotFoundException, URISyntaxException {
338         return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
339     }
340
341     /**
342      * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
343      * default mode.
344      *
345      * @param yangSourcePath relative path to the YANG file to be parsed
346      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
347      *
348      * @return effective schema context
349      *
350      * @throws ReactorException if there is an error in the parsed YANG source
351      * @throws FileNotFoundException if the specified file does not exist
352      * @throws URISyntaxException if the specified file does not exist
353      */
354     public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported)
355             throws ReactorException, FileNotFoundException, URISyntaxException {
356         return parseYangSource(yangSourcePath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
357     }
358
359     /**
360      * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
361      *
362      * @param yangSourcePath relative path to the YANG file to be parsed
363      * @param statementParserMode mode of statement parser
364      *
365      * @return effective schema context
366      *
367      * @throws ReactorException if there is an error in the parsed YANG source
368      * @throws FileNotFoundException if the specified file does not exist
369      * @throws URISyntaxException if the specified file does not exist
370      */
371     public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
372             throws ReactorException, FileNotFoundException, URISyntaxException {
373         return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
374     }
375
376     /**
377      * Creates a new effective schema context containing the specified YANG source.
378      *
379      * @param yangSourcePath relative path to the YANG file to be parsed
380      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
381      * @param statementParserMode mode of statement parser
382      *
383      * @return effective schema context
384      *
385      * @throws ReactorException if there is an error in the parsed YANG source
386      * @throws FileNotFoundException if the specified file does not exist
387      * @throws URISyntaxException if the specified file does not exist
388      */
389     public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported,
390             final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException, URISyntaxException {
391         final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
392         final File sourceFile = new File(sourcePath);
393         return parseYangSources(isFeatureSupported, statementParserMode, sourceFile);
394     }
395
396     /**
397      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
398      * default mode and all YANG features are supported.
399      *
400      * @param yangDirs relative paths to the directories containing YANG files to be parsed
401      * @param yangFiles relative paths to the YANG files to be parsed
402      *
403      * @return effective schema context
404      *
405      * @throws ReactorException if there is an error in one of the parsed YANG sources
406      * @throws FileNotFoundException if one of the specified directories or files does not exist
407      * @throws URISyntaxException if one of the specified directories or files does not exist
408      */
409     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
410             throws FileNotFoundException, ReactorException, URISyntaxException {
411         return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
412     }
413
414     /**
415      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
416      * default mode.
417      *
418      * @param yangDirs relative paths to the directories containing YANG files to be parsed
419      * @param yangFiles relative paths to the YANG files to be parsed
420      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
421      *
422      * @return effective schema context
423      *
424      * @throws ReactorException if there is an error in one of the parsed YANG sources
425      * @throws FileNotFoundException if one of the specified directories or files does not exist
426      * @throws URISyntaxException if one of the specified directories or files does not exist
427      */
428     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
429             final Predicate<QName> isFeatureSupported) throws FileNotFoundException, ReactorException, URISyntaxException {
430         return parseYangSources(yangDirs, yangFiles, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
431     }
432
433     /**
434      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
435      *
436      * @param yangDirs relative paths to the directories containing YANG files to be parsed
437      * @param yangFiles relative paths to the YANG files to be parsed
438      * @param statementParserMode mode of statement parser
439      *
440      * @return effective schema context
441      *
442      * @throws ReactorException if there is an error in one of the parsed YANG sources
443      * @throws FileNotFoundException if one of the specified directories or files does not exist
444      * @throws URISyntaxException if one of the specified directories or files does not exist
445      */
446     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
447             final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
448             URISyntaxException {
449         return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
450     }
451
452     /**
453      * Creates a new effective schema context containing the specified YANG sources.
454      *
455      * @param yangDirs relative paths to the directories containing YANG files to be parsed
456      * @param yangFiles relative paths to the YANG files to be parsed
457      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
458      * @param statementParserMode mode of statement parser
459      *
460      * @return effective schema context
461      *
462      * @throws ReactorException if there is an error in one of the parsed YANG sources
463      * @throws FileNotFoundException if one of the specified directories or files does not exist
464      * @throws URISyntaxException if one of the specified directories or files does not exist
465      */
466     public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
467             final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
468             throws FileNotFoundException, ReactorException, URISyntaxException {
469         final List<File> allYangFiles = new ArrayList<>();
470         for (final String yangDir : yangDirs) {
471             allYangFiles.addAll(getYangFiles(yangDir));
472         }
473
474         for (final String yangFile : yangFiles) {
475             final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
476             allYangFiles.add(new File(filePath));
477         }
478
479         return parseYangSources(allYangFiles, isFeatureSupported, statementParserMode);
480     }
481
482     private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
483         final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
484         final File dir = new File(directoryPath);
485
486         return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
487     }
488
489     /**
490      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
491      * default mode and all YANG features are supported.
492      *
493      * @param filePaths relative paths to the YANG files to be parsed
494      *
495      * @return effective schema context
496      *
497      * @throws ReactorException if there is an error in one of the parsed YANG sources
498      */
499     public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
500         return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
501     }
502
503     /**
504      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
505      * default mode.
506      *
507      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
508      * @param filePaths relative paths to the YANG files to be parsed
509      *
510      * @return effective schema context
511      *
512      * @throws ReactorException if there is an error in one of the parsed YANG sources
513      */
514     public static SchemaContext parseYangSources(final List<String> filePaths, final Predicate<QName> isFeatureSupported)
515             throws ReactorException {
516         return parseYangSources(filePaths, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
517     }
518
519     /**
520      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
521      *
522      * @param statementParserMode mode of statement parser
523      * @param filePaths relative paths to the YANG files to be parsed
524      *
525      * @return effective schema context
526      *
527      * @throws ReactorException if there is an error in one of the parsed YANG sources
528      */
529     public static SchemaContext parseYangSources(final List<String> filePaths,final StatementParserMode statementParserMode)
530             throws ReactorException {
531         return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
532     }
533
534     /**
535      * Creates a new effective schema context containing the specified YANG sources.
536      *
537      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
538      * @param statementParserMode mode of statement parser
539      * @param filePaths relative paths to the YANG files to be parsed
540      *
541      * @return effective schema context
542      *
543      * @throws ReactorException if there is an error in one of the parsed YANG sources
544      */
545     public static SchemaContext parseYangSources(final List<String> filePaths, final Predicate<QName> isFeatureSupported,
546             final StatementParserMode statementParserMode) throws ReactorException {
547         final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
548
549         for (int i = 0; i < filePaths.size(); i++) {
550             sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
551         }
552
553         return parseYangSources(isFeatureSupported, statementParserMode, sources);
554     }
555
556     /**
557      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
558      * default mode and all YANG features are supported.
559      *
560      * @param streams input streams containing YANG sources to be parsed
561      *
562      * @return effective schema context
563      *
564      * @throws ReactorException if there is an error in one of the parsed YANG sources
565      */
566     public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
567         return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
568     }
569
570     /**
571      * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
572      * default mode.
573      *
574      * @param streams input streams containing YANG sources to be parsed
575      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
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, final Predicate<QName> isFeatureSupported)
582             throws ReactorException {
583         return parseYangStreams(streams, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
584     }
585
586     /**
587      * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
588      *
589      * @param streams input streams containing YANG sources to be parsed
590      * @param statementParserMode mode of statement parser
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 StatementParserMode statementParserMode)
597             throws ReactorException {
598         return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
599     }
600
601     /**
602      * Creates a new effective schema context containing the specified YANG sources.
603      *
604      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
605      * @param statementParserMode mode of statement parser
606      * @param streams input streams containing YANG sources to be parsed
607      *
608      * @return effective schema context
609      *
610      * @throws ReactorException if there is an error in one of the parsed YANG sources
611      */
612     public static SchemaContext parseYangStreams(final List<InputStream> streams, final Predicate<QName> isFeatureSupported,
613             final StatementParserMode statementParserMode) throws ReactorException {
614         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
615                 statementParserMode, isFeatureSupported);
616         return reactor.buildEffective(streams);
617     }
618
619     /**
620      * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
621      * default mode and all YANG features are supported.
622      *
623      * @param sources YIN sources to be parsed
624      *
625      * @return effective schema context
626      *
627      * @throws ReactorException if there is an error in one of the parsed YIN sources
628      */
629     public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
630         return parseYinSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
631     }
632
633     /**
634      * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
635      * default mode.
636      *
637      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
638      * @param sources YIN sources to be parsed
639      *
640      * @return effective schema context
641      * @throws ReactorException if there is an error in one of the parsed YIN sources
642      */
643     public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
644             final YinStatementStreamSource... sources) throws ReactorException {
645         return parseYinSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
646     }
647
648     /**
649      * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
650      *
651      * @param statementParserMode mode of statement parser
652      * @param sources YIN sources to be parsed
653      *
654      * @return effective schema context
655      *
656      * @throws ReactorException if there is an error in one of the parsed YIN sources
657      */
658     public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
659             final YinStatementStreamSource... sources) throws ReactorException {
660         return parseYinSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
661     }
662
663     /**
664      * Creates a new effective schema context containing the specified YIN sources.
665      *
666      * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
667      * @param statementParserMode mode of statement parser
668      * @param sources YIN sources to be parsed
669      *
670      * @return effective schema context
671      *
672      * @throws ReactorException if there is an error in one of the parsed YIN sources
673      */
674     public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
675             final StatementParserMode statementParserMode, final YinStatementStreamSource... sources) throws ReactorException {
676         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
677                 statementParserMode, isFeatureSupported);
678         reactor.addSources(sources);
679
680         return reactor.buildEffective();
681     }
682 }