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.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;
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
39 public final class YangParserTestUtils {
41 private static final FileFilter YANG_FILE_FILTER = file -> {
42 final String name = file.getName().toLowerCase();
43 return name.endsWith(".yang") && file.isFile();
46 private YangParserTestUtils() {
47 throw new UnsupportedOperationException("Utility class should not be instantiated.");
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.
54 * @param sources YANG sources to be parsed
56 * @return effective schema context
58 * @throws ReactorException if there is an error in one of the parsed YANG sources
60 * @deprecated Migration method only, do not use.
63 public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
64 return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
68 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
74 * @return effective schema context
75 * @throws ReactorException if there is an error in one of the parsed YANG sources
77 * @deprecated Migration method only, do not use.
80 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
81 final YangStatementSourceImpl... sources) throws ReactorException {
82 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
86 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
88 * @param statementParserMode mode of statement parser
89 * @param sources YANG sources to be parsed
91 * @return effective schema context
92 * @throws ReactorException if there is an error in one of the parsed YANG sources
94 * @deprecated Migration method only, do not use.
97 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
98 final YangStatementSourceImpl... sources) throws ReactorException {
99 return parseYangSources(null, statementParserMode, sources);
103 * Creates a new effective schema context containing the specified YANG sources.
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
109 * @return effective schema context
111 * @throws ReactorException if there is an error in one of the parsed YANG sources
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);
120 return reactor.buildEffective();
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.
127 * @param files YANG files to be parsed
129 * @return effective schema context
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
134 public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
135 return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
139 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
145 * @return effective schema context
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
150 public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
151 throws ReactorException, FileNotFoundException {
152 return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
156 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
158 * @param statementParserMode mode of statement parser
159 * @param files YANG files to be parsed
161 * @return effective schema context
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
166 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
167 throws ReactorException, FileNotFoundException {
168 return parseYangSources(null, statementParserMode, files);
172 * Creates a new effective schema context containing the specified YANG sources.
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
178 * @return effective schema context
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
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()));
191 return parseYangSources(supportedFeatures, statementParserMode, sources);
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.
198 * @param files collection of YANG files to be parsed
200 * @return effective schema context
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
205 public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
206 FileNotFoundException {
207 return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
211 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
217 * @return effective schema context
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
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);
228 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
230 * @param statementParserMode mode of statement parser
231 * @param files collection of YANG files to be parsed
233 * @return effective schema context
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
238 public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
239 throws ReactorException, FileNotFoundException {
240 return parseYangSources(files, null, statementParserMode);
244 * Creates a new effective schema context containing the specified YANG sources.
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
250 * @return effective schema context
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
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()]));
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.
264 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
266 * @return effective schema context
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
272 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
273 FileNotFoundException, URISyntaxException {
274 return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
278 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
284 * @return effective schema context
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
290 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
291 final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
293 return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
297 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
299 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
300 * @param statementParserMode mode of statement parser
302 * @return effective schema context
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
308 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
309 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
311 return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
315 * Creates a new effective schema context containing the specified YANG sources.
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
321 * @return effective schema context
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
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);
333 return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
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.
340 * @param yangSourcePath relative path to the YANG file to be parsed
342 * @return effective schema context
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
348 public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
349 FileNotFoundException, URISyntaxException {
350 return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
354 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
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
360 * @return effective schema context
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
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);
372 * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
374 * @param yangSourcePath relative path to the YANG file to be parsed
375 * @param statementParserMode mode of statement parser
377 * @return effective schema context
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
383 public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
384 throws ReactorException, FileNotFoundException, URISyntaxException {
385 return parseYangSource(yangSourcePath, null, statementParserMode);
389 * Creates a new effective schema context containing the specified YANG source.
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
395 * @return effective schema context
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
401 public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
402 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
404 final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
405 final File sourceFile = new File(sourcePath);
406 return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
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.
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
416 * @return effective schema context
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
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);
428 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
435 * @return effective schema context
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
441 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
442 final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
444 return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
448 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
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
454 * @return effective schema context
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
460 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
461 final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
463 return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
467 * Creates a new effective schema context containing the specified YANG sources.
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
474 * @return effective schema context
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
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));
488 for (final String yangFile : yangFiles) {
489 final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
490 allYangFiles.add(new File(filePath));
493 return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
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);
500 return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
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.
507 * @param filePaths relative paths to the YANG files to be parsed
509 * @return effective schema context
511 * @throws ReactorException if there is an error in one of the parsed YANG sources
513 public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
514 return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
518 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
524 * @return effective schema context
526 * @throws ReactorException if there is an error in one of the parsed YANG sources
528 public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
529 throws ReactorException {
530 return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
534 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
536 * @param statementParserMode mode of statement parser
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,
544 final StatementParserMode statementParserMode) throws ReactorException {
545 return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
549 * Creates a new effective schema context containing the specified YANG sources.
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
555 * @return effective schema context
557 * @throws ReactorException if there is an error in one of the parsed YANG sources
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()];
564 for (int i = 0; i < filePaths.size(); i++) {
565 sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
568 return parseYangSources(supportedFeatures, statementParserMode, sources);
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.
575 * @param streams input streams containing YANG sources to be parsed
577 * @return effective schema context
579 * @throws ReactorException if there is an error in one of the parsed YANG sources
581 public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
582 return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
586 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
592 * @return effective schema context
594 * @throws ReactorException if there is an error in one of the parsed YANG sources
596 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
597 throws ReactorException {
598 return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
602 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
604 * @param streams input streams containing YANG sources to be parsed
605 * @param statementParserMode mode of statement parser
607 * @return effective schema context
609 * @throws ReactorException if there is an error in one of the parsed YANG sources
611 public static SchemaContext parseYangStreams(final List<InputStream> streams, final StatementParserMode statementParserMode)
612 throws ReactorException {
613 return parseYangStreams(streams, null, statementParserMode);
617 * Creates a new effective schema context containing the specified YANG sources.
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
623 * @return effective schema context
625 * @throws ReactorException if there is an error in one of the parsed YANG sources
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);
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.
638 * @param clazz Resource lookup base
639 * @param resources Resource names to be looked up
641 * @return effective schema context
643 * @throws ReactorException if there is an error in one of the parsed YANG sources
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);
654 return parseYangStreams(streams);
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.
661 * @param streams input streams containing YANG sources to be parsed
663 * @return effective schema context
665 * @throws ReactorException if there is an error in one of the parsed YANG sources
667 public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
668 return parseYangStreams(Arrays.asList(streams));
672 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
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
678 * @return effective schema context
680 * @throws ReactorException if there is an error in one of the parsed YANG sources
682 public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
683 final InputStream... streams) throws ReactorException {
684 return parseYangStreams(Arrays.asList(streams), supportedFeatures);
688 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
690 * @param statementParserMode mode of statement parser
691 * @param streams input streams containing YANG sources to be parsed
693 * @return effective schema context
695 * @throws ReactorException if there is an error in one of the parsed YANG sources
697 public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
698 final InputStream... streams) throws ReactorException {
699 return parseYangStreams(Arrays.asList(streams), statementParserMode);
703 * Creates a new effective schema context containing the specified YANG sources.
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
709 * @return effective schema context
711 * @throws ReactorException if there is an error in one of the parsed YANG sources
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);
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.
722 * @param sources YIN sources to be parsed
724 * @return effective schema context
726 * @throws ReactorException if there is an error in one of the parsed YIN sources
728 public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
729 return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
733 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
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
739 * @return effective schema context
740 * @throws ReactorException if there is an error in one of the parsed YIN sources
742 public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
743 final YinStatementStreamSource... sources) throws ReactorException {
744 return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
748 * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
750 * @param statementParserMode mode of statement parser
751 * @param sources YIN sources to be parsed
753 * @return effective schema context
755 * @throws ReactorException if there is an error in one of the parsed YIN sources
757 public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
758 final YinStatementStreamSource... sources) throws ReactorException {
759 return parseYinSources(null, statementParserMode, sources);
763 * Creates a new effective schema context containing the specified YIN sources.
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
769 * @return effective schema context
771 * @throws ReactorException if there is an error in one of the parsed YIN sources
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);
780 return reactor.buildEffective();