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.parser.rfc7950.reactor;
10 import static org.opendaylight.yangtools.yang.common.YangVersion.VERSION_1;
11 import static org.opendaylight.yangtools.yang.common.YangVersion.VERSION_1_1;
13 import com.google.common.annotations.Beta;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.collect.Sets;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.YangVersion;
18 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
19 import org.opendaylight.yangtools.yang.parser.openconfig.stmt.OpenConfigVersionSupport;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.YangNamespaceContextNamespace;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentImplicitHandlingNamespace;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentStatementRFC6020Support;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentStatementRFC7950Support;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate.DeviateStatementRFC6020Support;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate.DeviateStatementRFC7950Support;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.extension.ExtensionStatementSupport;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature.IfFeatureStatementRFC6020Support;
29 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature.IfFeatureStatementRFC7950Support;
30 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportStatementSupport;
31 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportedVersionNamespace;
32 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list.ConfigListWarningNamespace;
33 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list.ListStatementSupport;
34 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ActionStatementSupport;
35 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.AnydataStatementSupport;
36 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.AnyxmlStatementSupport;
37 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ArgumentStatementSupport;
38 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.BaseStatementSupport;
39 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.BelongsToStatementSupport;
40 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.BitStatementSupport;
41 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.CaseStatementSupport;
42 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ChoiceStatementSupport;
43 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ConfigStatementSupport;
44 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ContactStatementSupport;
45 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ContainerStatementSupport;
46 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.DefaultStatementSupport;
47 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.DescriptionStatementSupport;
48 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.DeviationStatementSupport;
49 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.EnumStatementSupport;
50 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ErrorAppTagStatementSupport;
51 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ErrorMessageStatementSupport;
52 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.FeatureStatementSupport;
53 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.FractionDigitsStatementSupport;
54 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.GroupingStatementSupport;
55 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.IdentityStatementSupport;
56 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.IncludeStatementSupport;
57 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.InputStatementSupport;
58 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.KeyStatementSupport;
59 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.LeafListStatementSupport;
60 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.LeafStatementSupport;
61 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.LengthStatementSupport;
62 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MandatoryStatementSupport;
63 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MaxElementsStatementSupport;
64 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MinElementsStatementSupport;
65 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ModifierStatementSupport;
66 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MustStatementSupport;
67 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.NamespaceStatementSupport;
68 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OrderedByStatementSupport;
69 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OrganizationStatementSupport;
70 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OutputStatementSupport;
71 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PositionStatementSupport;
72 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PrefixStatementSupport;
73 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PresenceStatementSupport;
74 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RangeStatementSupport;
75 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ReferenceStatementSupport;
76 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RequireInstanceStatementSupport;
77 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RevisionDateStatementSupport;
78 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RevisionStatementSupport;
79 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RpcStatementSupport;
80 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.StatusStatementSupport;
81 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.TypedefStatementSupport;
82 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.UniqueStatementSupport;
83 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.UnitsStatementSupport;
84 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ValueStatementSupport;
85 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.WhenStatementSupport;
86 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.XPathSupport;
87 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.YangVersionStatementSupport;
88 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.YinElementStatementSupport;
89 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.ModuleStatementSupport;
90 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.QNameModuleNamespace;
91 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification.NotificationStatementRFC6020Support;
92 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification.NotificationStatementRFC7950Support;
93 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.path.PathStatementSupport;
94 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.pattern.PatternStatementSupport;
95 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineStatementSupport;
96 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineTargetNamespace;
97 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule.SubmoduleStatementSupport;
98 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.BaseTypeNamespace;
99 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC6020Support;
100 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC7950Support;
101 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.SourceGroupingNamespace;
102 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.UsesStatementSupport;
103 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
104 import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
105 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
106 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
107 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
108 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
109 import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
110 import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
111 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
112 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
113 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
114 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
115 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
116 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
117 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
118 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
119 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
120 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
121 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
122 import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
123 import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier;
124 import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
125 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
126 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
127 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
128 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
129 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
130 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
131 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
132 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
133 import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
134 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
135 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
136 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
137 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
138 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
139 import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
142 * Utility class holding entrypoints for assembling RFC6020/RFC7950 statement {@link CrossSourceStatementReactor}s.
144 * @author Robert Varga
147 public final class RFC7950Reactors {
148 private static final ImmutableSet<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
150 private static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle.builder(SUPPORTED_VERSIONS)
151 .addSupport(ValidationBundlesNamespace.BEHAVIOUR)
152 .addSupport(SupportedFeaturesNamespace.BEHAVIOUR)
153 .addSupport(ModulesDeviatedByModules.BEHAVIOUR)
156 private RFC7950Reactors() {
160 private static StatementSupportBundle preLinkageBundle(final YangParserConfiguration config) {
161 return StatementSupportBundle.derivedFrom(INIT_BUNDLE)
162 .addVersionSpecificSupport(VERSION_1, ModuleStatementSupport.rfc6020Instance(config))
163 .addVersionSpecificSupport(VERSION_1_1, ModuleStatementSupport.rfc7950Instance(config))
164 .addVersionSpecificSupport(VERSION_1, SubmoduleStatementSupport.rfc6020Instance(config))
165 .addVersionSpecificSupport(VERSION_1_1, SubmoduleStatementSupport.rfc7950Instance(config))
166 .addSupport(new NamespaceStatementSupport(config))
167 .addVersionSpecificSupport(VERSION_1, ImportStatementSupport.rfc6020Instance(config))
168 .addVersionSpecificSupport(VERSION_1_1, ImportStatementSupport.rfc7950Instance(config))
169 .addVersionSpecificSupport(VERSION_1, IncludeStatementSupport.rfc6020Instance(config))
170 .addVersionSpecificSupport(VERSION_1_1, IncludeStatementSupport.rfc7950Instance(config))
171 .addSupport(new BelongsToStatementSupport(config))
172 .addSupport(new PrefixStatementSupport(config))
173 .addSupport(new YangVersionStatementSupport(config))
174 .addSupport(new RevisionStatementSupport(config))
175 .addSupport(new RevisionDateStatementSupport(config))
176 .addSupport(ModuleNameToNamespace.BEHAVIOUR)
177 .addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
178 .addSupport(ImpPrefixToNamespace.BEHAVIOUR)
179 .addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
180 .addSupport(QNameModuleNamespace.BEHAVIOUR)
181 .addSupport(ImportedVersionNamespace.BEHAVIOUR)
185 private static StatementSupportBundle linkageBundle(final StatementSupportBundle preLinkageBundle,
186 final YangParserConfiguration config) {
187 return StatementSupportBundle.derivedFrom(preLinkageBundle)
188 .addSupport(new DescriptionStatementSupport(config))
189 .addSupport(new ReferenceStatementSupport(config))
190 .addSupport(new ContactStatementSupport(config))
191 .addSupport(new OrganizationStatementSupport(config))
192 .addSupport(ModuleNamespace.BEHAVIOUR)
193 .addSupport(ModuleNamespaceForBelongsTo.BEHAVIOUR)
194 .addSupport(SubmoduleNamespace.BEHAVIOUR)
195 .addSupport(NamespaceToModule.BEHAVIOUR)
196 .addSupport(ModuleNameToModuleQName.BEHAVIOUR)
197 .addSupport(ModuleCtxToSourceIdentifier.BEHAVIOUR)
198 .addSupport(ModuleQNameToModuleName.BEHAVIOUR)
199 .addSupport(PrefixToModule.BEHAVIOUR)
200 .addSupport(ImportedModuleContext.BEHAVIOUR)
201 .addSupport(IncludedModuleContext.BEHAVIOUR)
202 .addSupport(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR)
203 .addSupport(ImportPrefixToModuleCtx.BEHAVIOUR)
204 .addSupport(BelongsToPrefixToModuleCtx.BEHAVIOUR)
205 .addSupport(ModuleQNameToPrefix.BEHAVIOUR)
206 .addSupport(BelongsToModuleContext.BEHAVIOUR)
207 .addSupport(BelongsToPrefixToModuleName.BEHAVIOUR)
211 private static StatementSupportBundle stmtDefBundle(final StatementSupportBundle linkageBundle,
212 final YangParserConfiguration config) {
213 return StatementSupportBundle.derivedFrom(linkageBundle)
214 .addSupport(new YinElementStatementSupport(config))
215 .addSupport(new ArgumentStatementSupport(config))
216 .addSupport(new ExtensionStatementSupport(config))
217 .addSupport(SchemaTreeNamespace.getInstance())
218 .addSupport(ExtensionNamespace.BEHAVIOUR)
219 .addSupport(new TypedefStatementSupport(config))
220 .addSupport(TypeNamespace.BEHAVIOUR)
221 .addVersionSpecificSupport(VERSION_1, IdentityStatementSupport.rfc6020Instance(config))
222 .addVersionSpecificSupport(VERSION_1_1, IdentityStatementSupport.rfc7950Instance(config))
223 .addSupport(IdentityNamespace.BEHAVIOUR)
224 .addSupport(new DefaultStatementSupport(config))
225 .addSupport(new StatusStatementSupport(config))
226 .addSupport(BaseTypeNamespace.BEHAVIOUR)
227 .addVersionSpecificSupport(VERSION_1, new TypeStatementRFC6020Support(config))
228 .addVersionSpecificSupport(VERSION_1_1, new TypeStatementRFC7950Support(config))
229 .addSupport(new UnitsStatementSupport(config))
230 .addSupport(new RequireInstanceStatementSupport(config))
231 .addVersionSpecificSupport(VERSION_1, BitStatementSupport.rfc6020Instance(config))
232 .addVersionSpecificSupport(VERSION_1_1, BitStatementSupport.rfc7950Instance(config))
233 .addSupport(PathStatementSupport.strictInstance(config))
234 .addVersionSpecificSupport(VERSION_1, EnumStatementSupport.rfc6020Instance(config))
235 .addVersionSpecificSupport(VERSION_1_1, EnumStatementSupport.rfc7950Instance(config))
236 .addSupport(new LengthStatementSupport(config))
237 .addVersionSpecificSupport(VERSION_1, PatternStatementSupport.rfc6020Instance(config))
238 .addVersionSpecificSupport(VERSION_1_1, PatternStatementSupport.rfc7950Instance(config))
239 .addVersionSpecificSupport(VERSION_1_1, new ModifierStatementSupport(config))
240 .addSupport(new RangeStatementSupport(config))
241 .addSupport(new KeyStatementSupport(config))
242 .addVersionSpecificSupport(VERSION_1, ContainerStatementSupport.rfc6020Instance(config))
243 .addVersionSpecificSupport(VERSION_1_1, ContainerStatementSupport.rfc7950Instance(config))
244 .addVersionSpecificSupport(VERSION_1, GroupingStatementSupport.rfc6020Instance(config))
245 .addVersionSpecificSupport(VERSION_1_1, GroupingStatementSupport.rfc7950Instance(config))
246 .addVersionSpecificSupport(VERSION_1, ListStatementSupport.rfc6020Instance(config))
247 .addVersionSpecificSupport(VERSION_1_1, ListStatementSupport.rfc7950Instance(config))
248 .addSupport(ConfigListWarningNamespace.BEHAVIOUR)
249 .addSupport(new UniqueStatementSupport(config))
250 .addVersionSpecificSupport(VERSION_1_1, new ActionStatementSupport(config))
251 .addVersionSpecificSupport(VERSION_1, new RpcStatementSupport(config))
252 .addVersionSpecificSupport(VERSION_1_1, new RpcStatementSupport(config))
253 .addVersionSpecificSupport(VERSION_1, InputStatementSupport.rfc6020Instance(config))
254 .addVersionSpecificSupport(VERSION_1_1, InputStatementSupport.rfc7950Instance(config))
255 .addVersionSpecificSupport(VERSION_1, OutputStatementSupport.rfc6020Instance(config))
256 .addVersionSpecificSupport(VERSION_1_1, OutputStatementSupport.rfc7950Instance(config))
257 .addVersionSpecificSupport(VERSION_1, new NotificationStatementRFC6020Support(config))
258 .addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRFC7950Support(config))
259 .addSupport(new FractionDigitsStatementSupport(config))
260 .addSupport(new BaseStatementSupport(config))
261 .addSupport(StatementDefinitionNamespace.BEHAVIOUR)
266 * Returns a pre-built {@link CrossSourceStatementReactor} supporting RFC6020 and RFC7950, along with OpenConfig
267 * semantic version extension. This is useful for parsing near-vanilla YANG models while providing complete
268 * support for semantic versions.
270 * @return A shared reactor instance.
272 public static @NonNull CrossSourceStatementReactor defaultReactor() {
273 return ServiceLoaderState.DefaultReactor.INSTANCE;
277 * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with RFC6020/RFC7950
278 * and OpenConfig semantic version support enabled.
280 * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
282 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder() {
283 return defaultReactorBuilder(YangParserConfiguration.DEFAULT);
286 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
287 final YangParserConfiguration config) {
288 return addExtensions(vanillaReactorBuilder(config), config);
291 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
292 final YangXPathParserFactory xpathFactory) {
293 return defaultReactorBuilder(xpathFactory, YangParserConfiguration.DEFAULT);
296 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
297 final YangXPathParserFactory xpathFactory, final YangParserConfiguration config) {
298 return addExtensions(vanillaReactorBuilder(xpathFactory, config), config);
301 private static @NonNull CustomCrossSourceStatementReactorBuilder addExtensions(
302 final @NonNull CustomCrossSourceStatementReactorBuilder builder, final YangParserConfiguration config) {
304 // Semantic version support
305 .addStatementSupport(ModelProcessingPhase.SOURCE_LINKAGE, new OpenConfigVersionSupport(config))
306 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE, SemanticVersionNamespace.BEHAVIOUR)
307 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE, SemanticVersionModuleNamespace.BEHAVIOUR)
308 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE,
309 ImportPrefixToSemVerSourceIdentifier.BEHAVIOUR);
313 * Returns a pre-built {@link CrossSourceStatementReactor} supporting both RFC6020 and RFC7950. This is useful
314 * for parsing vanilla YANG models without any semantic support for extensions. Notably missing is the semantic
315 * version extension, hence attempts to use semantic version mode will cause failures.
317 * @return A shared reactor instance.
319 public static @NonNull CrossSourceStatementReactor vanillaReactor() {
320 return ServiceLoaderState.VanillaReactor.INSTANCE;
324 * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with vanilla RFC6020/RFC7950
327 * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
329 public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder() {
330 return vanillaReactorBuilder(YangParserConfiguration.DEFAULT);
333 public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
334 final YangParserConfiguration config) {
335 return vanillaReactorBuilder(ServiceLoaderState.XPath.INSTANCE, config);
338 public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
339 final @NonNull YangXPathParserFactory xpathFactory) {
340 return vanillaReactorBuilder(xpathFactory, YangParserConfiguration.DEFAULT);
343 public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
344 final @NonNull YangXPathParserFactory xpathFactory, final YangParserConfiguration config) {
345 return vanillaReactorBuilder(new XPathSupport(xpathFactory), config);
348 private static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
349 final @NonNull XPathSupport xpathSupport, final YangParserConfiguration config) {
350 final StatementSupportBundle preLinkageBundle = preLinkageBundle(config);
351 final StatementSupportBundle linkageBundle = linkageBundle(preLinkageBundle, config);
352 final StatementSupportBundle stmtDefBundle = stmtDefBundle(linkageBundle, config);
353 final StatementSupportBundle fullDeclarationBundle =
354 fullDeclarationBundle(stmtDefBundle, xpathSupport, config);
356 return new CustomCrossSourceStatementReactorBuilder(SUPPORTED_VERSIONS)
357 .addAllSupports(ModelProcessingPhase.INIT, INIT_BUNDLE)
358 .addAllSupports(ModelProcessingPhase.SOURCE_PRE_LINKAGE, preLinkageBundle)
359 .addAllSupports(ModelProcessingPhase.SOURCE_LINKAGE, linkageBundle)
360 .addAllSupports(ModelProcessingPhase.STATEMENT_DEFINITION, stmtDefBundle)
361 .addAllSupports(ModelProcessingPhase.FULL_DECLARATION, fullDeclarationBundle)
362 .addAllSupports(ModelProcessingPhase.EFFECTIVE_MODEL, fullDeclarationBundle)
363 .addValidationBundle(ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
364 YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
365 .addValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
366 YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
368 // FIXME: 7.0.0: we do not seem to need this validation bundle
369 .addValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
370 YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
372 .addValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
373 YangValidationBundles.SUPPORTED_DATA_NODES);
376 private static @NonNull StatementSupportBundle fullDeclarationBundle(final StatementSupportBundle stmtDefBundle,
377 final XPathSupport xpathSupport, final YangParserConfiguration config) {
378 final CaseStatementSupport rfc6020case = CaseStatementSupport.rfc6020Instance(config);
379 final CaseStatementSupport rfc7950case = CaseStatementSupport.rfc7950Instance(config);
381 return StatementSupportBundle.derivedFrom(stmtDefBundle)
382 .addSupport(new LeafStatementSupport(config))
383 .addSupport(new ConfigStatementSupport(config))
384 .addSupport(new DeviationStatementSupport(config))
385 .addVersionSpecificSupport(VERSION_1, new DeviateStatementRFC6020Support(config))
386 .addVersionSpecificSupport(VERSION_1_1, new DeviateStatementRFC7950Support(config))
387 .addVersionSpecificSupport(VERSION_1, ChoiceStatementSupport.rfc6020Instance(config, rfc6020case))
388 .addVersionSpecificSupport(VERSION_1_1, ChoiceStatementSupport.rfc7950Instance(config, rfc7950case))
389 .addVersionSpecificSupport(VERSION_1, rfc6020case)
390 .addVersionSpecificSupport(VERSION_1_1, rfc7950case)
391 .addSupport(new MustStatementSupport(xpathSupport, config))
392 .addSupport(new MandatoryStatementSupport(config))
393 .addSupport(new AnyxmlStatementSupport(config))
394 .addVersionSpecificSupport(VERSION_1_1, new AnydataStatementSupport(config))
395 .addSupport(FeatureNamespace.BEHAVIOUR)
396 .addVersionSpecificSupport(VERSION_1, new IfFeatureStatementRFC6020Support(config))
397 .addVersionSpecificSupport(VERSION_1_1, new IfFeatureStatementRFC7950Support(config))
398 .addSupport(GroupingNamespace.BEHAVIOUR)
399 .addSupport(SourceGroupingNamespace.BEHAVIOUR)
400 .addSupport(new UsesStatementSupport(config))
401 .addSupport(new ErrorMessageStatementSupport(config))
402 .addSupport(new ErrorAppTagStatementSupport(config))
403 .addVersionSpecificSupport(VERSION_1, LeafListStatementSupport.rfc6020Instance(config))
404 .addVersionSpecificSupport(VERSION_1_1, LeafListStatementSupport.rfc7950Instance(config))
405 .addSupport(new PresenceStatementSupport(config))
406 .addSupport(new MaxElementsStatementSupport(config))
407 .addSupport(new MinElementsStatementSupport(config))
408 .addSupport(new OrderedByStatementSupport(config))
409 .addSupport(new WhenStatementSupport(xpathSupport, config))
410 .addSupport(AugmentImplicitHandlingNamespace.BEHAVIOUR)
411 .addVersionSpecificSupport(VERSION_1, new AugmentStatementRFC6020Support(config))
412 .addVersionSpecificSupport(VERSION_1_1, new AugmentStatementRFC7950Support(config))
413 .addSupport(RefineTargetNamespace.BEHAVIOUR)
414 .addVersionSpecificSupport(VERSION_1, RefineStatementSupport.rfc6020Instance(config))
415 .addVersionSpecificSupport(VERSION_1_1, RefineStatementSupport.rfc7950Instance(config))
416 .addSupport(new FeatureStatementSupport(config))
417 .addSupport(new PositionStatementSupport(config))
418 .addSupport(new ValueStatementSupport(config))
419 .addSupport(YangNamespaceContextNamespace.BEHAVIOUR)