2 * Copyright (c) 2015 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
8 package org.opendaylight.yangtools.yang.parser.spi.source;
10 import org.opendaylight.yangtools.concepts.Identifiable;
11 import org.opendaylight.yangtools.yang.common.YangVersion;
12 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
15 * Statement stream source, which is used for inference of effective model.
18 * Statement stream source is required to emit its statements using supplied
19 * {@link StatementWriter}.
22 * Since YANG allows language extensions defined in sources (which defines how
23 * source is serialized), instances of extensions present anywhere and forward
24 * references, each source needs to be processed in three steps, where each step
25 * uses different set of supported statements.
28 * Steps (in order of invocation) are:
30 * <li>{@link #writePreLinkage(StatementWriter, QNameToStatementDefinition)} -
31 * Source MUST emit only statements related in pre-linkage, which are present in
32 * supplied statement definition map. This step is used as preparatory cross-source
33 * relationship resolution phase which collects available module names and namespaces.
34 * It is necessary in order to correct resolution of unknown statements used by linkage
35 * phase (e.g. semantic version of yang modules).
37 * <li>{@link #writeLinkage(StatementWriter, QNameToStatementDefinition, PrefixToModule)} -
38 * Source MUST emit only statements related in linkage, which are present in
39 * supplied statement definition map. This step is used to build cross-source
40 * linkage and visibility relationship, and to determine XMl namespaces and
43 * {@link #writeLinkageAndStatementDefinitions(StatementWriter, QNameToStatementDefinition, PrefixToModule)}
44 * - Source MUST emit only statements related to linkage and language extensions
45 * definitions, which are present in supplied statement definition map. This
46 * step is used to build statement definitions in order to fully processed
49 * {@link #writeFull(StatementWriter, QNameToStatementDefinition, PrefixToModule)}
50 * - Source MUST emit all statements present in source. This step is used to
51 * build full declared statement model of source.</li>
54 public interface StatementStreamSource extends Identifiable<SourceIdentifier> {
57 * Emits only pre-linkage-related statements to supplied {@code writer}.
60 * {@link StatementWriter} which should be used to emit
63 * Map of available statement definitions. Only these statements
64 * may be written to statement writer, source MUST ignore and MUST NOT
65 * emit any other statements.
66 * @throws SourceException
67 * If source was is not valid, or provided statement writer
68 * failed to write statements.
70 void writePreLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef);
73 * Emits only linkage-related statements to supplied {@code writer}.
76 * {@link StatementWriter} which should be used to emit
79 * Map of available statement definitions. Only these statements
80 * may be written to statement writer, source MUST ignore and MUST NOT
81 * emit any other statements.
82 * @param preLinkagePrefixes
83 * Pre-linkage map of source-specific prefixes to namespaces
84 * @throws SourceException
85 * If source was is not valid, or provided statement writer
86 * failed to write statements.
88 void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule preLinkagePrefixes);
91 * Emits only linkage-related statements to supplied {@code writer} based on specified YANG version.
92 * Default implementation does not make any differences between versions.
95 * {@link StatementWriter} which should be used to emit
98 * Map of available statement definitions. Only these statements
99 * may be written to statement writer, source MUST ignore and
100 * MUST NOT emit any other statements.
101 * @param preLinkagePrefixes
102 * Pre-linkage map of source-specific prefixes to namespaces
105 * @throws SourceException
106 * If source was is not valid, or provided statement writer
107 * failed to write statements.
109 default void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
110 final PrefixToModule preLinkagePrefixes, final YangVersion yangVersion) {
111 writeLinkage(writer, stmtDef, preLinkagePrefixes);
115 * Emits only linkage and language extension statements to supplied {@code writer}.
118 * {@link StatementWriter} which should be used to emit statements.
120 * Map of available statement definitions. Only these statements
121 * may be written to statement writer, source MUST ignore and MUST NOT
122 * emit any other statements.
124 * Map of source-specific prefixes to namespaces
125 * @throws SourceException
126 * If source was is not valid, or provided statement writer
127 * failed to write statements.
129 void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
130 PrefixToModule prefixes);
133 * Emits only linkage and language extension statements to supplied
134 * {@code writer} based on specified YANG version. Default implementation
135 * does not make any differences between versions.
138 * {@link StatementWriter} which should be used to emit
141 * Map of available statement definitions. Only these statements
142 * may be written to statement writer, source MUST ignore and
143 * MUST NOT emit any other statements.
145 * Map of source-specific prefixes to namespaces
149 * @throws SourceException
150 * If source was is not valid, or provided statement writer
151 * failed to write statements.
153 default void writeLinkageAndStatementDefinitions(final StatementWriter writer,
154 final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
155 writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes);
159 * Emits every statements present in this statement source to supplied {@code writer}.
162 * {@link StatementWriter} which should be used to emit
165 * Map of available statement definitions.
167 * Map of source-specific prefixes to namespaces
168 * @throws SourceException
169 * If source was is not valid, or provided statement writer
170 * failed to write statements.
172 void writeFull(StatementWriter writer,QNameToStatementDefinition stmtDef, PrefixToModule prefixes);
175 * Emits every statements present in this statement source to supplied
176 * {@code writer} based on specified yang version. Default implementation
177 * does not make any differences between versions.
180 * {@link StatementWriter} which should be used to emit
183 * Map of available statement definitions.
185 * Map of source-specific prefixes to namespaces
188 * @throws SourceException
189 * If source was is not valid, or provided statement writer
190 * failed to write statements.
192 default void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
193 final PrefixToModule prefixes, final YangVersion yangVersion) {
194 writeFull(writer, stmtDef, prefixes);