2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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
8 package org.opendaylight.yangtools.yang.model.parser.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.SetMultimap;
12 import java.io.IOException;
13 import java.util.Collection;
14 import java.util.List;
16 import javax.annotation.Nonnull;
17 import javax.annotation.concurrent.NotThreadSafe;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
22 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
25 * Configurable single-use YANG parser. Each instance can be configured to use a different set of models after
26 * which it is built. Models once added cannot be removed.
28 * @author Robert Varga
32 public interface YangParser {
34 * Return enumeration of concrete types of {@link SchemaSourceRepresentation} parsers created from this factory
35 * support. Users can use this information prepare the source they have to a representation which will be accepted
38 * @return Enumeration of supported schema source representations.
40 Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations();
43 * Return the set of all YANG statements semantically supported by this parser instance.
45 * @return Set of all YANG statements semantically supported by this parser instance.
47 Set<QName> supportedStatements();
50 * Add main source. All main sources are present in resulting SchemaContext.
53 * which should be added into main sources
54 * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
55 * @throws IOException when an IO error occurs
56 * @throws IllegalArgumentException if the representation is not supported
58 YangParser addSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
61 * Add main sources. All main sources are present in resulting SchemaContext.
64 * which should be added into main sources
65 * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
66 * @throws IOException when an IO error occurs
67 * @throws IllegalArgumentException if the representation is not supported
69 default YangParser addSources(final SchemaSourceRepresentation... sources) throws IOException,
70 YangSyntaxErrorException {
71 for (SchemaSourceRepresentation source : sources) {
77 default YangParser addSources(final Collection<? extends SchemaSourceRepresentation> sources) throws IOException,
78 YangSyntaxErrorException {
79 for (SchemaSourceRepresentation source : sources) {
85 YangParser addLibSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
88 * Add library sources. Only library sources required by main sources are present in resulting SchemaContext.
89 * Any other library sources are ignored and this also applies to error reporting.
92 * Note: Library sources are not supported in semantic version mode currently.
95 * YANG sources which should be added into library sources
96 * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
97 * @throws IOException when an IO error occurs
98 * @throws IllegalArgumentException if the representation is not supported
100 default YangParser addLibSources(final SchemaSourceRepresentation... sources) throws IOException,
101 YangSyntaxErrorException {
102 for (SchemaSourceRepresentation source : sources) {
103 addLibSource(source);
108 default YangParser addLibSources(final Collection<SchemaSourceRepresentation> sources) throws IOException,
109 YangSyntaxErrorException {
110 for (SchemaSourceRepresentation source : sources) {
111 addLibSource(source);
117 * Set supported features based on which all if-feature statements in the
118 * parsed YANG modules will be resolved. If this method is not invoked, all features will be supported.
120 * @param supportedFeatures
121 * Set of supported features in the final SchemaContext.
122 * If the set is empty, no features encountered will be supported.
124 YangParser setSupportedFeatures(@Nonnull final Set<QName> supportedFeatures);
127 * Set YANG modules which can be deviated by specified modules during the parsing process.
128 * Map key (QNameModule) denotes a module which can be deviated by the modules in the Map value.
130 * @param modulesDeviatedByModules
131 * Map of YANG modules (Map key) which can be deviated by specified modules (Map value) in the final
132 * SchemaContext. If the map is empty, no deviations encountered will be supported.
134 YangParser setModulesWithSupportedDeviations(
135 @Nonnull SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules);
138 * Build the declared view of a combined view of declared statements.
140 * @return Ordered collection of declared statements from requested sources.
142 List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException;
145 * Build effective {@link SchemaContext}
147 * @return An effective schema context comprised of configured models.
148 * @throws YangSyntaxErrorException When a syntactic error is encountered.
150 SchemaContext buildSchemaContext() throws YangParserException;