2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.impl;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.odlext.parser.AugmentIdentifierStatementSupport;
13 import org.opendaylight.yangtools.odlext.parser.ContextInstanceStatementSupport;
14 import org.opendaylight.yangtools.odlext.parser.ContextReferenceStatementSupport;
15 import org.opendaylight.yangtools.odlext.parser.InstanceTargetStatementSupport;
16 import org.opendaylight.yangtools.odlext.parser.RpcContextReferenceStatementSupport;
17 import org.opendaylight.yangtools.openconfig.parser.EncryptedValueStatementSupport;
18 import org.opendaylight.yangtools.openconfig.parser.HashedValueStatementSupport;
19 import org.opendaylight.yangtools.openconfig.parser.OpenConfigVersionSupport;
20 import org.opendaylight.yangtools.rfc6241.parser.GetFilterElementAttributesStatementSupport;
21 import org.opendaylight.yangtools.rfc6536.parser.DefaultDenyAllStatementSupport;
22 import org.opendaylight.yangtools.rfc6536.parser.DefaultDenyWriteStatementSupport;
23 import org.opendaylight.yangtools.rfc6643.parser.AliasStatementSupport;
24 import org.opendaylight.yangtools.rfc6643.parser.DefValStatementSupport;
25 import org.opendaylight.yangtools.rfc6643.parser.DisplayHintStatementSupport;
26 import org.opendaylight.yangtools.rfc6643.parser.ImpliedStatementSupport;
27 import org.opendaylight.yangtools.rfc6643.parser.MaxAccessStatementSupport;
28 import org.opendaylight.yangtools.rfc6643.parser.OidStatementSupport;
29 import org.opendaylight.yangtools.rfc6643.parser.SubIdStatementSupport;
30 import org.opendaylight.yangtools.rfc7952.parser.AnnotationStatementSupport;
31 import org.opendaylight.yangtools.rfc8040.parser.YangDataArgumentNamespace;
32 import org.opendaylight.yangtools.rfc8040.parser.YangDataStatementSupport;
33 import org.opendaylight.yangtools.rfc8528.parser.MountPointStatementSupport;
34 import org.opendaylight.yangtools.rfc8639.parser.SubscriptionStateNotificationStatementSupport;
35 import org.opendaylight.yangtools.rfc8819.parser.ModuleTagStatementSupport;
36 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
37 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.CustomCrossSourceStatementReactorBuilder;
38 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
39 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
40 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
41 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.Builder;
42 import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
45 * Utility class for instantiating default-configured {@link CrossSourceStatementReactor}s.
47 * @author Robert Varga
50 public final class DefaultReactors {
51 private static final class DefaultReactor {
52 // Thread-safe lazy init
53 static final @NonNull CrossSourceStatementReactor INSTANCE = defaultReactorBuilder().build();
56 private DefaultReactors() {
61 * Get a shared default-configured reactor instance. This instance is configured to handle both RFC6020 and RFC7950,
64 * <li>RFC6536's default-deny-{all,write} extensions</li>
65 * <li>RFC7952's annotation extension</li>
66 * <li>RFC8040's yang-data extension</li>
67 * <li>OpenConfig extensions</li>
68 * <li>OpenDaylight extensions</li>
71 * @return a shared default-configured reactor instance.
73 public static @NonNull CrossSourceStatementReactor defaultReactor() {
74 return DefaultReactor.INSTANCE;
78 * Return a baseline CrossSourceStatementReactor {@link Builder}. The builder is initialized to the equivalent
79 * of the reactor returned via {@link #defaultReactor()}, but can be further customized before use.
81 * @return A populated CrossSourceStatementReactor builder.
83 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder() {
84 return defaultReactorBuilder(YangParserConfiguration.DEFAULT);
88 * Return a baseline CrossSourceStatementReactor {@link Builder}. The builder is initialized to the equivalent
89 * of the reactor returned via {@link #defaultReactor()}, but can be further customized before use.
91 * @param config parser configuration
92 * @return A populated CrossSourceStatementReactor builder.
94 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
95 final YangParserConfiguration config) {
96 return addExtensions(RFC7950Reactors.defaultReactorBuilder(config), config);
100 * Return a baseline CrossSourceStatementReactor {@link Builder}. The builder is initialized to the equivalent
101 * of the reactor returned via {@link #defaultReactor()}, but can be further customized before use.
103 * @return A populated CrossSourceStatementReactor builder.
105 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
106 final YangXPathParserFactory xpathFactory) {
107 return defaultReactorBuilder(xpathFactory, YangParserConfiguration.DEFAULT);
111 * Return a baseline CrossSourceStatementReactor {@link Builder}. The builder is initialized to the equivalent
112 * of the reactor returned via {@link #defaultReactor()}, but can be further customized before use.
114 * @param config parser configuration
115 * @return A populated CrossSourceStatementReactor builder.
117 public static @NonNull CustomCrossSourceStatementReactorBuilder defaultReactorBuilder(
118 final YangXPathParserFactory xpathFactory, final YangParserConfiguration config) {
119 return addExtensions(RFC7950Reactors.defaultReactorBuilder(xpathFactory, config), config);
122 private static @NonNull CustomCrossSourceStatementReactorBuilder addExtensions(
123 final @NonNull CustomCrossSourceStatementReactorBuilder builder, final YangParserConfiguration config) {
125 // OpenDaylight extensions
126 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new AugmentIdentifierStatementSupport(config))
127 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new ContextInstanceStatementSupport(config))
128 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new ContextReferenceStatementSupport(config))
129 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new InstanceTargetStatementSupport(config))
130 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new RpcContextReferenceStatementSupport(config))
132 // RFC6241 get-filter-element-attributes support
133 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
134 new GetFilterElementAttributesStatementSupport(config))
136 // RFC6536 default-deny-{all,write} support
137 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new DefaultDenyAllStatementSupport(config))
138 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new DefaultDenyWriteStatementSupport(config))
140 // RFC6643 extensions
141 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new DisplayHintStatementSupport(config))
142 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new MaxAccessStatementSupport(config))
143 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new DefValStatementSupport(config))
144 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new ImpliedStatementSupport(config))
145 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new AliasStatementSupport(config))
146 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new OidStatementSupport(config))
147 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new SubIdStatementSupport(config))
149 // RFC7952 annotation support
150 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new AnnotationStatementSupport(config))
152 // RFC8040 yang-data support
153 .addNamespaceSupport(ModelProcessingPhase.FULL_DECLARATION, YangDataArgumentNamespace.BEHAVIOUR)
154 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new YangDataStatementSupport(config))
156 // RFC8528 mount-point support
157 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new MountPointStatementSupport(config))
159 // RFC8639 subscription-state-notification support
160 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
161 new SubscriptionStateNotificationStatementSupport(config))
163 // RFC8819 module-tag extension support
164 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new ModuleTagStatementSupport(config))
166 // OpenConfig extensions support
167 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new EncryptedValueStatementSupport(config))
168 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new HashedValueStatementSupport(config))
169 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, new OpenConfigVersionSupport(config));