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