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.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
27 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
30 StatementSource getStatementSource();
33 StatementSourceReference getStatementSourceReference();
36 StatementDefinition getPublicDefinition();
39 * @return context of parent of statement
42 StmtContext<?, ?, ?> getParentContext();
45 String rawStatementArgument();
48 A getStatementArgument();
51 * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
52 * {@link Optional#absent()} is returned.
54 * @return Optional SchemaPath
56 @Nonnull Optional<SchemaPath> getSchemaPath();
58 boolean isConfiguration();
60 boolean isEnabledSemanticVersioning();
63 <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
64 Class<N> type, KT key) throws NamespaceNotAvailableException;
66 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
69 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
72 StmtContext<?, ?, ?> getRoot();
75 * Return declared substatements. These are the statements which are explicitly written in the source model.
77 * @return Collection of declared substatements
80 Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
83 * Return effective substatements. These are the statements which are added as this statement's substatements
84 * complete their effective model phase.
86 * @return Collection of declared substatements
89 Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
95 boolean isSupportedToBuildEffective();
97 void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
99 Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
101 void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
103 void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
105 StatementContextBase<?, ?, ?> createCopy(
106 StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
107 throws SourceException;
109 StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
110 StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
111 throws SourceException;
113 CopyHistory getCopyHistory();
115 enum SupportedByFeatures {
116 UNDEFINED, SUPPORTED, NOT_SUPPORTED
119 SupportedByFeatures getSupportedByFeatures();
121 void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
123 StatementContextBase<?, ?, ?> getOriginalCtx();
125 void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
127 boolean isRootContext();
129 void setOrder(int order);
133 void setCompletedPhase(ModelProcessingPhase completedPhase);
135 ModelProcessingPhase getCompletedPhase();
138 * Return version of root statement context.
140 * @return version of root statement context
142 @Nonnull YangVersion getRootVersion();
144 interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
145 extends StmtContext<A, D, E> {
148 StmtContext.Mutable<?, ?, ?> getParentContext();
150 <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
151 Class<N> type, KT key, VT value)
152 throws NamespaceNotAvailableException;
156 StmtContext.Mutable<?, ?, ?> getRoot();
159 * Create a new inference action to be executed during specified phase. The action cannot be cancelled
160 * and will be executed even if its definition remains incomplete.
162 * @param phase Target phase
163 * @return A new action builder.
164 * @throws NullPointerException if the specified phase is null
166 @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
168 <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
169 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
171 void setSupportedByFeatures(boolean isSupported);
174 * Set version of root statement context.
177 * of root statement context
179 void setRootVersion(YangVersion version);