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;
23 import java.util.function.Predicate;
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.IfFeaturePredicates;
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(".yang") && 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(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
69 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
72 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
73 * @param sources YANG sources to be parsed
75 * @return effective schema context
76 * @throws ReactorException if there is an error in one of the parsed YANG sources
78 * @deprecated Migration method only, do not use.
81 public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
82 final YangStatementSourceImpl... sources) throws ReactorException {
83 return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
87 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
89 * @param statementParserMode mode of statement parser
90 * @param sources YANG sources to be parsed
92 * @return effective schema context
93 * @throws ReactorException if there is an error in one of the parsed YANG sources
95 * @deprecated Migration method only, do not use.
98 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
99 final YangStatementSourceImpl... sources) throws ReactorException {
100 return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
104 * Creates a new effective schema context containing the specified YANG sources.
106 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
107 * @param statementParserMode mode of statement parser
108 * @param sources YANG sources to be parsed
110 * @return effective schema context
112 * @throws ReactorException if there is an error in one of the parsed YANG sources
114 public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
115 final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
116 throws ReactorException {
117 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
118 statementParserMode, isFeatureSupported);
119 reactor.addSources(sources);
121 return reactor.buildEffective();
125 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
126 * default mode and all YANG features are supported.
128 * @param files YANG files to be parsed
130 * @return effective schema context
132 * @throws ReactorException if there is an error in one of the parsed YANG sources
133 * @throws FileNotFoundException if one of the specified files does not exist
135 public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
136 return parseYangSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, files);
140 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
143 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
144 * @param files YANG files to be parsed
146 * @return effective schema context
148 * @throws ReactorException if there is an error in one of the parsed YANG sources
149 * @throws FileNotFoundException if one of the specified files does not exist
151 public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported, final File... files)
152 throws ReactorException, FileNotFoundException {
153 return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, files);
157 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
159 * @param statementParserMode mode of statement parser
160 * @param files YANG files to be parsed
162 * @return effective schema context
164 * @throws ReactorException if there is an error in one of the parsed YANG sources
165 * @throws FileNotFoundException if one of the specified files does not exist
167 public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
168 throws ReactorException, FileNotFoundException {
169 return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, files);
173 * Creates a new effective schema context containing the specified YANG sources.
175 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
176 * @param statementParserMode mode of statement parser
177 * @param files YANG files to be parsed
179 * @return effective schema context
181 * @throws ReactorException if there is an error in one of the parsed YANG sources
182 * @throws FileNotFoundException if one of the specified files does not exist
184 public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
185 final StatementParserMode statementParserMode, final File... files) throws ReactorException,
186 FileNotFoundException {
187 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
188 for (int i = 0; i < files.length; i++) {
189 sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
192 return parseYangSources(isFeatureSupported, statementParserMode, sources);
196 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
197 * default mode and all YANG features are supported.
199 * @param files collection of YANG files to be parsed
201 * @return effective schema context
203 * @throws ReactorException if there is an error in one of the parsed YANG sources
204 * @throws FileNotFoundException if one of the specified files does not exist
206 public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
207 FileNotFoundException {
208 return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
212 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
215 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
216 * @param files collection of YANG files to be parsed
218 * @return effective schema context
220 * @throws ReactorException if there is an error in one of the parsed YANG sources
221 * @throws FileNotFoundException if one of the specified files does not exist
223 public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported)
224 throws ReactorException, FileNotFoundException {
225 return parseYangSources(files, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
229 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
231 * @param statementParserMode mode of statement parser
232 * @param files collection of YANG files to be parsed
234 * @return effective schema context
236 * @throws ReactorException if there is an error in one of the parsed YANG sources
237 * @throws FileNotFoundException if one of the specified files does not exist
239 public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
240 throws ReactorException, FileNotFoundException {
241 return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
245 * Creates a new effective schema context containing the specified YANG sources.
247 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
248 * @param statementParserMode mode of statement parser
249 * @param files collection of YANG files to be parsed
251 * @return effective schema context
253 * @throws ReactorException if there is an error in one of the parsed YANG sources
254 * @throws FileNotFoundException if one of the specified files does not exist
256 public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported,
257 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
258 return parseYangSources(isFeatureSupported, statementParserMode, files.toArray(new File[files.size()]));
262 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
263 * default mode and all YANG features are supported.
265 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
267 * @return effective schema context
269 * @throws ReactorException if there is an error in one of the parsed YANG sources
270 * @throws FileNotFoundException if the specified directory does not exist
271 * @throws URISyntaxException if the specified directory does not exist
273 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
274 FileNotFoundException, URISyntaxException {
275 return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES,
276 StatementParserMode.DEFAULT_MODE);
280 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
283 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
284 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
286 * @return effective schema context
288 * @throws ReactorException if there is an error in one of the parsed YANG sources
289 * @throws FileNotFoundException if the specified directory does not exist
290 * @throws URISyntaxException if the specified directory does not exist
292 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
293 final Predicate<QName> isFeatureSupported) throws ReactorException, FileNotFoundException,
295 return parseYangSources(yangSourcesDirectoryPath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
299 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
301 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
302 * @param statementParserMode mode of statement parser
304 * @return effective schema context
306 * @throws ReactorException if there is an error in one of the parsed YANG sources
307 * @throws FileNotFoundException if the specified directory does not exist
308 * @throws URISyntaxException if the specified directory does not exist
310 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
311 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
313 return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
317 * Creates a new effective schema context containing the specified YANG sources.
319 * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
320 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
321 * @param statementParserMode mode of statement parser
323 * @return effective schema context
325 * @throws ReactorException if there is an error in one of the parsed YANG sources
326 * @throws FileNotFoundException if the specified directory does not exist
327 * @throws URISyntaxException if the specified directory does not exist
329 public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
330 final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
331 throws ReactorException, FileNotFoundException, URISyntaxException {
332 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
333 final File dir = new File(directoryPath);
335 return parseYangSources(isFeatureSupported, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
339 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
340 * default mode and all YANG features are supported.
342 * @param yangSourcePath relative path to the YANG file to be parsed
344 * @return effective schema context
346 * @throws ReactorException if there is an error in the parsed YANG source
347 * @throws FileNotFoundException if the specified file does not exist
348 * @throws URISyntaxException if the specified file does not exist
350 public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
351 FileNotFoundException, URISyntaxException {
352 return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
356 * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
359 * @param yangSourcePath relative path to the YANG file to be parsed
360 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
362 * @return effective schema context
364 * @throws ReactorException if there is an error in the parsed YANG source
365 * @throws FileNotFoundException if the specified file does not exist
366 * @throws URISyntaxException if the specified file does not exist
368 public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported)
369 throws ReactorException, FileNotFoundException, URISyntaxException {
370 return parseYangSource(yangSourcePath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
374 * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
376 * @param yangSourcePath relative path to the YANG file to be parsed
377 * @param statementParserMode mode of statement parser
379 * @return effective schema context
381 * @throws ReactorException if there is an error in the parsed YANG source
382 * @throws FileNotFoundException if the specified file does not exist
383 * @throws URISyntaxException if the specified file does not exist
385 public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
386 throws ReactorException, FileNotFoundException, URISyntaxException {
387 return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
391 * Creates a new effective schema context containing the specified YANG source.
393 * @param yangSourcePath relative path to the YANG file to be parsed
394 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
395 * @param statementParserMode mode of statement parser
397 * @return effective schema context
399 * @throws ReactorException if there is an error in the parsed YANG source
400 * @throws FileNotFoundException if the specified file does not exist
401 * @throws URISyntaxException if the specified file does not exist
403 public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported,
404 final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
406 final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
407 final File sourceFile = new File(sourcePath);
408 return parseYangSources(isFeatureSupported, statementParserMode, sourceFile);
412 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
413 * default mode and all YANG features are supported.
415 * @param yangDirs relative paths to the directories containing YANG files to be parsed
416 * @param yangFiles relative paths to the YANG files to be parsed
418 * @return effective schema context
420 * @throws ReactorException if there is an error in one of the parsed YANG sources
421 * @throws FileNotFoundException if one of the specified directories or files does not exist
422 * @throws URISyntaxException if one of the specified directories or files does not exist
424 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
425 throws FileNotFoundException, ReactorException, URISyntaxException {
426 return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
430 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
433 * @param yangDirs relative paths to the directories containing YANG files to be parsed
434 * @param yangFiles relative paths to the YANG files to be parsed
435 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
437 * @return effective schema context
439 * @throws ReactorException if there is an error in one of the parsed YANG sources
440 * @throws FileNotFoundException if one of the specified directories or files does not exist
441 * @throws URISyntaxException if one of the specified directories or files does not exist
443 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
444 final Predicate<QName> isFeatureSupported) throws FileNotFoundException, ReactorException,
446 return parseYangSources(yangDirs, yangFiles, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
450 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
452 * @param yangDirs relative paths to the directories containing YANG files to be parsed
453 * @param yangFiles relative paths to the YANG files to be parsed
454 * @param statementParserMode mode of statement parser
456 * @return effective schema context
458 * @throws ReactorException if there is an error in one of the parsed YANG sources
459 * @throws FileNotFoundException if one of the specified directories or files does not exist
460 * @throws URISyntaxException if one of the specified directories or files does not exist
462 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
463 final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
465 return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
469 * Creates a new effective schema context containing the specified YANG sources.
471 * @param yangDirs relative paths to the directories containing YANG files to be parsed
472 * @param yangFiles relative paths to the YANG files to be parsed
473 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
474 * @param statementParserMode mode of statement parser
476 * @return effective schema context
478 * @throws ReactorException if there is an error in one of the parsed YANG sources
479 * @throws FileNotFoundException if one of the specified directories or files does not exist
480 * @throws URISyntaxException if one of the specified directories or files does not exist
482 public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
483 final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
484 throws FileNotFoundException, ReactorException, URISyntaxException {
485 final List<File> allYangFiles = new ArrayList<>();
486 for (final String yangDir : yangDirs) {
487 allYangFiles.addAll(getYangFiles(yangDir));
490 for (final String yangFile : yangFiles) {
491 final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
492 allYangFiles.add(new File(filePath));
495 return parseYangSources(allYangFiles, isFeatureSupported, statementParserMode);
498 private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
499 final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
500 final File dir = new File(directoryPath);
502 return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
506 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
507 * default mode and all YANG features are supported.
509 * @param filePaths relative paths to the YANG files to be parsed
511 * @return effective schema context
513 * @throws ReactorException if there is an error in one of the parsed YANG sources
515 public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
516 return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
520 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
523 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
524 * @param filePaths relative paths to the YANG files to be parsed
526 * @return effective schema context
528 * @throws ReactorException if there is an error in one of the parsed YANG sources
530 public static SchemaContext parseYangSources(final List<String> filePaths, final Predicate<QName> isFeatureSupported)
531 throws ReactorException {
532 return parseYangSources(filePaths, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
536 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
538 * @param statementParserMode mode of statement parser
539 * @param filePaths relative paths to the YANG files to be parsed
541 * @return effective schema context
543 * @throws ReactorException if there is an error in one of the parsed YANG sources
545 public static SchemaContext parseYangSources(final List<String> filePaths,final StatementParserMode statementParserMode)
546 throws ReactorException {
547 return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
551 * Creates a new effective schema context containing the specified YANG sources.
553 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
554 * @param statementParserMode mode of statement parser
555 * @param filePaths relative paths to the YANG files to be parsed
557 * @return effective schema context
559 * @throws ReactorException if there is an error in one of the parsed YANG sources
561 public static SchemaContext parseYangSources(final List<String> filePaths,
562 final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
563 throws ReactorException {
564 final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
566 for (int i = 0; i < filePaths.size(); i++) {
567 sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
570 return parseYangSources(isFeatureSupported, statementParserMode, sources);
574 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
575 * default mode and all YANG features are supported.
577 * @param streams input streams containing YANG sources to be parsed
579 * @return effective schema context
581 * @throws ReactorException if there is an error in one of the parsed YANG sources
583 public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
584 return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
588 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
591 * @param streams input streams containing YANG sources to be parsed
592 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
594 * @return effective schema context
596 * @throws ReactorException if there is an error in one of the parsed YANG sources
598 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Predicate<QName> isFeatureSupported)
599 throws ReactorException {
600 return parseYangStreams(streams, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
604 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
606 * @param streams input streams containing YANG sources to be parsed
607 * @param statementParserMode mode of statement parser
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 StatementParserMode statementParserMode)
614 throws ReactorException {
615 return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
619 * Creates a new effective schema context containing the specified YANG sources.
621 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
622 * @param statementParserMode mode of statement parser
623 * @param streams input streams containing YANG sources to be parsed
625 * @return effective schema context
627 * @throws ReactorException if there is an error in one of the parsed YANG sources
629 public static SchemaContext parseYangStreams(final List<InputStream> streams, final Predicate<QName> isFeatureSupported,
630 final StatementParserMode statementParserMode) throws ReactorException {
631 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
632 statementParserMode, isFeatureSupported);
633 return reactor.buildEffective(streams);
637 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
638 * default mode and all YANG features are supported.
640 * @param clazz Resource lookup base
641 * @param resources Resource names to be looked up
643 * @return effective schema context
645 * @throws ReactorException if there is an error in one of the parsed YANG sources
647 public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
648 throws ReactorException {
649 final List<InputStream> streams = new ArrayList<>(resources.length);
650 for (String r : resources) {
651 final InputStream is = clazz.getResourceAsStream(r);
652 Preconditions.checkArgument(is != null, "Resource %s not found", r);
656 return parseYangStreams(streams);
660 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
661 * default mode and all YANG features are supported.
663 * @param streams input streams containing YANG sources to be parsed
665 * @return effective schema context
667 * @throws ReactorException if there is an error in one of the parsed YANG sources
669 public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
670 return parseYangStreams(Arrays.asList(streams));
674 * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
677 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
678 * @param streams input streams containing YANG sources to be parsed
680 * @return effective schema context
682 * @throws ReactorException if there is an error in one of the parsed YANG sources
684 public static SchemaContext parseYangStreams(final Predicate<QName> isFeatureSupported,
685 final InputStream... streams) throws ReactorException {
686 return parseYangStreams(Arrays.asList(streams), isFeatureSupported);
690 * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
692 * @param statementParserMode mode of statement parser
693 * @param streams input streams containing YANG sources to be parsed
695 * @return effective schema context
697 * @throws ReactorException if there is an error in one of the parsed YANG sources
699 public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
700 final InputStream... streams) throws ReactorException {
701 return parseYangStreams(Arrays.asList(streams), statementParserMode);
705 * Creates a new effective schema context containing the specified YANG sources.
707 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
708 * @param statementParserMode mode of statement parser
709 * @param streams input streams containing YANG sources to be parsed
711 * @return effective schema context
713 * @throws ReactorException if there is an error in one of the parsed YANG sources
715 public static SchemaContext parseYangStreams(final Predicate<QName> isFeatureSupported,
716 final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
717 return parseYangStreams(Arrays.asList(streams), isFeatureSupported, statementParserMode);
721 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
722 * default mode and all YANG features are supported.
724 * @param sources YIN sources to be parsed
726 * @return effective schema context
728 * @throws ReactorException if there is an error in one of the parsed YIN sources
730 public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
731 return parseYinSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
735 * Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
738 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
739 * @param sources YIN sources to be parsed
741 * @return effective schema context
742 * @throws ReactorException if there is an error in one of the parsed YIN sources
744 public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
745 final YinStatementStreamSource... sources) throws ReactorException {
746 return parseYinSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
750 * Creates a new effective schema context containing the specified YIN sources. All YANG features are supported.
752 * @param statementParserMode mode of statement parser
753 * @param sources YIN sources to be parsed
755 * @return effective schema context
757 * @throws ReactorException if there is an error in one of the parsed YIN sources
759 public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
760 final YinStatementStreamSource... sources) throws ReactorException {
761 return parseYinSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
765 * Creates a new effective schema context containing the specified YIN sources.
767 * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
768 * @param statementParserMode mode of statement parser
769 * @param sources YIN sources to be parsed
771 * @return effective schema context
773 * @throws ReactorException if there is an error in one of the parsed YIN sources
775 public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
776 final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
777 throws ReactorException {
778 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
779 statementParserMode, isFeatureSupported);
780 reactor.addSources(sources);
782 return reactor.buildEffective();