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.spi.meta;
10 import com.google.common.base.Optional;
11 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.YangVersion;
17 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
23 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
26 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
28 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
31 StatementSource getStatementSource();
34 StatementSourceReference getStatementSourceReference();
37 StatementDefinition getPublicDefinition();
40 * @return context of parent of statement
43 StmtContext<?, ?, ?> getParentContext();
46 * @return raw statement argument string
49 String rawStatementArgument();
52 A getStatementArgument();
55 * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
56 * {@link Optional#absent()} is returned.
58 * @return Optional SchemaPath
60 @Nonnull Optional<SchemaPath> getSchemaPath();
62 boolean isConfiguration();
65 * Checks whether this statement is placed within a 'yang-data' extension statement.
66 * Some YANG statements are constrained when used within a 'yang-data' statement.
67 * See the following link for more information - https://tools.ietf.org/html/rfc8040#section-8
69 * @return true if it is placed within a 'yang-data' extension statement, otherwise false
71 boolean isInYangDataExtensionBody();
73 boolean isEnabledSemanticVersioning();
76 <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
77 Class<N> type, KT key) throws NamespaceNotAvailableException;
79 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
82 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
85 StmtContext<?, ?, ?> getRoot();
88 * Return declared substatements. These are the statements which are explicitly written in the source model.
90 * @return Collection of declared substatements
93 Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
96 * Return effective substatements. These are the statements which are added as this statement's substatements
97 * complete their effective model phase.
99 * @return Collection of declared substatements
102 Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
108 boolean isSupportedToBuildEffective();
110 void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
112 Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
114 void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
116 void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
118 StatementContextBase<?, ?, ?> createCopy(
119 StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
120 throws SourceException;
122 StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
123 StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
124 throws SourceException;
126 CopyHistory getCopyHistory();
128 enum SupportedByFeatures {
129 UNDEFINED, SUPPORTED, NOT_SUPPORTED
132 SupportedByFeatures getSupportedByFeatures();
134 void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
136 StatementContextBase<?, ?, ?> getOriginalCtx();
138 void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
140 boolean isRootContext();
142 void setOrder(int order);
146 void setCompletedPhase(ModelProcessingPhase completedPhase);
148 ModelProcessingPhase getCompletedPhase();
151 * Return version of root statement context.
153 * @return version of root statement context
155 @Nonnull YangVersion getRootVersion();
157 interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
158 extends StmtContext<A, D, E> {
161 StmtContext.Mutable<?, ?, ?> getParentContext();
163 <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
164 Class<N> type, KT key, VT value)
165 throws NamespaceNotAvailableException;
169 StmtContext.Mutable<?, ?, ?> getRoot();
172 * Create a new inference action to be executed during specified phase. The action cannot be cancelled
173 * and will be executed even if its definition remains incomplete.
175 * @param phase Target phase
176 * @return A new action builder.
177 * @throws NullPointerException if the specified phase is null
179 @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
181 <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
182 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
184 void setSupportedByFeatures(boolean isSupported);
187 * Set version of root statement context.
190 * of root statement context
192 void setRootVersion(YangVersion version);
195 * Add mutable statement to seal. Each mutable statement must be sealed
196 * as the last step of statement parser processing.
198 * @param mutableStatement
199 * mutable statement which should be sealed
201 void addMutableStmtToSeal(MutableStatement mutableStatement);
204 * Add required module. Based on these dependencies are collected
205 * required sources from library sources.
208 * ModuleIdentifier of module required by current root
211 void addRequiredModule(ModuleIdentifier dependency);
214 * Set identifier of current root context.
217 * of current root context
219 void setRootIdentifier(ModuleIdentifier identifier);