fd44a86e0d4a06951d2a943ee2505839d0648fd0
[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.List;
13 import java.util.Map;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
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     @Nullable
39     StmtContext<?, ?, ?> getParentContext();
40
41     @Nullable
42     String rawStatementArgument();
43
44     @Nullable
45     A getStatementArgument();
46
47     /**
48      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
49      * {@link Optional#absent()} is returned.
50      *
51      * @return Optional SchemaPath
52      */
53     @Nonnull Optional<SchemaPath> getSchemaPath();
54
55     boolean isConfiguration();
56
57     boolean isEnabledSemanticVersioning();
58
59     @Nonnull
60     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
61             Class<N> type, KT key) throws NamespaceNotAvailableException;
62
63     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
64             Class<N> type);
65
66     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
67
68     @Nonnull
69     StmtContext<?, ?, ?> getRoot();
70
71     @Nonnull
72     Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
73
74     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
75
76     Collection<StatementContextBase<?, ?, ?>> substatements();
77
78     D buildDeclared();
79
80     E buildEffective();
81
82     boolean isSupportedToBuildEffective();
83
84     void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
85
86     Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
87
88     void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
89
90     StatementContextBase<?, ?, ?> createCopy(
91             StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
92             throws SourceException;
93
94     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
95             StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
96             throws SourceException;
97
98     enum TypeOfCopy {
99         ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION, ADDED_BY_USES_AUGMENTATION
100     }
101
102     List<TypeOfCopy> getCopyHistory();
103
104     enum SupportedByFeatures {
105         UNDEFINED, SUPPORTED, NOT_SUPPORTED
106     }
107
108     SupportedByFeatures getSupportedByFeatures();
109
110     void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList);
111
112     void addToCopyHistory(TypeOfCopy typeOfCopy);
113
114     StatementContextBase<?, ?, ?> getOriginalCtx();
115
116     void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
117
118     boolean isRootContext();
119
120     void setOrder(int order);
121
122     int getOrder();
123
124     void setCompletedPhase(ModelProcessingPhase completedPhase);
125
126     ModelProcessingPhase getCompletedPhase();
127
128     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
129             extends StmtContext<A, D, E> {
130
131         @Override
132         StmtContext.Mutable<?, ?, ?> getParentContext();
133
134         <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
135                 Class<N> type, KT key, VT value)
136                 throws NamespaceNotAvailableException;
137
138         @Override
139         StmtContext.Mutable<?, ?, ?> getRoot();
140
141         ModelActionBuilder newInferenceAction(ModelProcessingPhase phase);
142
143         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
144                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
145
146         void setSupportedByFeatures(boolean isSupported);
147     }
148
149 }