Skip to content

Commit

Permalink
Rename DataSchemaContextNode to DataSchemaContext
Browse files Browse the repository at this point in the history
Drop the 'Node' suffix, as it quite overloaded.

JIRA: YANGTOOLS-1413
Change-Id: I68931049b215239bca1a3382c879200a3e801c4b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
  • Loading branch information
rovarga committed May 21, 2023
1 parent 2c1ebba commit 90dd70f
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.common.base.MoreObjects;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
Expand All @@ -21,7 +20,6 @@
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.ContainerLike;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
Expand Down Expand Up @@ -76,14 +74,14 @@ public InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration tre
}

private ModificationApplyOperation getOperation(final DataSchemaNode rootSchemaNode) {
if (rootSchemaNode instanceof ContainerLike && maskMandatory) {
return new ContainerModificationStrategy((ContainerLike) rootSchemaNode, treeConfig);
if (rootSchemaNode instanceof ContainerLike rootContainerLike && maskMandatory) {
return new ContainerModificationStrategy(rootContainerLike, treeConfig);
}
if (rootSchemaNode instanceof ListSchemaNode) {
if (rootSchemaNode instanceof ListSchemaNode rootList) {
final PathArgument arg = treeConfig.getRootPath().getLastPathArgument();
if (arg instanceof NodeIdentifierWithPredicates) {
return maskMandatory ? new MapEntryModificationStrategy((ListSchemaNode) rootSchemaNode, treeConfig)
: MapEntryModificationStrategy.of((ListSchemaNode) rootSchemaNode, treeConfig);
return maskMandatory ? new MapEntryModificationStrategy(rootList, treeConfig)
: MapEntryModificationStrategy.of(rootList, treeConfig);
}
}

Expand All @@ -108,20 +106,20 @@ private synchronized void internalSetSchemaContext(final EffectiveModelContext n

LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);

final DataSchemaContextTree contextTree = DataSchemaContextTree.from(newSchemaContext);
final Optional<DataSchemaContextNode> rootContextNode = contextTree.findChild(getRootPath());
final var contextTree = DataSchemaContextTree.from(newSchemaContext);
final var rootContextNode = contextTree.findChild(getRootPath());
if (!rootContextNode.isPresent()) {
LOG.warn("Could not find root {} in new schema context, not upgrading", getRootPath());
return;
}

final DataSchemaNode rootSchemaNode = rootContextNode.orElseThrow().getDataSchemaNode();
final var rootSchemaNode = rootContextNode.orElseThrow().dataSchemaNode();
if (!(rootSchemaNode instanceof DataNodeContainer)) {
LOG.warn("Root {} resolves to non-container type {}, not upgrading", getRootPath(), rootSchemaNode);
return;
}

final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
final var rootNode = getOperation(rootSchemaNode);
DataTreeState currentState;
DataTreeState newState;
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static com.google.common.base.Preconditions.checkArgument;

import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.NonNull;
Expand All @@ -31,7 +30,6 @@
import org.opendaylight.yangtools.yang.data.tree.impl.InMemoryDataTree;
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.ContainerLike;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
Expand Down Expand Up @@ -155,11 +153,11 @@ void deactivate() {

private static DataSchemaNode getRootSchemaNode(final EffectiveModelContext schemaContext,
final YangInstanceIdentifier rootPath) {
final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
final Optional<DataSchemaContextNode> rootContextNode = contextTree.findChild(rootPath);
final var contextTree = DataSchemaContextTree.from(schemaContext);
final var rootContextNode = contextTree.findChild(rootPath);
checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);

final DataSchemaNode rootSchemaNode = rootContextNode.orElseThrow().getDataSchemaNode();
final var rootSchemaNode = rootContextNode.orElseThrow().dataSchemaNode();
checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s",
rootPath, rootSchemaNode);
return rootSchemaNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.codec.InstanceIdentifierCodec;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode.Composite;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode.PathMixin;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.Composite;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.PathMixin;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;

Expand All @@ -46,7 +46,7 @@ public abstract class AbstractStringInstanceIdentifierCodec extends AbstractName
@Override
protected final String serializeImpl(final YangInstanceIdentifier data) {
final StringBuilder sb = new StringBuilder();
DataSchemaContextNode current = getDataContextTree().getRoot();
DataSchemaContext current = getDataContextTree().getRoot();
QNameModule lastModule = null;
for (var arg : data.getPathArguments()) {
current = current instanceof Composite composite ? composite.childByArg(arg) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode.Composite;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode.SimpleValue;
import org.opendaylight.yangtools.yang.data.util.impl.model.AbstractCompositeContextNode;
import org.opendaylight.yangtools.yang.data.util.impl.model.AbstractDataSchemaContextNode;
import org.opendaylight.yangtools.yang.data.util.impl.model.AbstractMixinContextNode;
import org.opendaylight.yangtools.yang.data.util.impl.model.LeafContextNode;
import org.opendaylight.yangtools.yang.data.util.impl.model.LeafListItemContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.Composite;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.SimpleValue;
import org.opendaylight.yangtools.yang.data.util.impl.context.AbstractCompositeContext;
import org.opendaylight.yangtools.yang.data.util.impl.context.AbstractContext;
import org.opendaylight.yangtools.yang.data.util.impl.context.AbstractPathMixinContext;
import org.opendaylight.yangtools.yang.data.util.impl.context.LeafContext;
import org.opendaylight.yangtools.yang.data.util.impl.context.LeafListItemContext;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
Expand All @@ -38,19 +38,19 @@
* {@link org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode} and serialization format defined in RFC6020,
* since the mapping is not one-to-one.
*/
public sealed interface DataSchemaContextNode permits AbstractDataSchemaContextNode, Composite, SimpleValue {
public sealed interface DataSchemaContext permits AbstractContext, Composite, SimpleValue {
/**
* A {@link DataSchemaContextNode} containing other {@link DataSchemaContextNode}s.
* A {@link DataSchemaContext} containing other {@link DataSchemaContext}s.
*/
sealed interface Composite extends DataSchemaContextNode permits PathMixin, AbstractCompositeContextNode {
sealed interface Composite extends DataSchemaContext permits PathMixin, AbstractCompositeContext {
/**
* Find a child node identifier by its {@link PathArgument}.
*
* @param arg Child path argument
* @return A child node, or {@code null} if not found
* @throws NullPointerException if {@code arg} is {@code null}
*/
@Nullable DataSchemaContextNode childByArg(PathArgument arg);
@Nullable DataSchemaContext childByArg(PathArgument arg);

/**
* Find a child node identifier by its {code data tree} {@link QName}. This method returns intermediate nodes
Expand All @@ -63,7 +63,7 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
* @return A child node, or {@code null} if not found
* @throws NullPointerException if {@code arg} is {@code null}
*/
@Nullable DataSchemaContextNode childByQName(QName qname);
@Nullable DataSchemaContext childByQName(QName qname);

/**
* Find a child node as identified by a {@link YangInstanceIdentifier} relative to this node.
Expand All @@ -72,7 +72,7 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
* @return Child node if present, or empty when corresponding child is not found.
* @throws NullPointerException if {@code path} is {@code null}
*/
default @Nullable DataSchemaContextNode childByPath(final @NonNull YangInstanceIdentifier path) {
default @Nullable DataSchemaContext childByPath(final @NonNull YangInstanceIdentifier path) {
final var it = path.getPathArguments().iterator();
if (!it.hasNext()) {
return this;
Expand All @@ -92,7 +92,7 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
}

/**
* Attempt to enter a child {@link DataSchemaContextNode} towards the {@link DataSchemaNode} child identified by
* Attempt to enter a child {@link DataSchemaContext} towards the {@link DataSchemaNode} child identified by
* specified {@code data tree} {@link QName}, adjusting provided {@code stack} with inference steps
* corresponding to the transition to the returned node. The stack is expected to be correctly pointing at this
* node's schema, otherwise the results of this method are undefined.
Expand All @@ -102,10 +102,10 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
* @return A DataSchemaContextNode on the path towards the specified child
* @throws NullPointerException if any argument is {@code null}
*/
@Nullable DataSchemaContextNode enterChild(SchemaInferenceStack stack, QName child);
@Nullable DataSchemaContext enterChild(SchemaInferenceStack stack, QName child);

/**
* Attempt to enter a child {@link DataSchemaContextNode} towards the {@link DataSchemaNode} child identified by
* Attempt to enter a child {@link DataSchemaContext} towards the {@link DataSchemaNode} child identified by
* specified {@link PathArgument}, adjusting provided {@code stack} with inference steps corresponding to
* the transition to the returned node. The stack is expected to be correctly pointing at this node's schema,
* otherwise the results of this method are undefined.
Expand All @@ -115,7 +115,7 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
* @return A DataSchemaContextNode for the specified child
* @throws NullPointerException if any argument is {@code null}
*/
@Nullable DataSchemaContextNode enterChild(SchemaInferenceStack stack, PathArgument child);
@Nullable DataSchemaContext enterChild(SchemaInferenceStack stack, PathArgument child);
}

/**
Expand All @@ -133,7 +133,7 @@ sealed interface Composite extends DataSchemaContextNode permits PathMixin, Abst
* <p>
* This trait is important for XML codec, but also for JSON encoding of {@link YangInstanceIdentifier}.
*/
sealed interface PathMixin extends Composite permits AbstractMixinContextNode {
sealed interface PathMixin extends Composite permits AbstractPathMixinContext {
/**
* The mixed-in {@link NodeIdentifier}.
*
Expand All @@ -147,11 +147,11 @@ sealed interface PathMixin extends Composite permits AbstractMixinContextNode {
/**
* Marker interface for contexts which boil down to a simple, not-structured value. The
*/
sealed interface SimpleValue extends DataSchemaContextNode permits LeafContextNode, LeafListItemContextNode {
sealed interface SimpleValue extends DataSchemaContext permits LeafContext, LeafListItemContext {
// Marker interface
}

@NonNull DataSchemaNode getDataSchemaNode();
@NonNull DataSchemaNode dataSchemaNode();

/**
* Return the fixed {@link YangInstanceIdentifier} step, if available. This method returns {@code null} for contexts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.opendaylight.yangtools.concepts.CheckedValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode.Composite;
import org.opendaylight.yangtools.yang.data.util.impl.model.ContainerContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.Composite;
import org.opendaylight.yangtools.yang.data.util.impl.context.ContainerContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
Expand All @@ -28,8 +28,8 @@
* schema and data has differences, the mapping is not trivial -- which is where this class comes in.
*/
public final class DataSchemaContextTree extends AbstractEffectiveModelContextProvider {
public record NodeAndStack(@NonNull DataSchemaContextNode node, @NonNull SchemaInferenceStack stack) {
public NodeAndStack(final @NonNull DataSchemaContextNode node, final @NonNull SchemaInferenceStack stack) {
public record NodeAndStack(@NonNull DataSchemaContext node, @NonNull SchemaInferenceStack stack) {
public NodeAndStack(final @NonNull DataSchemaContext node, final @NonNull SchemaInferenceStack stack) {
this.node = requireNonNull(node);
this.stack = requireNonNull(stack);
}
Expand All @@ -43,11 +43,11 @@ public DataSchemaContextTree load(final EffectiveModelContext key) {
}
});

private final @NonNull ContainerContextNode root;
private final @NonNull ContainerContext root;

private DataSchemaContextTree(final EffectiveModelContext ctx) {
super(ctx);
root = new ContainerContextNode(ctx);
root = new ContainerContext(ctx);
}

public static @NonNull DataSchemaContextTree from(final @NonNull EffectiveModelContext ctx) {
Expand All @@ -61,7 +61,7 @@ private DataSchemaContextTree(final EffectiveModelContext ctx) {
* @return Child node if present, or empty when corresponding child is not found.
* @throws NullPointerException if {@code path} is null
*/
public @NonNull Optional<@NonNull DataSchemaContextNode> findChild(final @NonNull YangInstanceIdentifier path) {
public @NonNull Optional<@NonNull DataSchemaContext> findChild(final @NonNull YangInstanceIdentifier path) {
// Optional.ofNullable() inline due to annotations
final var child = root.childByPath(path);
return child == null ? Optional.empty() : Optional.of(child);
Expand All @@ -77,8 +77,8 @@ private DataSchemaContextTree(final EffectiveModelContext ctx) {
*/
public @NonNull CheckedValue<@NonNull NodeAndStack, @NonNull IllegalArgumentException> enterPath(
final YangInstanceIdentifier path) {
final var stack = SchemaInferenceStack.of((EffectiveModelContext) root.getDataSchemaNode());
DataSchemaContextNode node = root;
final var stack = SchemaInferenceStack.of((EffectiveModelContext) root.dataSchemaNode());
DataSchemaContext node = root;
for (var arg : path.getPathArguments()) {
final var child = node instanceof Composite composite ? composite.enterChild(stack, arg) : null;
if (child == null) {
Expand All @@ -90,7 +90,7 @@ private DataSchemaContextTree(final EffectiveModelContext ctx) {
return CheckedValue.ofValue(new NodeAndStack(node, stack));
}

public DataSchemaContextNode.@NonNull Composite getRoot() {
public DataSchemaContext.@NonNull Composite getRoot() {
return root;
}
}

0 comments on commit 90dd70f

Please sign in to comment.