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