import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
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.api.schema.ValueNode;
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.data.util.impl.context.AbstractValueContext;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
/**
}
/**
- * Marker interface for contexts which boil down to a simple, not-structured value. The
+ * Marker interface for contexts which boil down to a simple, not-structured {@link ValueNode}. This can be one of
+ * <ul>
+ * <li>{@link LeafNode} backed by a {@link LeafSchemaNode}, or</li>
+ * <li>{@link LeafSetNode} backed by a {@link LeafListSchemaNode}</li>
+ * </ul>
+ *
+ * <p>
+ * This trait interface is exposed for determining that the corresponding {@link TypeDefinition} of the normalized
+ * body.
*/
- sealed interface SimpleValue extends DataSchemaContext permits LeafContext, LeafListItemContext {
- // Marker interface
+ sealed interface SimpleValue extends DataSchemaContext permits AbstractValueContext {
+ /**
+ * Return the {@link TypeDefinition} of the type backing this context.
+ *
+ * @return A {@link TypeDefinition}
+ */
+ // FIXME: YANGTOOLS-1528: return yang.data.api.type.NormalizedType
+ @NonNull TypeDefinition<?> type();
}
/**
* since the mapping is not one-to-one.
*/
public abstract sealed class AbstractContext implements DataSchemaContext
- permits AbstractPathMixinContext, AbstractCompositeContext, LeafContext, LeafListItemContext, OpaqueContext {
+ permits AbstractPathMixinContext, AbstractCompositeContext, AbstractValueContext, OpaqueContext {
private final NodeIdentifier pathStep;
final @NonNull DataSchemaNode dataSchemaNode;
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.util.impl.context;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.SimpleValue;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
+
+public abstract sealed class AbstractValueContext extends AbstractContext implements SimpleValue
+ permits LeafContext, LeafListItemContext {
+ AbstractValueContext(final NodeIdentifier pathStep, final TypedDataSchemaNode dataSchemaNode) {
+ super(pathStep, dataSchemaNode);
+ }
+
+ @Override
+ public final TypeDefinition<?> type() {
+ return ((TypedDataSchemaNode) dataSchemaNode()).getType();
+ }
+}
package org.opendaylight.yangtools.yang.data.util.impl.context;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.SimpleValue;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-public final class LeafContext extends AbstractContext implements SimpleValue {
+public final class LeafContext extends AbstractValueContext {
LeafContext(final LeafSchemaNode schema) {
super(NodeIdentifier.create(schema.getQName()), schema);
}
*/
package org.opendaylight.yangtools.yang.data.util.impl.context;
-import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.SimpleValue;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
-public final class LeafListItemContext extends AbstractContext implements SimpleValue {
+public final class LeafListItemContext extends AbstractValueContext {
LeafListItemContext(final LeafListSchemaNode schema) {
super(null, schema);
}
* type of the base type (YANG <code>type</code> substatement) which
* is included in the instance of this type
*/
-// FIXME: 8.0.0: it seems this construct is mostly used in yang-data-api/codec view of the world. Introduce a dead
-// ringer interface at that layer, which will not have a SchemaNode implication but (perhaps) is backed
-// by a TypedefEffectiveStatement (or TypeEffectiveStatement?)
+// FIXME: YANGTOOLS-1528: this construct is mostly used in yang-data-api/codec view of the world. Introduce a dead
+// ringer interface, yang.data.api.type.NormalizedType and use it in yang-data-* components.
public interface TypeDefinition<T extends TypeDefinition<?>> extends SchemaNode {
/**
* Returns the base type from which this type is derived. If this is yang built-in type, returns null.