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