import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
+import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableMap;
import java.text.ParseException;
import java.util.ArrayList;
import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-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.api.TypedDataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
private Object prepareValueByType(final SchemaInferenceStack stack, final DataSchemaNode schemaNode,
final @NonNull String value) {
-
- TypeDefinition<? extends TypeDefinition<?>> typedef;
- if (schemaNode instanceof LeafListSchemaNode leafList) {
- typedef = leafList.getType();
- } else {
- typedef = ((LeafSchemaNode) schemaNode).getType();
+ if (schemaNode instanceof TypedDataSchemaNode typedSchema) {
+ return prepareValueByType(stack, typedSchema, typedSchema.getType(), value);
}
- if (typedef instanceof LeafrefTypeDefinition leafref) {
+ throw new VerifyException("Unhandled schema " + schemaNode + " decoding '" + value + "'");
+ }
+
+ private Object prepareValueByType(final SchemaInferenceStack stack, final TypedDataSchemaNode schemaNode,
+ final TypeDefinition<?> unresolved, final @NonNull String value) {
+ // Resolve 'type leafref' before dispatching on type
+ final TypeDefinition<?> typedef;
+ if (unresolved instanceof LeafrefTypeDefinition leafref) {
typedef = stack.resolveLeafref(leafref);
+ } else {
+ typedef = unresolved;
}
+ // Complex types
if (typedef instanceof IdentityrefTypeDefinition) {
return toIdentityrefQName(value, schemaNode);
}
return toInstanceIdentifier(value, schemaNode);
}
+ // Simple types
+ final var codec = verifyNotNull(TypeDefinitionAwareCodec.from(typedef), "Unhandled type %s decoding %s",
+ typedef, value);
try {
- return verifyNotNull(TypeDefinitionAwareCodec.from(typedef),
- "Unhandled type %s decoding %s", typedef, value).deserialize(value);
+ return codec.deserialize(value);
} catch (IllegalArgumentException e) {
throw new RestconfDocumentedException("Invalid value '" + value + "' for " + schemaNode.getQName(),
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, e);
keyValues.get(0)));
}
- private YangInstanceIdentifier toInstanceIdentifier(final String value, final DataSchemaNode schemaNode) {
+ private YangInstanceIdentifier toInstanceIdentifier(final String value, final TypedDataSchemaNode schemaNode) {
if (value.isEmpty() || !value.startsWith("/")) {
throw new RestconfDocumentedException("Invalid value '" + value + "' for " + schemaNode.getQName(),
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
}
- private QName toIdentityrefQName(final String value, final DataSchemaNode schemaNode) {
+ private QName toIdentityrefQName(final String value, final TypedDataSchemaNode schemaNode) {
final QNameModule namespace;
final String localName;
final int firstColon = value.indexOf(':');