Bug 8307: Add the option for activating deviation statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / YangInferencePipeline.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020;
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 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.global;
13 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
14 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
15
16 import com.google.common.collect.ImmutableMap;
17 import com.google.common.collect.Sets;
18 import java.util.Collection;
19 import java.util.Map;
20 import java.util.Set;
21 import org.opendaylight.yangtools.yang.common.YangVersion;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
23 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
25 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
26 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
27 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
28 import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
29 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
30 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
36 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
37 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
38 import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
39 import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
40 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
41 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
42 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
43 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
44 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
45 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier;
46 import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
47 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
48 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
49 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier;
50 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
51 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
52 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
53 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
54 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
55 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
56 import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
57 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
58 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
59 import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
60 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
61 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
62 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
63 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
64 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ActionStatementImpl;
65 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.AnydataStatementImpl;
66 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.AugmentStatementRfc7950Support;
67 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.BitStatementRfc7950Support;
68 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.CaseStatementRfc7950Support;
69 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ChoiceStatementRfc7950Support;
70 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ContainerStatementRfc7950Support;
71 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.DeviateStatementRfc7950Support;
72 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.EnumStatementRfc7950Support;
73 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.GroupingStatementRfc7950Support;
74 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.IdentityStatementRfc7950Support;
75 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ImportStatementRfc7950Support;
76 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.IncludeStatementRfc7950Support;
77 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.InputStatementRfc7950Support;
78 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.LeafListStatementRfc7950Support;
79 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ListStatementRfc7950Support;
80 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ModifierStatementImpl;
81 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ModuleStatementRfc7950Support;
82 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.NotificationStatementRfc7950Support;
83 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.OutputStatementRfc7950Support;
84 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.PatternStatementRfc7950Support;
85 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.RefineStatementRfc7950Support;
86 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.RpcStatementRfc7950Support;
87 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.SubmoduleStatementRfc7950Support;
88 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.TypeStatementRfc7950Support;
89
90 public final class YangInferencePipeline {
91     public static final Set<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
92
93     public static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle
94             .builder(SUPPORTED_VERSIONS).addSupport(global(ValidationBundlesNamespace.class))
95             .addSupport(global(SupportedFeaturesNamespace.class))
96             .addSupport(global(ModulesDeviatedByModules.class))
97             .build();
98
99     public static final StatementSupportBundle PRE_LINKAGE_BUNDLE = StatementSupportBundle
100             .derivedFrom(INIT_BUNDLE)
101             .addVersionSpecificSupport(VERSION_1, new ModuleStatementSupport())
102             .addVersionSpecificSupport(VERSION_1_1, new ModuleStatementRfc7950Support())
103             .addVersionSpecificSupport(VERSION_1, new SubmoduleStatementImpl.Definition())
104             .addVersionSpecificSupport(VERSION_1_1, new SubmoduleStatementRfc7950Support())
105             .addSupport(new NamespaceStatementImpl.Definition())
106             .addVersionSpecificSupport(VERSION_1, new ImportStatementDefinition())
107             .addVersionSpecificSupport(VERSION_1_1, new ImportStatementRfc7950Support())
108             .addVersionSpecificSupport(VERSION_1, new IncludeStatementImpl.Definition())
109             .addVersionSpecificSupport(VERSION_1_1, new IncludeStatementRfc7950Support())
110             .addSupport(new PrefixStatementImpl.Definition())
111             .addSupport(new YangVersionStatementImpl.Definition())
112             .addSupport(new RevisionStatementImpl.Definition())
113             .addSupport(new RevisionDateStatementImpl.Definition())
114             .addSupport(global(ModuleNameToNamespace.class))
115             .addSupport(global(PreLinkageModuleNamespace.class))
116             .addSupport(sourceLocal(ImpPrefixToNamespace.class))
117             .addSupport(global(ModuleCtxToModuleQName.class))
118             .build();
119
120     public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
121             .derivedFrom(PRE_LINKAGE_BUNDLE)
122             .addSupport(new DescriptionStatementImpl.Definition())
123             .addSupport(new ReferenceStatementImpl.Definition())
124             .addSupport(new ContactStatementImpl.Definition())
125             .addSupport(new OrganizationStatementImpl.Definition())
126             .addSupport(new BelongsToStatementImpl.Definition())
127             .addSupport(global(ModuleNamespace.class))
128             .addSupport(global(ModuleNamespaceForBelongsTo.class))
129             .addSupport(global(SubmoduleNamespace.class))
130             .addSupport(global(NamespaceToModule.class))
131             .addSupport(global(ModuleNameToModuleQName.class))
132             .addSupport(global(ModuleCtxToModuleIdentifier.class))
133             .addSupport(global(ModuleQNameToModuleName.class))
134             .addSupport(global(PrefixToModule.class))
135             .addSupport(global(ModuleIdentifierToModuleQName.class))
136             .addSupport(QNameCacheNamespace.getInstance())
137             .addSupport(sourceLocal(ImportedModuleContext.class))
138             .addSupport(sourceLocal(IncludedModuleContext.class))
139             .addSupport(sourceLocal(IncludedSubmoduleNameToIdentifier.class))
140             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
141             .addSupport(sourceLocal(BelongsToPrefixToModuleIdentifier.class))
142             .addSupport(sourceLocal(URIStringToImpPrefix.class))
143             .addSupport(sourceLocal(BelongsToModuleContext.class))
144             .addSupport(sourceLocal(QNameToStatementDefinition.class))
145             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
146             .addSupport(new SemanticVersionStatementImpl.SemanticVersionSupport())
147             .addSupport(global(SemanticVersionNamespace.class))
148             .addSupport(global(SemanticVersionModuleNamespace.class))
149             .addSupport(sourceLocal(ImpPrefixToSemVerModuleIdentifier.class))
150             .build();
151
152     public static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle
153             .derivedFrom(LINKAGE_BUNDLE)
154             .addSupport(new YinElementStatementImpl.Definition())
155             .addSupport(new ArgumentStatementImpl.Definition())
156             .addSupport(new ExtensionStatementImpl.Definition())
157             .addSupport(new ChildSchemaNodes<>())
158             .addSupport(new SchemaNodeIdentifierBuildNamespace())
159             .addSupport(global(ExtensionNamespace.class))
160             .addSupport(new TypedefStatementImpl.Definition())
161             .addSupport(treeScoped(TypeNamespace.class))
162             .addVersionSpecificSupport(VERSION_1, new IdentityStatementImpl.Definition())
163             .addVersionSpecificSupport(VERSION_1_1, new IdentityStatementRfc7950Support())
164             .addSupport(global(IdentityNamespace.class))
165             .addSupport(new DefaultStatementImpl.Definition())
166             .addSupport(new StatusStatementImpl.Definition())
167             .addVersionSpecificSupport(VERSION_1, new TypeStatementImpl.Definition())
168             .addVersionSpecificSupport(VERSION_1_1, new TypeStatementRfc7950Support())
169             .addSupport(new UnitsStatementImpl.Definition())
170             .addSupport(new RequireInstanceStatementImpl.Definition())
171             .addVersionSpecificSupport(VERSION_1, new BitStatementImpl.Definition())
172             .addVersionSpecificSupport(VERSION_1_1, new BitStatementRfc7950Support())
173             .addSupport(new PathStatementImpl.Definition())
174             .addVersionSpecificSupport(VERSION_1, new EnumStatementImpl.Definition())
175             .addVersionSpecificSupport(VERSION_1_1, new EnumStatementRfc7950Support())
176             .addSupport(new LengthStatementImpl.Definition())
177             .addVersionSpecificSupport(VERSION_1, new PatternStatementImpl.Definition())
178             .addVersionSpecificSupport(VERSION_1_1, new PatternStatementRfc7950Support())
179             .addVersionSpecificSupport(VERSION_1_1, new ModifierStatementImpl.Definition())
180             .addSupport(new RangeStatementImpl.Definition())
181             .addSupport(new KeyStatementImpl.Definition())
182             .addVersionSpecificSupport(VERSION_1, new ContainerStatementImpl.Definition())
183             .addVersionSpecificSupport(VERSION_1_1, new ContainerStatementRfc7950Support())
184             .addVersionSpecificSupport(VERSION_1, new GroupingStatementImpl.Definition())
185             .addVersionSpecificSupport(VERSION_1_1, new GroupingStatementRfc7950Support())
186             .addVersionSpecificSupport(VERSION_1, new ListStatementImpl.Definition())
187             .addVersionSpecificSupport(VERSION_1_1, new ListStatementRfc7950Support())
188             .addSupport(new UniqueStatementImpl.Definition())
189             .addVersionSpecificSupport(VERSION_1_1, new ActionStatementImpl.Definition())
190             .addVersionSpecificSupport(VERSION_1, new RpcStatementImpl.Definition())
191             .addVersionSpecificSupport(VERSION_1_1, new RpcStatementRfc7950Support())
192             .addVersionSpecificSupport(VERSION_1, new InputStatementImpl.Definition())
193             .addVersionSpecificSupport(VERSION_1_1, new InputStatementRfc7950Support())
194             .addVersionSpecificSupport(VERSION_1, new OutputStatementImpl.Definition())
195             .addVersionSpecificSupport(VERSION_1_1, new OutputStatementRfc7950Support())
196             .addVersionSpecificSupport(VERSION_1, new NotificationStatementImpl.Definition())
197             .addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRfc7950Support())
198             .addSupport(new FractionDigitsStatementImpl.Definition())
199             .addSupport(new BaseStatementImpl.Definition())
200             .addSupport(global(DerivedIdentitiesNamespace.class))
201             .addSupport(global(StatementDefinitionNamespace.class))
202             .build();
203
204     public static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
205             .derivedFrom(STMT_DEF_BUNDLE)
206             .addSupport(new LeafStatementImpl.Definition())
207             .addSupport(new ConfigStatementImpl.Definition())
208             .addSupport(new DeviationStatementImpl.Definition())
209             .addVersionSpecificSupport(VERSION_1, new DeviateStatementImpl.Definition())
210             .addVersionSpecificSupport(VERSION_1_1, new DeviateStatementRfc7950Support())
211             .addVersionSpecificSupport(VERSION_1, new ChoiceStatementImpl.Definition())
212             .addVersionSpecificSupport(VERSION_1_1, new ChoiceStatementRfc7950Support())
213             .addVersionSpecificSupport(VERSION_1, new CaseStatementImpl.Definition())
214             .addVersionSpecificSupport(VERSION_1_1, new CaseStatementRfc7950Support())
215             .addSupport(new MustStatementImpl.Definition())
216             .addSupport(new MandatoryStatementImpl.Definition())
217             .addSupport(new AnyxmlStatementImpl.Definition())
218             .addVersionSpecificSupport(VERSION_1_1, new AnydataStatementImpl.Definition())
219             .addSupport(new IfFeatureStatementImpl.Definition())
220             .addSupport(new UsesStatementImpl.Definition())
221             .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
222             .addSupport(new ErrorMessageStatementImpl.Definition())
223             .addSupport(new ErrorAppTagStatementImpl.Definition())
224             .addVersionSpecificSupport(VERSION_1, new LeafListStatementImpl.Definition())
225             .addVersionSpecificSupport(VERSION_1_1, new LeafListStatementRfc7950Support())
226             .addSupport(new PresenceStatementImpl.Definition())
227             .addSupport(new MaxElementsStatementImpl.Definition())
228             .addSupport(new MinElementsStatementImpl.Definition())
229             .addSupport(new OrderedByStatementImpl.Definition())
230             .addSupport(new WhenStatementImpl.Definition())
231             .addVersionSpecificSupport(VERSION_1, new AugmentStatementImpl.Definition())
232             .addVersionSpecificSupport(VERSION_1_1, new AugmentStatementRfc7950Support())
233             .addSupport(treeScoped(AugmentToChoiceNamespace.class))
234             .addVersionSpecificSupport(VERSION_1, new RefineStatementImpl.Definition())
235             .addVersionSpecificSupport(VERSION_1_1, new RefineStatementRfc7950Support())
236             .addSupport(new FeatureStatementImpl.Definition())
237             .addSupport(new PositionStatementImpl.Definition())
238             .addSupport(new ValueStatementImpl.Definition())
239             .addSupport(new AnyxmlSchemaLocationStatementImpl.AnyxmlSchemaLocationSupport())
240             .addSupport(treeScoped(AnyxmlSchemaLocationNamespace.class))
241             .addSupport(global(StmtOrderingNamespace.class))
242             .build();
243
244     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
245             .<ModelProcessingPhase, StatementSupportBundle> builder()
246             .put(ModelProcessingPhase.INIT, INIT_BUNDLE)
247             .put(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
248             .put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
249             .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
250             .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
251             .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
252             .build();
253
254     public static final Map<ValidationBundleType, Collection<StatementDefinition>> RFC6020_VALIDATION_BUNDLE = ImmutableMap
255             .<ValidationBundleType, Collection<StatementDefinition>> builder()
256             .put(ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS, YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
257             .put(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS, YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
258             .put(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS, YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
259             .put(ValidationBundleType.SUPPORTED_DATA_NODES, YangValidationBundles.SUPPORTED_DATA_NODES)
260             .build();
261
262     public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor
263             .builder()
264             .setBundle(ModelProcessingPhase.INIT, INIT_BUNDLE)
265             .setBundle(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
266             .setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
267             .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,
268                     STMT_DEF_BUNDLE)
269             .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
270             .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
271             .setValidationBundle(
272                     ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
273                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
274             .setValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
275                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
276             .setValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
277                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
278             .setValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
279                     YangValidationBundles.SUPPORTED_DATA_NODES)
280              .build();
281
282     private YangInferencePipeline() {
283         throw new UnsupportedOperationException("Utility class");
284     }
285 }