BUG-6757: revert fix for BUG-4456
[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.parser.spi.meta.NamespaceBehaviour.global;
11 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
12 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
13
14 import com.google.common.collect.ImmutableMap;
15 import java.util.Map;
16 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
17 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
18 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
19 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
20 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
21 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
22 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
27 import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
28 import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
29 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
30 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
31 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
32 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
33 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
34 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
35 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
36 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
37 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
38 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
39 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
40 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
41 import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
42 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
43 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
44 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
45
46 public final class YangInferencePipeline {
47
48     public static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle
49             .builder().addSupport(global(ValidationBundlesNamespace.class))
50             .build();
51
52     public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
53             .derivedFrom(INIT_BUNDLE)
54             .addSupport(new ModuleStatementSupport())
55             .addSupport(new SubmoduleStatementImpl.Definition())
56             .addSupport(new NamespaceStatementImpl.Definition())
57             .addSupport(new ImportStatementDefinition())
58             .addSupport(new IncludeStatementImpl.Definition())
59             .addSupport(new PrefixStatementImpl.Definition())
60             .addSupport(new YangVersionStatementImpl.Definition())
61             .addSupport(new DescriptionStatementImpl.Definition())
62             .addSupport(new RevisionStatementImpl.Definition())
63             .addSupport(new RevisionDateStatementImpl.Definition())
64             .addSupport(new ReferenceStatementImpl.Definition())
65             .addSupport(new ContactStatementImpl.Definition())
66             .addSupport(new OrganizationStatementImpl.Definition())
67             .addSupport(new BelongsToStatementImpl.Definition())
68             .addSupport(global(ModuleNamespace.class))
69             .addSupport(global(ModuleNamespaceForBelongsTo.class))
70             .addSupport(global(SubmoduleNamespace.class))
71             .addSupport(global(NamespaceToModule.class))
72             .addSupport(global(ModuleNameToModuleQName.class))
73             .addSupport(global(ModuleCtxToModuleQName.class))
74             .addSupport(global(ModuleQNameToModuleName.class))
75             .addSupport(global(PrefixToModule.class))
76             .addSupport(global(ModuleIdentifierToModuleQName.class))
77             .addSupport(QNameCacheNamespace.getInstance())
78             .addSupport(sourceLocal(ImportedModuleContext.class))
79             .addSupport(sourceLocal(IncludedModuleContext.class))
80             .addSupport(sourceLocal(IncludedSubmoduleNameToIdentifier.class))
81             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
82             .addSupport(sourceLocal(BelongsToPrefixToModuleIdentifier.class))
83             .addSupport(sourceLocal(URIStringToImpPrefix.class))
84             .addSupport(sourceLocal(BelongsToModuleContext.class))
85             .addSupport(sourceLocal(QNameToStatementDefinition.class))
86             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class)).build();
87
88
89     private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle
90             .derivedFrom(LINKAGE_BUNDLE)
91             .addSupport(new YinElementStatementImpl.Definition())
92             .addSupport(new ArgumentStatementImpl.Definition())
93             .addSupport(new ExtensionStatementImpl.Definition())
94             .addSupport(new ChildSchemaNodes<>())
95             .addSupport(new SchemaNodeIdentifierBuildNamespace())
96             .addSupport(global(ExtensionNamespace.class))
97             .addSupport(new TypedefStatementImpl.Definition())
98             .addSupport(treeScoped(TypeNamespace.class))
99             .addSupport(new IdentityStatementImpl.Definition())
100             .addSupport(global(IdentityNamespace.class))
101             .addSupport(new DefaultStatementImpl.Definition())
102             .addSupport(new StatusStatementImpl.Definition())
103             .addSupport(new TypeStatementImpl.Definition())
104             .addSupport(new UnitsStatementImpl.Definition())
105             .addSupport(new RequireInstanceStatementImpl.Definition())
106             .addSupport(new BitStatementImpl.Definition())
107             .addSupport(new PathStatementImpl.Definition())
108             .addSupport(new EnumStatementImpl.Definition())
109             .addSupport(new LengthStatementImpl.Definition())
110             .addSupport(new PatternStatementImpl.Definition())
111             .addSupport(new RangeStatementImpl.Definition())
112             .addSupport(new ContainerStatementImpl.Definition())
113             .addSupport(new GroupingStatementImpl.Definition())
114             .addSupport(new ListStatementImpl.Definition())
115             .addSupport(new UniqueStatementImpl.Definition())
116             .addSupport(new RpcStatementImpl.Definition())
117             .addSupport(new InputStatementImpl.Definition())
118             .addSupport(new OutputStatementImpl.Definition())
119             .addSupport(new NotificationStatementImpl.Definition())
120             .addSupport(new FractionDigitsStatementImpl.Definition())
121             .addSupport(new BaseStatementImpl.Definition())
122             .addSupport(global(DerivedIdentitiesNamespace.class))
123             .build();
124
125     private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
126             .derivedFrom(STMT_DEF_BUNDLE)
127             .addSupport(new LeafStatementImpl.Definition())
128             .addSupport(new ConfigStatementImpl.Definition())
129             .addSupport(new DeviationStatementImpl.Definition())
130             .addSupport(new DeviateStatementImpl.Definition())
131             .addSupport(new ChoiceStatementImpl.Definition())
132             .addSupport(new CaseStatementImpl.Definition())
133             .addSupport(new MustStatementImpl.Definition())
134             .addSupport(new MandatoryStatementImpl.Definition())
135             .addSupport(new AnyxmlStatementImpl.Definition())
136             .addSupport(new IfFeatureStatementImpl.Definition())
137             .addSupport(new UsesStatementImpl.Definition())
138             .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
139             .addSupport(new ErrorMessageStatementImpl.Definition())
140             .addSupport(new ErrorAppTagStatementImpl.Definition())
141             .addSupport(new LeafListStatementImpl.Definition())
142             .addSupport(new PresenceStatementImpl.Definition())
143             .addSupport(new KeyStatementImpl.Definition())
144             .addSupport(new MaxElementsStatementImpl.Definition())
145             .addSupport(new MinElementsStatementImpl.Definition())
146             .addSupport(new OrderedByStatementImpl.Definition())
147             .addSupport(new WhenStatementImpl.Definition())
148             .addSupport(new AugmentStatementImpl.Definition())
149             .addSupport(treeScoped(AugmentToChoiceNamespace.class))
150             .addSupport(new RefineStatementImpl.Definition())
151             .addSupport(new FeatureStatementImpl.Definition())
152             .addSupport(new PositionStatementImpl.Definition())
153             .addSupport(new ValueStatementImpl.Definition())
154             .addSupport(new AnyxmlSchemaLocationStatementImpl.AnyxmlSchemaLocationSupport())
155             .addSupport(treeScoped(AnyxmlSchemaLocationNamespace.class))
156             .addSupport(global(StmtOrderingNamespace.class))
157             .build();
158
159     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
160             .<ModelProcessingPhase, StatementSupportBundle> builder()
161             .put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
162             .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
163             .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
164             .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
165             .build();
166
167     public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor
168             .builder()
169             .setBundle(ModelProcessingPhase.INIT, INIT_BUNDLE)
170             .setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
171             .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,
172                     STMT_DEF_BUNDLE)
173             .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
174             .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
175             .setValidationBundle(
176                     ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
177                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
178             .setValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
179                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
180             .setValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
181                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
182             .setValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
183                     YangValidationBundles.SUPPORTED_DATA_NODES)
184              .build();
185
186     private YangInferencePipeline() {
187         throw new UnsupportedOperationException("Utility class");
188     }
189 }