Remove ImportResolutionMode.OPENCONFIG_SEMVER
[yangtools.git] / parser / 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.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.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.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 RFC7950Reactors() {
155         // Hidden on purpose
156     }
157
158     private static StatementSupportBundle preLinkageBundle(final YangParserConfiguration config) {
159         return StatementSupportBundle.derivedFrom(INIT_BUNDLE)
160             .addVersionSpecificSupport(VERSION_1, ModuleStatementSupport.rfc6020Instance(config))
161             .addVersionSpecificSupport(VERSION_1_1, ModuleStatementSupport.rfc7950Instance(config))
162             .addVersionSpecificSupport(VERSION_1, SubmoduleStatementSupport.rfc6020Instance(config))
163             .addVersionSpecificSupport(VERSION_1_1, SubmoduleStatementSupport.rfc7950Instance(config))
164             .addSupport(new NamespaceStatementSupport(config))
165             .addVersionSpecificSupport(VERSION_1, ImportStatementSupport.rfc6020Instance(config))
166             .addVersionSpecificSupport(VERSION_1_1, ImportStatementSupport.rfc7950Instance(config))
167             .addVersionSpecificSupport(VERSION_1, IncludeStatementSupport.rfc6020Instance(config))
168             .addVersionSpecificSupport(VERSION_1_1, IncludeStatementSupport.rfc7950Instance(config))
169             .addSupport(new BelongsToStatementSupport(config))
170             .addSupport(new PrefixStatementSupport(config))
171             .addSupport(new YangVersionStatementSupport(config))
172             .addSupport(new RevisionStatementSupport(config))
173             .addSupport(new RevisionDateStatementSupport(config))
174             .addSupport(ModuleNameToNamespace.BEHAVIOUR)
175             .addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
176             .addSupport(ImpPrefixToNamespace.BEHAVIOUR)
177             .addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
178             .addSupport(QNameModuleNamespace.BEHAVIOUR)
179             .addSupport(ImportedVersionNamespace.BEHAVIOUR)
180             .build();
181     }
182
183     private static StatementSupportBundle linkageBundle(final StatementSupportBundle preLinkageBundle,
184             final YangParserConfiguration config) {
185         return StatementSupportBundle.derivedFrom(preLinkageBundle)
186             .addSupport(new DescriptionStatementSupport(config))
187             .addSupport(new ReferenceStatementSupport(config))
188             .addSupport(new ContactStatementSupport(config))
189             .addSupport(new OrganizationStatementSupport(config))
190             .addSupport(ModuleNamespace.BEHAVIOUR)
191             .addSupport(ModuleNamespaceForBelongsTo.BEHAVIOUR)
192             .addSupport(SubmoduleNamespace.BEHAVIOUR)
193             .addSupport(NamespaceToModule.BEHAVIOUR)
194             .addSupport(ModuleNameToModuleQName.BEHAVIOUR)
195             .addSupport(ModuleCtxToSourceIdentifier.BEHAVIOUR)
196             .addSupport(ModuleQNameToModuleName.BEHAVIOUR)
197             .addSupport(PrefixToModule.BEHAVIOUR)
198             .addSupport(ImportedModuleContext.BEHAVIOUR)
199             .addSupport(IncludedModuleContext.BEHAVIOUR)
200             .addSupport(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR)
201             .addSupport(ImportPrefixToModuleCtx.BEHAVIOUR)
202             .addSupport(BelongsToPrefixToModuleCtx.BEHAVIOUR)
203             .addSupport(ModuleQNameToPrefix.BEHAVIOUR)
204             .addSupport(BelongsToModuleContext.BEHAVIOUR)
205             .addSupport(BelongsToPrefixToModuleName.BEHAVIOUR)
206             .build();
207     }
208
209     private static StatementSupportBundle stmtDefBundle(final StatementSupportBundle linkageBundle,
210             final YangParserConfiguration config) {
211         return StatementSupportBundle.derivedFrom(linkageBundle)
212             .addSupport(new YinElementStatementSupport(config))
213             .addSupport(new ArgumentStatementSupport(config))
214             .addSupport(new ExtensionStatementSupport(config))
215             .addSupport(SchemaTreeNamespace.getInstance())
216             .addSupport(ExtensionNamespace.BEHAVIOUR)
217             .addSupport(new TypedefStatementSupport(config))
218             .addSupport(TypeNamespace.BEHAVIOUR)
219             .addVersionSpecificSupport(VERSION_1, IdentityStatementSupport.rfc6020Instance(config))
220             .addVersionSpecificSupport(VERSION_1_1, IdentityStatementSupport.rfc7950Instance(config))
221             .addSupport(IdentityNamespace.BEHAVIOUR)
222             .addSupport(new DefaultStatementSupport(config))
223             .addSupport(new StatusStatementSupport(config))
224             .addSupport(BaseTypeNamespace.BEHAVIOUR)
225             .addVersionSpecificSupport(VERSION_1, new TypeStatementRFC6020Support(config))
226             .addVersionSpecificSupport(VERSION_1_1, new TypeStatementRFC7950Support(config))
227             .addSupport(new UnitsStatementSupport(config))
228             .addSupport(new RequireInstanceStatementSupport(config))
229             .addVersionSpecificSupport(VERSION_1, BitStatementSupport.rfc6020Instance(config))
230             .addVersionSpecificSupport(VERSION_1_1, BitStatementSupport.rfc7950Instance(config))
231             .addSupport(PathStatementSupport.strictInstance(config))
232             .addVersionSpecificSupport(VERSION_1, EnumStatementSupport.rfc6020Instance(config))
233             .addVersionSpecificSupport(VERSION_1_1, EnumStatementSupport.rfc7950Instance(config))
234             .addSupport(new LengthStatementSupport(config))
235             .addVersionSpecificSupport(VERSION_1, PatternStatementSupport.rfc6020Instance(config))
236             .addVersionSpecificSupport(VERSION_1_1, PatternStatementSupport.rfc7950Instance(config))
237             .addVersionSpecificSupport(VERSION_1_1, new ModifierStatementSupport(config))
238             .addSupport(new RangeStatementSupport(config))
239             .addSupport(new KeyStatementSupport(config))
240             .addVersionSpecificSupport(VERSION_1, ContainerStatementSupport.rfc6020Instance(config))
241             .addVersionSpecificSupport(VERSION_1_1, ContainerStatementSupport.rfc7950Instance(config))
242             .addVersionSpecificSupport(VERSION_1, GroupingStatementSupport.rfc6020Instance(config))
243             .addVersionSpecificSupport(VERSION_1_1, GroupingStatementSupport.rfc7950Instance(config))
244             .addVersionSpecificSupport(VERSION_1, ListStatementSupport.rfc6020Instance(config))
245             .addVersionSpecificSupport(VERSION_1_1, ListStatementSupport.rfc7950Instance(config))
246             .addSupport(ConfigListWarningNamespace.BEHAVIOUR)
247             .addSupport(new UniqueStatementSupport(config))
248             .addVersionSpecificSupport(VERSION_1_1, new ActionStatementSupport(config))
249             .addVersionSpecificSupport(VERSION_1, new RpcStatementSupport(config))
250             .addVersionSpecificSupport(VERSION_1_1, new RpcStatementSupport(config))
251             .addVersionSpecificSupport(VERSION_1, InputStatementSupport.rfc6020Instance(config))
252             .addVersionSpecificSupport(VERSION_1_1, InputStatementSupport.rfc7950Instance(config))
253             .addVersionSpecificSupport(VERSION_1, OutputStatementSupport.rfc6020Instance(config))
254             .addVersionSpecificSupport(VERSION_1_1, OutputStatementSupport.rfc7950Instance(config))
255             .addVersionSpecificSupport(VERSION_1, new NotificationStatementRFC6020Support(config))
256             .addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRFC7950Support(config))
257             .addSupport(new FractionDigitsStatementSupport(config))
258             .addSupport(new BaseStatementSupport(config))
259             .addSupport(StatementDefinitionNamespace.BEHAVIOUR)
260             .build();
261     }
262
263     /**
264      * Returns a pre-built {@link CrossSourceStatementReactor} supporting RFC6020 and RFC7950, along with OpenConfig
265      * semantic version extension. This is useful for parsing near-vanilla YANG models while providing complete
266      * support for semantic versions.
267      *
268      * @return A shared reactor instance.
269      */
270     public static @NonNull CrossSourceStatementReactor defaultReactor() {
271         return ServiceLoaderState.DefaultReactor.INSTANCE;
272     }
273
274     /**
275      * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with RFC6020/RFC7950
276      * and OpenConfig semantic version support enabled.
277      *
278      * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
279      */
280     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder() {
281         return defaultReactorBuilder(YangParserConfiguration.DEFAULT);
282     }
283
284     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
285             final YangParserConfiguration config) {
286         return addExtensions(vanillaReactorBuilder(config), config);
287     }
288
289     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
290             final YangXPathParserFactory xpathFactory) {
291         return defaultReactorBuilder(xpathFactory, YangParserConfiguration.DEFAULT);
292     }
293
294     public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
295             final YangXPathParserFactory xpathFactory, final YangParserConfiguration config) {
296         return addExtensions(vanillaReactorBuilder(xpathFactory, config), config);
297     }
298
299     private static @NonNull CustomCrossSourceStatementReactorBuilder addExtensions(
300             final @NonNull CustomCrossSourceStatementReactorBuilder builder, final YangParserConfiguration config) {
301         return builder
302                 // Semantic version support
303                 .addStatementSupport(ModelProcessingPhase.SOURCE_LINKAGE, new OpenConfigVersionSupport(config))
304                 .addNamespaceSupport(ModelProcessingPhase.SOURCE_LINKAGE, SemanticVersionNamespace.BEHAVIOUR);
305     }
306
307     /**
308      * Returns a pre-built {@link CrossSourceStatementReactor} supporting both RFC6020 and RFC7950. This is useful
309      * for parsing vanilla YANG models without any semantic support for extensions. Notably missing is the semantic
310      * version extension, hence attempts to use semantic version mode will cause failures.
311      *
312      * @return A shared reactor instance.
313      */
314     public static @NonNull CrossSourceStatementReactor vanillaReactor() {
315         return ServiceLoaderState.VanillaReactor.INSTANCE;
316     }
317
318     /**
319      * Returns a partially-configured {@link CustomCrossSourceStatementReactorBuilder}, with vanilla RFC6020/RFC7950
320      * support enabled.
321      *
322      * @return A new {@link CustomCrossSourceStatementReactorBuilder}.
323      */
324     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder() {
325         return vanillaReactorBuilder(YangParserConfiguration.DEFAULT);
326     }
327
328     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
329             final YangParserConfiguration config) {
330         return vanillaReactorBuilder(ServiceLoaderState.XPath.INSTANCE, config);
331     }
332
333     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
334             final @NonNull YangXPathParserFactory xpathFactory) {
335         return vanillaReactorBuilder(xpathFactory, YangParserConfiguration.DEFAULT);
336     }
337
338     public static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
339             final @NonNull YangXPathParserFactory xpathFactory, final YangParserConfiguration config) {
340         return vanillaReactorBuilder(new XPathSupport(xpathFactory), config);
341     }
342
343     private static @NonNull CustomCrossSourceStatementReactorBuilder vanillaReactorBuilder(
344             final @NonNull XPathSupport xpathSupport, final YangParserConfiguration config) {
345         final StatementSupportBundle preLinkageBundle = preLinkageBundle(config);
346         final StatementSupportBundle linkageBundle = linkageBundle(preLinkageBundle, config);
347         final StatementSupportBundle stmtDefBundle = stmtDefBundle(linkageBundle, config);
348         final StatementSupportBundle fullDeclarationBundle =
349             fullDeclarationBundle(stmtDefBundle, xpathSupport, config);
350
351         return new CustomCrossSourceStatementReactorBuilder(SUPPORTED_VERSIONS)
352                 .addAllSupports(ModelProcessingPhase.INIT, INIT_BUNDLE)
353                 .addAllSupports(ModelProcessingPhase.SOURCE_PRE_LINKAGE, preLinkageBundle)
354                 .addAllSupports(ModelProcessingPhase.SOURCE_LINKAGE, linkageBundle)
355                 .addAllSupports(ModelProcessingPhase.STATEMENT_DEFINITION, stmtDefBundle)
356                 .addAllSupports(ModelProcessingPhase.FULL_DECLARATION, fullDeclarationBundle)
357                 .addAllSupports(ModelProcessingPhase.EFFECTIVE_MODEL, fullDeclarationBundle)
358                 .addValidationBundle(ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
359                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
360                 .addValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
361                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
362
363                 // FIXME: 7.0.0: we do not seem to need this validation bundle
364                 .addValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
365                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
366
367                 .addValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
368                     YangValidationBundles.SUPPORTED_DATA_NODES);
369     }
370
371     private static @NonNull StatementSupportBundle fullDeclarationBundle(final StatementSupportBundle stmtDefBundle,
372             final XPathSupport xpathSupport, final YangParserConfiguration config) {
373         return StatementSupportBundle.derivedFrom(stmtDefBundle)
374             .addSupport(new LeafStatementSupport(config))
375             .addSupport(new ConfigStatementSupport(config))
376             .addSupport(new DeviationStatementSupport(config))
377             .addVersionSpecificSupport(VERSION_1, new DeviateStatementRFC6020Support(config))
378             .addVersionSpecificSupport(VERSION_1_1, new DeviateStatementRFC7950Support(config))
379             .addVersionSpecificSupport(VERSION_1, ChoiceStatementSupport.rfc6020Instance(config))
380             .addVersionSpecificSupport(VERSION_1_1, ChoiceStatementSupport.rfc7950Instance(config))
381             .addVersionSpecificSupport(VERSION_1, CaseStatementSupport.rfc6020Instance(config))
382             .addVersionSpecificSupport(VERSION_1_1, CaseStatementSupport.rfc7950Instance(config))
383             .addSupport(new MustStatementSupport(xpathSupport, config))
384             .addSupport(new MandatoryStatementSupport(config))
385             .addSupport(new AnyxmlStatementSupport(config))
386             .addVersionSpecificSupport(VERSION_1_1, new AnydataStatementSupport(config))
387             .addSupport(FeatureNamespace.BEHAVIOUR)
388             .addVersionSpecificSupport(VERSION_1, new IfFeatureStatementRFC6020Support(config))
389             .addVersionSpecificSupport(VERSION_1_1, new IfFeatureStatementRFC7950Support(config))
390             .addSupport(GroupingNamespace.BEHAVIOUR)
391             .addSupport(SourceGroupingNamespace.BEHAVIOUR)
392             .addSupport(new UsesStatementSupport(config))
393             .addSupport(new ErrorMessageStatementSupport(config))
394             .addSupport(new ErrorAppTagStatementSupport(config))
395             .addVersionSpecificSupport(VERSION_1, LeafListStatementSupport.rfc6020Instance(config))
396             .addVersionSpecificSupport(VERSION_1_1, LeafListStatementSupport.rfc7950Instance(config))
397             .addSupport(new PresenceStatementSupport(config))
398             .addSupport(new MaxElementsStatementSupport(config))
399             .addSupport(new MinElementsStatementSupport(config))
400             .addSupport(new OrderedByStatementSupport(config))
401             .addSupport(new WhenStatementSupport(xpathSupport, config))
402             .addSupport(AugmentImplicitHandlingNamespace.BEHAVIOUR)
403             .addVersionSpecificSupport(VERSION_1, new AugmentStatementRFC6020Support(config))
404             .addVersionSpecificSupport(VERSION_1_1, new AugmentStatementRFC7950Support(config))
405             .addSupport(RefineTargetNamespace.BEHAVIOUR)
406             .addVersionSpecificSupport(VERSION_1, RefineStatementSupport.rfc6020Instance(config))
407             .addVersionSpecificSupport(VERSION_1_1, RefineStatementSupport.rfc7950Instance(config))
408             .addSupport(new FeatureStatementSupport(config))
409             .addSupport(new PositionStatementSupport(config))
410             .addSupport(new ValueStatementSupport(config))
411             .addSupport(YangNamespaceContextNamespace.BEHAVIOUR)
412             .build();
413     }
414 }