5cf46cc6ed879d8be904cf35a9a6a1757e6f0763
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / reactor / RFC7950Reactors.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.reactor;
9
10 import static org.opendaylight.yangtools.yang.common.YangVersion.VERSION_1;
11 import static org.opendaylight.yangtools.yang.common.YangVersion.VERSION_1_1;
12
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.openconfig.stmt.OpenConfigVersionSupport;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.YangNamespaceContextNamespace;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentImplicitHandlingNamespace;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentStatementRFC6020Support;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.augment.AugmentStatementRFC7950Support;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate.DeviateStatementRFC6020Support;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate.DeviateStatementRFC7950Support;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.extension.ExtensionStatementSupport;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature.IfFeatureStatementRFC6020Support;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature.IfFeatureStatementRFC7950Support;
29 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportStatementSupport;
30 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportedVersionNamespace;
31 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.leaf_list.LeafListStatementSupport;
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.LeafStatementSupport;
60 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.LengthStatementSupport;
61 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MandatoryStatementSupport;
62 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MaxElementsStatementSupport;
63 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MinElementsStatementSupport;
64 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ModifierStatementSupport;
65 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.MustStatementSupport;
66 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.NamespaceStatementSupport;
67 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OrderedByStatementSupport;
68 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OrganizationStatementSupport;
69 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.OutputStatementSupport;
70 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PositionStatementSupport;
71 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PrefixStatementSupport;
72 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.PresenceStatementSupport;
73 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RangeStatementSupport;
74 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ReferenceStatementSupport;
75 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RequireInstanceStatementSupport;
76 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RevisionDateStatementSupport;
77 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RevisionStatementSupport;
78 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.RpcStatementSupport;
79 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.StatusStatementSupport;
80 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.TypedefStatementSupport;
81 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.UniqueStatementSupport;
82 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.UnitsStatementSupport;
83 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.ValueStatementSupport;
84 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.WhenStatementSupport;
85 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.XPathSupport;
86 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.YangVersionStatementSupport;
87 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta.YinElementStatementSupport;
88 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.ModuleStatementSupport;
89 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.QNameModuleNamespace;
90 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification.NotificationStatementRFC6020Support;
91 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification.NotificationStatementRFC7950Support;
92 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.path.PathStatementSupport;
93 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.pattern.PatternStatementSupport;
94 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineStatementSupport;
95 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineTargetNamespace;
96 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule.SubmoduleStatementSupport;
97 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.BaseTypeNamespace;
98 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC6020Support;
99 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC7950Support;
100 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.SourceGroupingNamespace;
101 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.UsesStatementSupport;
102 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
103 import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
104 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
105 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
106 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
107 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
108 import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
109 import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
110 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
111 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
112 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
113 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
114 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
115 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
116 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
117 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
118 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
119 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
120 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
121 import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
122 import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier;
123 import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
124 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
125 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
126 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
127 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
128 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
129 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
130 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
131 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
132 import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
133 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
134 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
135 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
136 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
137 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
138 import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
139
140 /**
141  * Utility class holding entrypoints for assembling RFC6020/RFC7950 statement {@link CrossSourceStatementReactor}s.
142  *
143  * @author Robert Varga
144  */
145 @Beta
146 public final class RFC7950Reactors {
147     private static final ImmutableSet<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
148
149     private static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle.builder(SUPPORTED_VERSIONS)
150             .addSupport(ValidationBundlesNamespace.BEHAVIOUR)
151             .addSupport(SupportedFeaturesNamespace.BEHAVIOUR)
152             .addSupport(ModulesDeviatedByModules.BEHAVIOUR)
153             .build();
154
155     private static final StatementSupportBundle PRE_LINKAGE_BUNDLE = StatementSupportBundle.derivedFrom(INIT_BUNDLE)
156             .addVersionSpecificSupport(VERSION_1, ModuleStatementSupport.rfc6020Instance())
157             .addVersionSpecificSupport(VERSION_1_1, ModuleStatementSupport.rfc7950Instance())
158             .addVersionSpecificSupport(VERSION_1, SubmoduleStatementSupport.rfc6020Instance())
159             .addVersionSpecificSupport(VERSION_1_1, SubmoduleStatementSupport.rfc7950Instance())
160             .addSupport(NamespaceStatementSupport.getInstance())
161             .addVersionSpecificSupport(VERSION_1, ImportStatementSupport.rfc6020Instance())
162             .addVersionSpecificSupport(VERSION_1_1, ImportStatementSupport.rfc7950Instance())
163             .addVersionSpecificSupport(VERSION_1, IncludeStatementSupport.rfc6020Instance())
164             .addVersionSpecificSupport(VERSION_1_1, IncludeStatementSupport.rfc7950Instance())
165             .addSupport(BelongsToStatementSupport.getInstance())
166             .addSupport(PrefixStatementSupport.getInstance())
167             .addSupport(YangVersionStatementSupport.getInstance())
168             .addSupport(RevisionStatementSupport.getInstance())
169             .addSupport(RevisionDateStatementSupport.getInstance())
170             .addSupport(ModuleNameToNamespace.BEHAVIOUR)
171             .addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
172             .addSupport(ImpPrefixToNamespace.BEHAVIOUR)
173             .addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
174             .addSupport(QNameModuleNamespace.BEHAVIOUR)
175             .addSupport(ImportedVersionNamespace.BEHAVIOUR)
176             .build();
177
178     private static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
179             .derivedFrom(PRE_LINKAGE_BUNDLE)
180             .addSupport(DescriptionStatementSupport.getInstance())
181             .addSupport(ReferenceStatementSupport.getInstance())
182             .addSupport(ContactStatementSupport.getInstance())
183             .addSupport(OrganizationStatementSupport.getInstance())
184             .addSupport(ModuleNamespace.BEHAVIOUR)
185             .addSupport(ModuleNamespaceForBelongsTo.BEHAVIOUR)
186             .addSupport(SubmoduleNamespace.BEHAVIOUR)
187             .addSupport(NamespaceToModule.BEHAVIOUR)
188             .addSupport(ModuleNameToModuleQName.BEHAVIOUR)
189             .addSupport(ModuleCtxToSourceIdentifier.BEHAVIOUR)
190             .addSupport(ModuleQNameToModuleName.BEHAVIOUR)
191             .addSupport(PrefixToModule.BEHAVIOUR)
192             .addSupport(ImportedModuleContext.BEHAVIOUR)
193             .addSupport(IncludedModuleContext.BEHAVIOUR)
194             .addSupport(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR)
195             .addSupport(ImportPrefixToModuleCtx.BEHAVIOUR)
196             .addSupport(BelongsToPrefixToModuleCtx.BEHAVIOUR)
197             .addSupport(ModuleQNameToPrefix.BEHAVIOUR)
198             .addSupport(BelongsToModuleContext.BEHAVIOUR)
199             .addSupport(BelongsToPrefixToModuleName.BEHAVIOUR)
200             .build();
201
202     private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle
203             .derivedFrom(LINKAGE_BUNDLE)
204             .addSupport(YinElementStatementSupport.getInstance())
205             .addSupport(ArgumentStatementSupport.getInstance())
206             .addSupport(ExtensionStatementSupport.getInstance())
207             .addSupport(SchemaTreeNamespace.getInstance())
208             .addSupport(ExtensionNamespace.BEHAVIOUR)
209             .addSupport(TypedefStatementSupport.getInstance())
210             .addSupport(TypeNamespace.BEHAVIOUR)
211             .addVersionSpecificSupport(VERSION_1, IdentityStatementSupport.rfc6020Instance())
212             .addVersionSpecificSupport(VERSION_1_1, IdentityStatementSupport.rfc7950Instance())
213             .addSupport(IdentityNamespace.BEHAVIOUR)
214             .addSupport(DefaultStatementSupport.getInstance())
215             .addSupport(StatusStatementSupport.getInstance())
216             .addSupport(BaseTypeNamespace.BEHAVIOUR)
217             .addVersionSpecificSupport(VERSION_1, TypeStatementRFC6020Support.getInstance())
218             .addVersionSpecificSupport(VERSION_1_1, TypeStatementRFC7950Support.getInstance())
219             .addSupport(UnitsStatementSupport.getInstance())
220             .addSupport(RequireInstanceStatementSupport.getInstance())
221             .addVersionSpecificSupport(VERSION_1, BitStatementSupport.rfc6020Instance())
222             .addVersionSpecificSupport(VERSION_1_1, BitStatementSupport.rfc7950Instance())
223             .addSupport(PathStatementSupport.strictInstance())
224             .addVersionSpecificSupport(VERSION_1, EnumStatementSupport.rfc6020Instance())
225             .addVersionSpecificSupport(VERSION_1_1, EnumStatementSupport.rfc7950Instance())
226             .addSupport(LengthStatementSupport.getInstance())
227             .addVersionSpecificSupport(VERSION_1, PatternStatementSupport.rfc6020Instance())
228             .addVersionSpecificSupport(VERSION_1_1, PatternStatementSupport.rfc7950Instance())
229             .addVersionSpecificSupport(VERSION_1_1, ModifierStatementSupport.getInstance())
230             .addSupport(RangeStatementSupport.getInstance())
231             .addSupport(KeyStatementSupport.getInstance())
232             .addVersionSpecificSupport(VERSION_1, ContainerStatementSupport.rfc6020Instance())
233             .addVersionSpecificSupport(VERSION_1_1, ContainerStatementSupport.rfc7950Instance())
234             .addVersionSpecificSupport(VERSION_1, GroupingStatementSupport.rfc6020Instance())
235             .addVersionSpecificSupport(VERSION_1_1, GroupingStatementSupport.rfc7950Instance())
236             .addVersionSpecificSupport(VERSION_1, ListStatementSupport.rfc6020Instance())
237             .addVersionSpecificSupport(VERSION_1_1, ListStatementSupport.rfc7950Instance())
238             .addSupport(ConfigListWarningNamespace.BEHAVIOUR)
239             .addSupport(UniqueStatementSupport.getInstance())
240             .addVersionSpecificSupport(VERSION_1_1, ActionStatementSupport.getInstance())
241             .addVersionSpecificSupport(VERSION_1, RpcStatementSupport.rfc6020Instance())
242             .addVersionSpecificSupport(VERSION_1_1, RpcStatementSupport.rfc7950Instance())
243             .addVersionSpecificSupport(VERSION_1, InputStatementSupport.rfc6020Instance())
244             .addVersionSpecificSupport(VERSION_1_1, InputStatementSupport.rfc7950Instance())
245             .addVersionSpecificSupport(VERSION_1, OutputStatementSupport.rfc6020Instance())
246             .addVersionSpecificSupport(VERSION_1_1, OutputStatementSupport.rfc7950Instance())
247             .addVersionSpecificSupport(VERSION_1, NotificationStatementRFC6020Support.getInstance())
248             .addVersionSpecificSupport(VERSION_1_1, NotificationStatementRFC7950Support.getInstance())
249             .addSupport(FractionDigitsStatementSupport.getInstance())
250             .addSupport(BaseStatementSupport.getInstance())
251             .addSupport(StatementDefinitionNamespace.BEHAVIOUR)
252             .build();
253
254
255     private RFC7950Reactors() {
256         // Hidden on purpose
257     }
258
259     /**
260      * Returns a pre-built {@link CrossSourceStatementReactor} supporting RFC6020 and RFC7950, along with OpenConfig
261      * semantic version extension. This is useful for parsing near-vanilla YANG models while providing complete
262      * support for semantic versions.
263      *
264      * @return A shared reactor instance.
265      */
266     public static @NonNull CrossSourceStatementReactor defaultReactor() {
267         return ServiceLoaderState.DefaultReactor.INSTANCE;
268     }
269
270     /**
271      * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with RFC6020/RFC7950
272      * and OpenConfig semantic version support enabled.
273      *
274      * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
275      */
276     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder() {
277         return addExtensions(vanillaReactorBuilder());
278     }
279
280     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
281             final YangXPathParserFactory xpathFactory) {
282         return addExtensions(vanillaReactorBuilder(xpathFactory));
283     }
284
285     private static @NonNull CustomCrossSourceStatementReactorBuilder addExtensions(
286             final @NonNull CustomCrossSourceStatementReactorBuilder builder) {
287         return builder
288                 // Semantic version support
289                 .addStatementSupport(ModelProcessingPhase.SOURCE_LINKAGE, OpenConfigVersionSupport.getInstance())
290                 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE, SemanticVersionNamespace.BEHAVIOUR)
291                 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE, SemanticVersionModuleNamespace.BEHAVIOUR)
292                 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE,
293                     ImportPrefixToSemVerSourceIdentifier.BEHAVIOUR);
294     }
295
296     /**
297      * Returns a pre-built {@link CrossSourceStatementReactor} supporting both RFC6020 and RFC7950. This is useful
298      * for parsing vanilla YANG models without any semantic support for extensions. Notably missing is the semantic
299      * version extension, hence attempts to use semantic version mode will cause failures.
300      *
301      * @return A shared reactor instance.
302      */
303     public static @NonNull CrossSourceStatementReactor vanillaReactor() {
304         return ServiceLoaderState.VanillaReactor.INSTANCE;
305     }
306
307     /**
308      * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with vanilla RFC6020/RFC7950
309      * support enabled.
310      *
311      * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
312      */
313     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder() {
314         return vanillaReactorBuilder(ServiceLoaderState.XPath.INSTANCE);
315     }
316
317     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
318             final @NonNull YangXPathParserFactory xpathFactory) {
319         return vanillaReactorBuilder(new XPathSupport(xpathFactory));
320     }
321
322     private static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
323             final @NonNull XPathSupport xpathSupport) {
324         final StatementSupportBundle fullDeclarationBundle = fullDeclarationBundle(xpathSupport);
325         return new CustomCrossSourceStatementReactorBuilder(SUPPORTED_VERSIONS)
326                 .addAllSupports(ModelProcessingPhase.INIT, INIT_BUNDLE)
327                 .addAllSupports(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
328                 .addAllSupports(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
329                 .addAllSupports(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
330                 .addAllSupports(ModelProcessingPhase.FULL_DECLARATION, fullDeclarationBundle)
331                 .addAllSupports(ModelProcessingPhase.EFFECTIVE_MODEL, fullDeclarationBundle)
332                 .addValidationBundle(ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
333                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
334                 .addValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
335                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
336
337                 // FIXME: 7.0.0: we do not seem to need this validation bundle
338                 .addValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
339                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
340
341                 .addValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
342                     YangValidationBundles.SUPPORTED_DATA_NODES);
343     }
344
345     private static @NonNull StatementSupportBundle fullDeclarationBundle(final XPathSupport xpathSupport) {
346         return StatementSupportBundle
347             .derivedFrom(STMT_DEF_BUNDLE)
348             .addSupport(LeafStatementSupport.getInstance())
349             .addSupport(ConfigStatementSupport.getInstance())
350             .addSupport(DeviationStatementSupport.getInstance())
351             .addVersionSpecificSupport(VERSION_1, DeviateStatementRFC6020Support.getInstance())
352             .addVersionSpecificSupport(VERSION_1_1, DeviateStatementRFC7950Support.getInstance())
353             .addVersionSpecificSupport(VERSION_1, ChoiceStatementSupport.rfc6020Instance())
354             .addVersionSpecificSupport(VERSION_1_1, ChoiceStatementSupport.rfc7950Instance())
355             .addVersionSpecificSupport(VERSION_1, CaseStatementSupport.rfc6020Instance())
356             .addVersionSpecificSupport(VERSION_1_1, CaseStatementSupport.rfc7950Instance())
357             .addSupport(MustStatementSupport.createInstance(xpathSupport))
358             .addSupport(MandatoryStatementSupport.getInstance())
359             .addSupport(AnyxmlStatementSupport.getInstance())
360             .addVersionSpecificSupport(VERSION_1_1, AnydataStatementSupport.getInstance())
361             .addSupport(FeatureNamespace.BEHAVIOUR)
362             .addVersionSpecificSupport(VERSION_1, IfFeatureStatementRFC6020Support.getInstance())
363             .addVersionSpecificSupport(VERSION_1_1, IfFeatureStatementRFC7950Support.getInstance())
364             .addSupport(GroupingNamespace.BEHAVIOUR)
365             .addSupport(SourceGroupingNamespace.BEHAVIOUR)
366             .addSupport(UsesStatementSupport.getInstance())
367             .addSupport(ErrorMessageStatementSupport.getInstance())
368             .addSupport(ErrorAppTagStatementSupport.getInstance())
369             .addVersionSpecificSupport(VERSION_1, LeafListStatementSupport.rfc6020Instance())
370             .addVersionSpecificSupport(VERSION_1_1, LeafListStatementSupport.rfc7950Instance())
371             .addSupport(PresenceStatementSupport.getInstance())
372             .addSupport(MaxElementsStatementSupport.getInstance())
373             .addSupport(MinElementsStatementSupport.getInstance())
374             .addSupport(OrderedByStatementSupport.getInstance())
375             .addSupport(WhenStatementSupport.createInstance(xpathSupport))
376             .addSupport(AugmentImplicitHandlingNamespace.BEHAVIOUR)
377             .addVersionSpecificSupport(VERSION_1, AugmentStatementRFC6020Support.getInstance())
378             .addVersionSpecificSupport(VERSION_1_1, AugmentStatementRFC7950Support.getInstance())
379             .addSupport(RefineTargetNamespace.BEHAVIOUR)
380             .addVersionSpecificSupport(VERSION_1, RefineStatementSupport.rfc6020Instance())
381             .addVersionSpecificSupport(VERSION_1_1, RefineStatementSupport.rfc7950Instance())
382             .addSupport(FeatureStatementSupport.getInstance())
383             .addSupport(PositionStatementSupport.getInstance())
384             .addSupport(ValueStatementSupport.getInstance())
385             .addSupport(YangNamespaceContextNamespace.BEHAVIOUR)
386             .build();
387     }
388 }