Bug 6869: [Yang 1.1] Allow if-feature in bit, enum, refine & identity
[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.PrefixToModule;
57 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
58 import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
59 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
60 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
61 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
62 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
63 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ActionStatementImpl;
64 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.AnydataStatementImpl;
65 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.AugmentStatementRfc7950Support;
66 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.BitStatementRfc7950Support;
67 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.CaseStatementRfc7950Support;
68 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ChoiceStatementRfc7950Support;
69 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ContainerStatementRfc7950Support;
70 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.EnumStatementRfc7950Support;
71 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.GroupingStatementRfc7950Support;
72 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.IdentityStatementRfc7950Support;
73 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ImportStatementRfc7950Support;
74 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.IncludeStatementRfc7950Support;
75 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.InputStatementRfc7950Support;
76 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ListStatementRfc7950Support;
77 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.ModuleStatementRfc7950Support;
78 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.NotificationStatementRfc7950Support;
79 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.OutputStatementRfc7950Support;
80 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.RefineStatementRfc7950Support;
81 import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.SubmoduleStatementRfc7950Support;
82
83 public final class YangInferencePipeline {
84     public static final Set<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
85
86     public static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle
87             .builder(SUPPORTED_VERSIONS).addSupport(global(ValidationBundlesNamespace.class))
88             .addSupport(global(SupportedFeaturesNamespace.class))
89             .build();
90
91     public static final StatementSupportBundle PRE_LINKAGE_BUNDLE = StatementSupportBundle
92             .derivedFrom(INIT_BUNDLE)
93             .addVersionSpecificSupport(VERSION_1, new ModuleStatementSupport())
94             .addVersionSpecificSupport(VERSION_1_1, new ModuleStatementRfc7950Support())
95             .addVersionSpecificSupport(VERSION_1, new SubmoduleStatementImpl.Definition())
96             .addVersionSpecificSupport(VERSION_1_1, new SubmoduleStatementRfc7950Support())
97             .addSupport(new NamespaceStatementImpl.Definition())
98             .addVersionSpecificSupport(VERSION_1, new ImportStatementDefinition())
99             .addVersionSpecificSupport(VERSION_1_1, new ImportStatementRfc7950Support())
100             .addVersionSpecificSupport(VERSION_1, new IncludeStatementImpl.Definition())
101             .addVersionSpecificSupport(VERSION_1_1, new IncludeStatementRfc7950Support())
102             .addSupport(new PrefixStatementImpl.Definition())
103             .addSupport(new YangVersionStatementImpl.Definition())
104             .addSupport(new RevisionStatementImpl.Definition())
105             .addSupport(global(ModuleNameToNamespace.class))
106             .addSupport(global(PreLinkageModuleNamespace.class))
107             .addSupport(sourceLocal(ImpPrefixToNamespace.class))
108             .addSupport(global(ModuleCtxToModuleQName.class))
109             .build();
110
111     public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
112             .derivedFrom(PRE_LINKAGE_BUNDLE)
113             .addSupport(new DescriptionStatementImpl.Definition())
114             .addSupport(new RevisionDateStatementImpl.Definition())
115             .addSupport(new ReferenceStatementImpl.Definition())
116             .addSupport(new ContactStatementImpl.Definition())
117             .addSupport(new OrganizationStatementImpl.Definition())
118             .addSupport(new BelongsToStatementImpl.Definition())
119             .addSupport(global(ModuleNamespace.class))
120             .addSupport(global(ModuleNamespaceForBelongsTo.class))
121             .addSupport(global(SubmoduleNamespace.class))
122             .addSupport(global(NamespaceToModule.class))
123             .addSupport(global(ModuleNameToModuleQName.class))
124             .addSupport(global(ModuleCtxToModuleIdentifier.class))
125             .addSupport(global(ModuleQNameToModuleName.class))
126             .addSupport(global(PrefixToModule.class))
127             .addSupport(global(ModuleIdentifierToModuleQName.class))
128             .addSupport(QNameCacheNamespace.getInstance())
129             .addSupport(sourceLocal(ImportedModuleContext.class))
130             .addSupport(sourceLocal(IncludedModuleContext.class))
131             .addSupport(sourceLocal(IncludedSubmoduleNameToIdentifier.class))
132             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
133             .addSupport(sourceLocal(BelongsToPrefixToModuleIdentifier.class))
134             .addSupport(sourceLocal(URIStringToImpPrefix.class))
135             .addSupport(sourceLocal(BelongsToModuleContext.class))
136             .addSupport(sourceLocal(QNameToStatementDefinition.class))
137             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
138             .addSupport(new SemanticVersionStatementImpl.SemanticVersionSupport())
139             .addSupport(global(SemanticVersionNamespace.class))
140             .addSupport(global(SemanticVersionModuleNamespace.class))
141             .addSupport(sourceLocal(ImpPrefixToSemVerModuleIdentifier.class))
142             .build();
143
144     public static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle
145             .derivedFrom(LINKAGE_BUNDLE)
146             .addSupport(new YinElementStatementImpl.Definition())
147             .addSupport(new ArgumentStatementImpl.Definition())
148             .addSupport(new ExtensionStatementImpl.Definition())
149             .addSupport(new ChildSchemaNodes<>())
150             .addSupport(new SchemaNodeIdentifierBuildNamespace())
151             .addSupport(global(ExtensionNamespace.class))
152             .addSupport(new TypedefStatementImpl.Definition())
153             .addSupport(treeScoped(TypeNamespace.class))
154             .addVersionSpecificSupport(VERSION_1, new IdentityStatementImpl.Definition())
155             .addVersionSpecificSupport(VERSION_1_1, new IdentityStatementRfc7950Support())
156             .addSupport(global(IdentityNamespace.class))
157             .addSupport(new DefaultStatementImpl.Definition())
158             .addSupport(new StatusStatementImpl.Definition())
159             .addSupport(new TypeStatementImpl.Definition())
160             .addSupport(new UnitsStatementImpl.Definition())
161             .addSupport(new RequireInstanceStatementImpl.Definition())
162             .addVersionSpecificSupport(VERSION_1, new BitStatementImpl.Definition())
163             .addVersionSpecificSupport(VERSION_1_1, new BitStatementRfc7950Support())
164             .addSupport(new PathStatementImpl.Definition())
165             .addVersionSpecificSupport(VERSION_1, new EnumStatementImpl.Definition())
166             .addVersionSpecificSupport(VERSION_1_1, new EnumStatementRfc7950Support())
167             .addSupport(new LengthStatementImpl.Definition())
168             .addSupport(new PatternStatementImpl.Definition())
169             .addSupport(new RangeStatementImpl.Definition())
170             .addVersionSpecificSupport(VERSION_1, new ContainerStatementImpl.Definition())
171             .addVersionSpecificSupport(VERSION_1_1, new ContainerStatementRfc7950Support())
172             .addVersionSpecificSupport(VERSION_1, new GroupingStatementImpl.Definition())
173             .addVersionSpecificSupport(VERSION_1_1, new GroupingStatementRfc7950Support())
174             .addVersionSpecificSupport(VERSION_1, new ListStatementImpl.Definition())
175             .addVersionSpecificSupport(VERSION_1_1, new ListStatementRfc7950Support())
176             .addSupport(new UniqueStatementImpl.Definition())
177             .addVersionSpecificSupport(VERSION_1_1, new ActionStatementImpl.Definition())
178             .addSupport(new RpcStatementImpl.Definition())
179             .addVersionSpecificSupport(VERSION_1, new InputStatementImpl.Definition())
180             .addVersionSpecificSupport(VERSION_1_1, new InputStatementRfc7950Support())
181             .addVersionSpecificSupport(VERSION_1, new OutputStatementImpl.Definition())
182             .addVersionSpecificSupport(VERSION_1_1, new OutputStatementRfc7950Support())
183             .addVersionSpecificSupport(VERSION_1, new NotificationStatementImpl.Definition())
184             .addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRfc7950Support())
185             .addSupport(new FractionDigitsStatementImpl.Definition())
186             .addSupport(new BaseStatementImpl.Definition())
187             .addSupport(global(DerivedIdentitiesNamespace.class))
188             .addSupport(global(StatementDefinitionNamespace.class))
189             .build();
190
191     public static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
192             .derivedFrom(STMT_DEF_BUNDLE)
193             .addSupport(new LeafStatementImpl.Definition())
194             .addSupport(new ConfigStatementImpl.Definition())
195             .addSupport(new DeviationStatementImpl.Definition())
196             .addSupport(new DeviateStatementImpl.Definition())
197             .addVersionSpecificSupport(VERSION_1, new ChoiceStatementImpl.Definition())
198             .addVersionSpecificSupport(VERSION_1_1, new ChoiceStatementRfc7950Support())
199             .addVersionSpecificSupport(VERSION_1, new CaseStatementImpl.Definition())
200             .addVersionSpecificSupport(VERSION_1_1, new CaseStatementRfc7950Support())
201             .addSupport(new MustStatementImpl.Definition())
202             .addSupport(new MandatoryStatementImpl.Definition())
203             .addSupport(new AnyxmlStatementImpl.Definition())
204             .addVersionSpecificSupport(VERSION_1_1, new AnydataStatementImpl.Definition())
205             .addSupport(new IfFeatureStatementImpl.Definition())
206             .addSupport(new UsesStatementImpl.Definition())
207             .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
208             .addSupport(new ErrorMessageStatementImpl.Definition())
209             .addSupport(new ErrorAppTagStatementImpl.Definition())
210             .addSupport(new LeafListStatementImpl.Definition())
211             .addSupport(new PresenceStatementImpl.Definition())
212             .addSupport(new KeyStatementImpl.Definition())
213             .addSupport(new MaxElementsStatementImpl.Definition())
214             .addSupport(new MinElementsStatementImpl.Definition())
215             .addSupport(new OrderedByStatementImpl.Definition())
216             .addSupport(new WhenStatementImpl.Definition())
217             .addVersionSpecificSupport(VERSION_1, new AugmentStatementImpl.Definition())
218             .addVersionSpecificSupport(VERSION_1_1, new AugmentStatementRfc7950Support())
219             .addSupport(treeScoped(AugmentToChoiceNamespace.class))
220             .addVersionSpecificSupport(VERSION_1, new RefineStatementImpl.Definition())
221             .addVersionSpecificSupport(VERSION_1_1, new RefineStatementRfc7950Support())
222             .addSupport(new FeatureStatementImpl.Definition())
223             .addSupport(new PositionStatementImpl.Definition())
224             .addSupport(new ValueStatementImpl.Definition())
225             .addSupport(new AnyxmlSchemaLocationStatementImpl.AnyxmlSchemaLocationSupport())
226             .addSupport(treeScoped(AnyxmlSchemaLocationNamespace.class))
227             .addSupport(global(StmtOrderingNamespace.class))
228             .build();
229
230     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
231             .<ModelProcessingPhase, StatementSupportBundle> builder()
232             .put(ModelProcessingPhase.INIT, INIT_BUNDLE)
233             .put(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
234             .put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
235             .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
236             .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
237             .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
238             .build();
239
240     public static final Map<ValidationBundleType, Collection<StatementDefinition>> RFC6020_VALIDATION_BUNDLE = ImmutableMap
241             .<ValidationBundleType, Collection<StatementDefinition>> builder()
242             .put(ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS, YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
243             .put(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS, YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
244             .put(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS, YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
245             .put(ValidationBundleType.SUPPORTED_DATA_NODES, YangValidationBundles.SUPPORTED_DATA_NODES)
246             .build();
247
248     public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor
249             .builder()
250             .setBundle(ModelProcessingPhase.INIT, INIT_BUNDLE)
251             .setBundle(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
252             .setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
253             .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,
254                     STMT_DEF_BUNDLE)
255             .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
256             .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
257             .setValidationBundle(
258                     ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
259                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
260             .setValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
261                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
262             .setValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
263                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
264             .setValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
265                     YangValidationBundles.SUPPORTED_DATA_NODES)
266              .build();
267
268     private YangInferencePipeline() {
269         throw new UnsupportedOperationException("Utility class");
270     }
271 }