Revert "Bug 4640: Change semantic-version to openconfig-version"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.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.spi.meta;
9
10 import com.google.common.base.Optional;
11 import java.util.Collection;
12 import java.util.Map;
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;
27
28 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
29
30     @Nonnull
31     StatementSource getStatementSource();
32
33     @Nonnull
34     StatementSourceReference getStatementSourceReference();
35
36     @Nonnull
37     StatementDefinition getPublicDefinition();
38
39     /**
40      * @return context of parent of statement
41      */
42     @Nullable
43     StmtContext<?, ?, ?> getParentContext();
44
45     /**
46      * @return raw statement argument string
47      */
48     @Nullable
49     String rawStatementArgument();
50
51     @Nullable
52     A getStatementArgument();
53
54     /**
55      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
56      * {@link Optional#absent()} is returned.
57      *
58      * @return Optional SchemaPath
59      */
60     @Nonnull Optional<SchemaPath> getSchemaPath();
61
62     boolean isConfiguration();
63
64     boolean isEnabledSemanticVersioning();
65
66     @Nonnull
67     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
68             Class<N> type, KT key) throws NamespaceNotAvailableException;
69
70     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
71             Class<N> type);
72
73     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
74
75     @Nonnull
76     StmtContext<?, ?, ?> getRoot();
77
78     /**
79      * Return declared substatements. These are the statements which are explicitly written in the source model.
80      *
81      * @return Collection of declared substatements
82      */
83     @Nonnull
84     Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
85
86     /**
87      * Return effective substatements. These are the statements which are added as this statement's substatements
88      * complete their effective model phase.
89      *
90      * @return Collection of declared substatements
91      */
92     @Nonnull
93     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
94
95     D buildDeclared();
96
97     E buildEffective();
98
99     boolean isSupportedToBuildEffective();
100
101     void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
102
103     Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
104
105     void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
106
107     void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
108
109     StatementContextBase<?, ?, ?> createCopy(
110             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
111             throws SourceException;
112
113     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
114             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
115             throws SourceException;
116
117     CopyHistory getCopyHistory();
118
119     enum SupportedByFeatures {
120         UNDEFINED, SUPPORTED, NOT_SUPPORTED
121     }
122
123     SupportedByFeatures getSupportedByFeatures();
124
125     void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
126
127     StatementContextBase<?, ?, ?> getOriginalCtx();
128
129     void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
130
131     boolean isRootContext();
132
133     void setOrder(int order);
134
135     int getOrder();
136
137     void setCompletedPhase(ModelProcessingPhase completedPhase);
138
139     ModelProcessingPhase getCompletedPhase();
140
141     /**
142      * Return version of root statement context.
143      *
144      * @return version of root statement context
145      */
146     @Nonnull YangVersion getRootVersion();
147
148     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
149             extends StmtContext<A, D, E> {
150
151         @Override
152         StmtContext.Mutable<?, ?, ?> getParentContext();
153
154         <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
155                 Class<N> type, KT key, VT value)
156                 throws NamespaceNotAvailableException;
157
158         @Nonnull
159         @Override
160         StmtContext.Mutable<?, ?, ?> getRoot();
161
162         /**
163          * Create a new inference action to be executed during specified phase. The action cannot be cancelled
164          * and will be executed even if its definition remains incomplete.
165          *
166          * @param phase Target phase
167          * @return A new action builder.
168          * @throws NullPointerException if the specified phase is null
169          */
170         @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
171
172         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
173                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
174
175         void setSupportedByFeatures(boolean isSupported);
176
177         /**
178          * Set version of root statement context.
179          *
180          * @param version
181          *            of root statement context
182          */
183         void setRootVersion(YangVersion version);
184
185         /**
186          * Add mutable statement to seal. Each mutable statement must be sealed
187          * as the last step of statement parser processing.
188          *
189          * @param mutableStatement
190          *            mutable statement which should be sealed
191          */
192         void addMutableStmtToSeal(MutableStatement mutableStatement);
193
194         /**
195          * Add required module. Based on these dependencies are collected
196          * required sources from library sources.
197          *
198          * @param dependency
199          *            ModuleIdentifier of module required by current root
200          *            context
201          */
202         void addRequiredModule(ModuleIdentifier dependency);
203
204         /**
205          * Set identifier of current root context.
206          *
207          * @param identifier
208          *            of current root context
209          */
210         void setRootIdentifier(ModuleIdentifier identifier);
211     }
212 }