import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(ii, case2Cont);
-
+ modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
*/
@Nonnull Optional<SchemaPath> getSchemaPath();
+ boolean isConfiguration();
+
@Nonnull
<K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
Class<N> type, KT key) throws NamespaceNotAvailableException;
return null;
}
+ @SuppressWarnings("unchecked")
+ public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstEffectiveSubstatement(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
+ for (StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
+ if (producesDeclared(subStmtContext,declaredType)) {
+ return (StmtContext<AT, ?, ?>) subStmtContext;
+ }
+ }
+ return null;
+ }
+
+ public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstSubstatement(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
+ StmtContext<AT, ?, ?> declaredSubstatement = findFirstDeclaredSubstatement(stmtContext, declaredType);
+ return declaredSubstatement != null ? declaredSubstatement : findFirstEffectiveSubstatement(stmtContext, declaredType);
+ }
+
@SafeVarargs
public static StmtContext<?, ?, ?> findFirstDeclaredSubstatement(final StmtContext<?, ?, ?> stmtContext,
int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
public boolean isRootContext() {
return true;
}
+
+ @Override
+ public boolean isConfiguration() {
+ return true;
+ }
}
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
public boolean isRootContext() {
return false;
}
+
+ @Override
+ public boolean isConfiguration() {
+ StmtContext<Boolean, ?, ?> configStatement = StmtContextUtils
+ .findFirstSubstatement(this, ConfigStatement.class);
+
+ /*
+ * If "config" statement is not specified, the default is the same as
+ * the parent schema node's "config" value.
+ */
+ if (configStatement == null) {
+ return parent.isConfiguration();
+ }
+
+ /*
+ * If a parent node has "config" set to "true", the node underneath it can
+ * have "config" set to "true" or "false".
+ */
+ if (parent.isConfiguration()) {
+ return configStatement.getStatementArgument();
+ }
+
+ /*
+ * If a parent node has "config" set to "false", no node underneath it
+ * can have "config" set to "true", therefore only "false" is permitted.
+ */
+ if (!configStatement.getStatementArgument()) {
+ return false;
+ }
+
+ throw new InferenceException(
+ "Parent node has config statement set to false, therefore no node underneath it can have config set to true",
+ getStatementSourceReference());
+ }
}
this.path = ctx.getSchemaPath().get();
this.constraints = EffectiveConstraintDefinitionImpl.forParent(this);
-
- ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class);
- this.configuration = (configStmt == null) ? true : configStmt.argument();
+ this.configuration = ctx.isConfiguration();
// initSubstatementCollectionsAndFields
return Optional.fromNullable(original);
}
- @Override
- public boolean isConfiguration() {
- return false;
- }
-
@Override
public int hashCode() {
final int prime = 31;