X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2Ftree%2FInMemoryDataTree.java;h=1078f74b17187f5b71e2ab6737091f1d2ffa84fc;hb=37380a5c65e213bc5f34b521d8f8e7d315df7465;hp=587664ca39561cc0b689da1fe5ff829e030bdc10;hpb=c8668229ad6e73d5ae03a52f4b87e8e4d2a67c6e;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java index 587664ca39..1078f74b17 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.tree; -import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; @@ -24,12 +23,11 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguratio import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ContainerLike; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,17 +57,18 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree { private volatile DataTreeState state; InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration treeConfig, - final SchemaContext schemaContext) { + final EffectiveModelContext schemaContext) { this.treeConfig = requireNonNull(treeConfig, "treeConfig"); maskMandatory = true; state = DataTreeState.createInitial(rootNode); if (schemaContext != null) { - setSchemaContext(schemaContext); + setEffectiveModelContext(schemaContext); } } InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration treeConfig, - final SchemaContext schemaContext, final DataSchemaNode rootSchemaNode, final boolean maskMandatory) { + final EffectiveModelContext schemaContext, final DataSchemaNode rootSchemaNode, + final boolean maskMandatory) { this.treeConfig = requireNonNull(treeConfig, "treeConfig"); this.maskMandatory = maskMandatory; @@ -77,24 +76,22 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree { } private ModificationApplyOperation getOperation(final DataSchemaNode rootSchemaNode) { - if (rootSchemaNode instanceof ContainerSchemaNode && maskMandatory) { - return new ContainerModificationStrategy((ContainerSchemaNode) rootSchemaNode, treeConfig); + if (rootSchemaNode instanceof ContainerLike && maskMandatory) { + return new ContainerModificationStrategy((ContainerLike) rootSchemaNode, treeConfig); } if (rootSchemaNode instanceof ListSchemaNode) { final PathArgument arg = treeConfig.getRootPath().getLastPathArgument(); if (arg instanceof NodeIdentifierWithPredicates) { - return maskMandatory ? new ListEntryModificationStrategy((ListSchemaNode) rootSchemaNode, treeConfig) - : ListEntryModificationStrategy.of((ListSchemaNode) rootSchemaNode, treeConfig); + return maskMandatory ? new MapEntryModificationStrategy((ListSchemaNode) rootSchemaNode, treeConfig) + : MapEntryModificationStrategy.of((ListSchemaNode) rootSchemaNode, treeConfig); } } - return SchemaAwareApplyOperation.from(rootSchemaNode, treeConfig); - } - - @Deprecated - @Override - public void setSchemaContext(final SchemaContext newSchemaContext) { - internalSetSchemaContext(newSchemaContext); + try { + return SchemaAwareApplyOperation.from(rootSchemaNode, treeConfig); + } catch (ExcludedDataSchemaNodeException e) { + throw new IllegalArgumentException("Root node does not belong current data tree", e); + } } @Override @@ -106,7 +103,7 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree { * This method is synchronized to guard against user attempting to install * multiple contexts. Otherwise it runs in a lock-free manner. */ - private synchronized void internalSetSchemaContext(final SchemaContext newSchemaContext) { + private synchronized void internalSetSchemaContext(final EffectiveModelContext newSchemaContext) { requireNonNull(newSchemaContext); LOG.debug("Following schema contexts will be attempted {}", newSchemaContext); @@ -144,10 +141,11 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree { if (candidate instanceof NoopDataTreeCandidate) { return; } - checkArgument(candidate instanceof InMemoryDataTreeCandidate, "Invalid candidate class %s", - candidate.getClass()); - final InMemoryDataTreeCandidate c = (InMemoryDataTreeCandidate)candidate; + if (!(candidate instanceof InMemoryDataTreeCandidate)) { + throw new IllegalArgumentException("Invalid candidate class " + candidate.getClass()); + } + final InMemoryDataTreeCandidate c = (InMemoryDataTreeCandidate)candidate; if (LOG.isTraceEnabled()) { LOG.trace("Data Tree is {}", NormalizedNodes.toStringTree(c.getTipRoot().getData())); }