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