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
9 package org.opendaylight.yangtools.yang.test.util;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
14 import java.io.FileFilter;
15 import java.io.FileNotFoundException;
16 import java.io.InputStream;
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;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.common.YangConstants;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
28 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
32 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
33 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
36 * Utility class which provides convenience methods for producing effective schema context based on the supplied
37 * yang/yin sources or paths to these sources
40 public final class YangParserTestUtils {
42 private static final FileFilter YANG_FILE_FILTER = file -> {
43 final String name = file.getName().toLowerCase();
44 return name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION) && file.isFile();
47 private YangParserTestUtils() {
48 throw new UnsupportedOperationException("Utility class should not be instantiated.");
52 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
53 * default mode and all YANG features are supported.
55 * @param sources YANG sources to be parsed
57 * @return effective schema context
59 * @throws ReactorException if there is an error in one of the parsed YANG sources
61 * @deprecated Migration method only, do not use.
64 public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
65 return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
69 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
72 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
74 * @param sources YANG sources to be parsed
76 * @return effective schema context
77 * @throws ReactorException if there is an error in one of the parsed YANG sources
79 * @deprecated Migration method only, do not use.
82 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
83 final YangStatementSourceImpl... sources) throws ReactorException {
84 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
88 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
90 * @param statementParserMode mode of statement parser
91 * @param sources YANG sources to be parsed
93 * @return effective schema context
94 * @throws ReactorException if there is an error in one of the parsed YANG sources
96 * @deprecated Migration method only, do not use.
99 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
100 final YangStatementSourceImpl... sources) throws ReactorException {
101 return parseYangSources(null, statementParserMode, sources);
105 * Creates a new effective schema context containing the specified YANG sources.
107 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
108 * models are resolved
109 * @param statementParserMode mode of statement parser
110 * @param sources YANG sources to be parsed
112 * @return effective schema context
114 * @throws ReactorException if there is an error in one of the parsed YANG sources
116 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
117 final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
118 throws ReactorException {
119 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
120 statementParserMode, supportedFeatures);
121 reactor.addSources(sources);
123 return reactor.buildEffective();
127 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
128 * default mode and all YANG features are supported.
130 * @param files YANG files to be parsed
132 * @return effective schema context
134 * @throws ReactorException if there is an error in one of the parsed YANG sources
135 * @throws FileNotFoundException if one of the specified files does not exist
137 public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
138 return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
142 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
145 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
146 * models are resolved
147 * @param files YANG files to be parsed
149 * @return effective schema context
151 * @throws ReactorException if there is an error in one of the parsed YANG sources
152 * @throws FileNotFoundException if one of the specified files does not exist
154 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
155 throws ReactorException, FileNotFoundException {
156 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
160 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
162 * @param statementParserMode mode of statement parser
163 * @param files YANG files to be parsed
165 * @return effective schema context
167 * @throws ReactorException if there is an error in one of the parsed YANG sources
168 * @throws FileNotFoundException if one of the specified files does not exist
170 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
171 throws ReactorException, FileNotFoundException {
172 return parseYangSources(null, statementParserMode, files);
176 * Creates a new effective schema context containing the specified YANG sources.
178 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
179 * models are resolved
180 * @param statementParserMode mode of statement parser
181 * @param files YANG files to be parsed
183 * @return effective schema context
185 * @throws ReactorException if there is an error in one of the parsed YANG sources
186 * @throws FileNotFoundException if one of the specified files does not exist
188 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
189 final StatementParserMode statementParserMode, final File... files) throws ReactorException,
190 FileNotFoundException {
191 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
192 for (int i = 0; i < files.length; i++) {
193 sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
196 return parseYangSources(supportedFeatures, statementParserMode, sources);
200 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
201 * default mode and all YANG features are supported.
203 * @param files collection of YANG files to be parsed
205 * @return effective schema context
207 * @throws ReactorException if there is an error in one of the parsed YANG sources
208 * @throws FileNotFoundException if one of the specified files does not exist
210 public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
211 FileNotFoundException {
212 return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
216 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
219 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
220 * models are resolved
221 * @param files collection of YANG files to be parsed
223 * @return effective schema context
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
228 public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
229 throws ReactorException, FileNotFoundException {
230 return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
234 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
236 * @param statementParserMode mode of statement parser
237 * @param files collection of YANG files to be parsed
239 * @return effective schema context
241 * @throws ReactorException if there is an error in one of the parsed YANG sources
242 * @throws FileNotFoundException if one of the specified files does not exist
244 public static SchemaContext parseYangSources(final Collection<File> files,
245 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
246 return parseYangSources(files, null, statementParserMode);
250 * Creates a new effective schema context containing the specified YANG sources.
252 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
253 * models are resolved
254 * @param statementParserMode mode of statement parser
255 * @param files collection of YANG files to be parsed
257 * @return effective schema context
259 * @throws ReactorException if there is an error in one of the parsed YANG sources
260 * @throws FileNotFoundException if one of the specified files does not exist
262 public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
263 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
264 return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
268 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
269 * default mode and all YANG features are supported.
271 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
273 * @return effective schema context
275 * @throws ReactorException if there is an error in one of the parsed YANG sources
276 * @throws FileNotFoundException if the specified directory does not exist
277 * @throws URISyntaxException if the specified directory does not exist
279 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
280 FileNotFoundException, URISyntaxException {
281 return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
285 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
288 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
289 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
290 * models are resolved
292 * @return effective schema context
294 * @throws ReactorException if there is an error in one of the parsed YANG sources
295 * @throws FileNotFoundException if the specified directory does not exist
296 * @throws URISyntaxException if the specified directory does not exist
298 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
299 final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
301 return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
305 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
307 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
308 * @param statementParserMode mode of statement parser
310 * @return effective schema context
312 * @throws ReactorException if there is an error in one of the parsed YANG sources
313 * @throws FileNotFoundException if the specified directory does not exist
314 * @throws URISyntaxException if the specified directory does not exist
316 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
317 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
319 return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
323 * Creates a new effective schema context containing the specified YANG sources.
325 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
326 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
327 * models are resolved
328 * @param statementParserMode mode of statement parser
330 * @return effective schema context
332 * @throws ReactorException if there is an error in one of the parsed YANG sources
333 * @throws FileNotFoundException if the specified directory does not exist
334 * @throws URISyntaxException if the specified directory does not exist
336 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
337 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
338 throws ReactorException, FileNotFoundException, URISyntaxException {
339 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
340 final File dir = new File(directoryPath);
342 return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
346 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
347 * default mode and all YANG features are supported.
349 * @param yangSourcePath relative path to the YANG file to be parsed
351 * @return effective schema context
353 * @throws ReactorException if there is an error in the parsed YANG source
354 * @throws FileNotFoundException if the specified file does not exist
355 * @throws URISyntaxException if the specified file does not exist
357 public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
358 FileNotFoundException, URISyntaxException {
359 return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
363 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
366 * @param yangSourcePath relative path to the YANG file to be parsed
367 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
370 * @return effective schema context
372 * @throws ReactorException if there is an error in the parsed YANG source
373 * @throws FileNotFoundException if the specified file does not exist
374 * @throws URISyntaxException if the specified file does not exist
376 public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
377 throws ReactorException, FileNotFoundException, URISyntaxException {
378 return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
382 * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
384 * @param yangSourcePath relative path to the YANG file to be parsed
385 * @param statementParserMode mode of statement parser
387 * @return effective schema context
389 * @throws ReactorException if there is an error in the parsed YANG source
390 * @throws FileNotFoundException if the specified file does not exist
391 * @throws URISyntaxException if the specified file does not exist
393 public static SchemaContext parseYangSource(final String yangSourcePath,
394 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
396 return parseYangSource(yangSourcePath, null, statementParserMode);
400 * Creates a new effective schema context containing the specified YANG source.
402 * @param yangSourcePath relative path to the YANG file to be parsed
403 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
405 * @param statementParserMode mode of statement parser
407 * @return effective schema context
409 * @throws ReactorException if there is an error in the parsed YANG source
410 * @throws FileNotFoundException if the specified file does not exist
411 * @throws URISyntaxException if the specified file does not exist
413 public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
414 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
416 final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
417 final File sourceFile = new File(sourcePath);
418 return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
422 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
423 * default mode and all YANG features are supported.
425 * @param yangDirs relative paths to the directories containing YANG files to be parsed
426 * @param yangFiles relative paths to the YANG files to be parsed
428 * @return effective schema context
430 * @throws ReactorException if there is an error in one of the parsed YANG sources
431 * @throws FileNotFoundException if one of the specified directories or files does not exist
432 * @throws URISyntaxException if one of the specified directories or files does not exist
434 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
435 throws FileNotFoundException, ReactorException, URISyntaxException {
436 return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
440 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
443 * @param yangDirs relative paths to the directories containing YANG files to be parsed
444 * @param yangFiles relative paths to the YANG files to be parsed
445 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
446 * models are resolved
448 * @return effective schema context
450 * @throws ReactorException if there is an error in one of the parsed YANG sources
451 * @throws FileNotFoundException if one of the specified directories or files does not exist
452 * @throws URISyntaxException if one of the specified directories or files does not exist
454 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
455 final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
457 return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
461 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
463 * @param yangDirs relative paths to the directories containing YANG files to be parsed
464 * @param yangFiles relative paths to the YANG files to be parsed
465 * @param statementParserMode mode of statement parser
467 * @return effective schema context
469 * @throws ReactorException if there is an error in one of the parsed YANG sources
470 * @throws FileNotFoundException if one of the specified directories or files does not exist
471 * @throws URISyntaxException if one of the specified directories or files does not exist
473 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
474 final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
476 return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
480 * Creates a new effective schema context containing the specified YANG sources.
482 * @param yangDirs relative paths to the directories containing YANG files to be parsed
483 * @param yangFiles relative paths to the YANG files to be parsed
484 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
485 * models are resolved
486 * @param statementParserMode mode of statement parser
488 * @return effective schema context
490 * @throws ReactorException if there is an error in one of the parsed YANG sources
491 * @throws FileNotFoundException if one of the specified directories or files does not exist
492 * @throws URISyntaxException if one of the specified directories or files does not exist
494 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
495 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
496 throws FileNotFoundException, ReactorException, URISyntaxException {
497 final List<File> allYangFiles = new ArrayList<>();
498 for (final String yangDir : yangDirs) {
499 allYangFiles.addAll(getYangFiles(yangDir));
502 for (final String yangFile : yangFiles) {
503 final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
504 allYangFiles.add(new File(filePath));
507 return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
510 private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
511 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
512 final File dir = new File(directoryPath);
514 return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
518 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
519 * default mode and all YANG features are supported.
521 * @param filePaths relative paths to the YANG files to be parsed
523 * @return effective schema context
525 * @throws ReactorException if there is an error in one of the parsed YANG sources
527 public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
528 return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
532 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
535 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
536 * models are resolved
537 * @param filePaths relative paths to the YANG files to be parsed
539 * @return effective schema context
541 * @throws ReactorException if there is an error in one of the parsed YANG sources
543 public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
544 throws ReactorException {
545 return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
549 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
551 * @param statementParserMode mode of statement parser
552 * @param filePaths relative paths to the YANG files to be parsed
554 * @return effective schema context
556 * @throws ReactorException if there is an error in one of the parsed YANG sources
558 public static SchemaContext parseYangSources(final List<String> filePaths,
559 final StatementParserMode statementParserMode) throws ReactorException {
560 return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
564 * Creates a new effective schema context containing the specified YANG sources.
566 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
567 * models are resolved
568 * @param statementParserMode mode of statement parser
569 * @param filePaths relative paths to the YANG files to be parsed
571 * @return effective schema context
573 * @throws ReactorException if there is an error in one of the parsed YANG sources
575 public static SchemaContext parseYangSources(final List<String> filePaths,
576 final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
577 throws ReactorException {
578 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
580 for (int i = 0; i < filePaths.size(); i++) {
581 sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
584 return parseYangSources(supportedFeatures, statementParserMode, sources);
588 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
589 * default mode and all YANG features are supported.
591 * @param streams input streams containing YANG sources to be parsed
593 * @return effective schema context
595 * @throws ReactorException if there is an error in one of the parsed YANG sources
597 public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
598 return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
602 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
605 * @param streams input streams containing YANG sources to be parsed
606 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
607 * models are resolved
609 * @return effective schema context
611 * @throws ReactorException if there is an error in one of the parsed YANG sources
613 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
614 throws ReactorException {
615 return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
619 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
621 * @param streams input streams containing YANG sources to be parsed
622 * @param statementParserMode mode of statement parser
624 * @return effective schema context
626 * @throws ReactorException if there is an error in one of the parsed YANG sources
628 public static SchemaContext parseYangStreams(final List<InputStream> streams,
629 final StatementParserMode statementParserMode) throws ReactorException {
630 return parseYangStreams(streams, null, statementParserMode);
634 * Creates a new effective schema context containing the specified YANG sources.
636 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
637 * models are resolved
638 * @param statementParserMode mode of statement parser
639 * @param streams input streams containing YANG sources to be parsed
641 * @return effective schema context
643 * @throws ReactorException if there is an error in one of the parsed YANG sources
645 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
646 final StatementParserMode statementParserMode) throws ReactorException {
647 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
648 statementParserMode, supportedFeatures);
649 return reactor.buildEffective(streams);
653 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
654 * default mode and all YANG features are supported.
656 * @param clazz Resource lookup base
657 * @param resources Resource names to be looked up
659 * @return effective schema context
661 * @throws ReactorException if there is an error in one of the parsed YANG sources
663 public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
664 throws ReactorException {
665 final List<InputStream> streams = new ArrayList<>(resources.length);
666 for (final String r : resources) {
667 final InputStream is = clazz.getResourceAsStream(r);
668 Preconditions.checkArgument(is != null, "Resource %s not found", r);
672 return parseYangStreams(streams);
676 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
677 * default mode and all YANG features are supported.
679 * @param streams input streams containing YANG sources to be parsed
681 * @return effective schema context
683 * @throws ReactorException if there is an error in one of the parsed YANG sources
685 public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
686 return parseYangStreams(Arrays.asList(streams));
690 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
693 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
694 * models are resolved
695 * @param streams input streams containing YANG sources to be parsed
697 * @return effective schema context
699 * @throws ReactorException if there is an error in one of the parsed YANG sources
701 public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
702 final InputStream... streams) throws ReactorException {
703 return parseYangStreams(Arrays.asList(streams), supportedFeatures);
707 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
709 * @param statementParserMode mode of statement parser
710 * @param streams input streams containing YANG sources to be parsed
712 * @return effective schema context
714 * @throws ReactorException if there is an error in one of the parsed YANG sources
716 public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
717 final InputStream... streams) throws ReactorException {
718 return parseYangStreams(Arrays.asList(streams), statementParserMode);
722 * Creates a new effective schema context containing the specified YANG sources.
724 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
725 * models are resolved
726 * @param statementParserMode mode of statement parser
727 * @param streams input streams containing YANG sources to be parsed
729 * @return effective schema context
731 * @throws ReactorException if there is an error in one of the parsed YANG sources
733 public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
734 final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
735 return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
739 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
740 * default mode and all YANG features are supported.
742 * @param sources YIN sources to be parsed
744 * @return effective schema context
746 * @throws ReactorException if there is an error in one of the parsed YIN sources
748 public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
749 return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
753 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
756 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
757 * models are resolved
758 * @param sources YIN sources to be parsed
760 * @return effective schema context
761 * @throws ReactorException if there is an error in one of the parsed YIN sources
763 public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
764 final YinStatementStreamSource... sources) throws ReactorException {
765 return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
769 * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
771 * @param statementParserMode mode of statement parser
772 * @param sources YIN sources to be parsed
774 * @return effective schema context
776 * @throws ReactorException if there is an error in one of the parsed YIN sources
778 public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
779 final YinStatementStreamSource... sources) throws ReactorException {
780 return parseYinSources(null, statementParserMode, sources);
784 * Creates a new effective schema context containing the specified YIN sources.
786 * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
787 * models are resolved
788 * @param statementParserMode mode of statement parser
789 * @param sources YIN sources to be parsed
791 * @return effective schema context
793 * @throws ReactorException if there is an error in one of the parsed YIN sources
795 public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
796 final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
797 throws ReactorException {
798 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
799 statementParserMode, supportedFeatures);
800 reactor.addSources(sources);
802 return reactor.buildEffective();