Move StatementContextBase.getStorageNodeType()
[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.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;
26
27 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
28
29     @Nonnull
30     StatementSource getStatementSource();
31
32     @Nonnull
33     StatementSourceReference getStatementSourceReference();
34
35     @Nonnull
36     StatementDefinition getPublicDefinition();
37
38     /**
39      * @return context of parent of statement
40      */
41     @Nullable
42     StmtContext<?, ?, ?> getParentContext();
43
44     @Nullable
45     String rawStatementArgument();
46
47     @Nullable
48     A getStatementArgument();
49
50     /**
51      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
52      * {@link Optional#absent()} is returned.
53      *
54      * @return Optional SchemaPath
55      */
56     @Nonnull Optional<SchemaPath> getSchemaPath();
57
58     boolean isConfiguration();
59
60     boolean isEnabledSemanticVersioning();
61
62     @Nonnull
63     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
64             Class<N> type, KT key) throws NamespaceNotAvailableException;
65
66     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
67             Class<N> type);
68
69     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
70
71     @Nonnull
72     StmtContext<?, ?, ?> getRoot();
73
74     /**
75      * Return declared substatements. These are the statements which are explicitly written in the source model.
76      *
77      * @return Collection of declared substatements
78      */
79     @Nonnull
80     Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
81
82     /**
83      * Return effective substatements. These are the statements which are added as this statement's substatements
84      * complete their effective model phase.
85      *
86      * @return Collection of declared substatements
87      */
88     @Nonnull
89     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
90
91     D buildDeclared();
92
93     E buildEffective();
94
95     boolean isSupportedToBuildEffective();
96
97     void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
98
99     Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
100
101     void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
102
103     void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
104
105     StatementContextBase<?, ?, ?> createCopy(
106             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
107             throws SourceException;
108
109     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
110             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
111             throws SourceException;
112
113     CopyHistory getCopyHistory();
114
115     enum SupportedByFeatures {
116         UNDEFINED, SUPPORTED, NOT_SUPPORTED
117     }
118
119     SupportedByFeatures getSupportedByFeatures();
120
121     void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
122
123     StatementContextBase<?, ?, ?> getOriginalCtx();
124
125     void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
126
127     boolean isRootContext();
128
129     void setOrder(int order);
130
131     int getOrder();
132
133     void setCompletedPhase(ModelProcessingPhase completedPhase);
134
135     ModelProcessingPhase getCompletedPhase();
136
137     /**
138      * Return version of root statement context.
139      *
140      * @return version of root statement context
141      */
142     @Nonnull YangVersion getRootVersion();
143
144     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
145             extends StmtContext<A, D, E> {
146
147         @Override
148         StmtContext.Mutable<?, ?, ?> getParentContext();
149
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;
153
154         @Nonnull
155         @Override
156         StmtContext.Mutable<?, ?, ?> getRoot();
157
158         /**
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.
161          *
162          * @param phase Target phase
163          * @return A new action builder.
164          * @throws NullPointerException if the specified phase is null
165          */
166         @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
167
168         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
169                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
170
171         void setSupportedByFeatures(boolean isSupported);
172
173         /**
174          * Set version of root statement context.
175          *
176          * @param version
177          *            of root statement context
178          */
179         void setRootVersion(YangVersion version);
180     }
181
182 }