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