Search in sources :

Example 41 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project mdsal by opendaylight.

the class DataObjectStreamerGenerator method generateStreamer.

static Class<? extends DataObjectStreamer<?>> generateStreamer(final CodecClassLoader loader, final CodecContextFactory registry, final Class<?> type) {
    final var typeAndSchema = registry.getRuntimeContext().getTypeWithSchema(type);
    final var schema = typeAndSchema.statement();
    final StackManipulation startEvent;
    if (schema instanceof ContainerLike || schema instanceof NotificationDefinition) {
        startEvent = classUnknownSizeMethod(START_CONTAINER_NODE, type);
    } else if (schema instanceof ListSchemaNode) {
        startEvent = ((ListSchemaNode) schema).getKeyDefinition().isEmpty() ? START_UNKEYED_LIST_ITEM : START_MAP_ENTRY_NODE;
    } else if (schema instanceof AugmentationSchemaNode) {
        // startAugmentationNode(Foo.class)
        startEvent = new StackManipulation.Compound(ClassConstant.of(Sort.describe(type).asErasure()), START_AUGMENTATION_NODE);
    } else if (schema instanceof CaseSchemaNode) {
        startEvent = classUnknownSizeMethod(START_CASE, type);
    } else {
        throw new UnsupportedOperationException("Schema type " + schema.getClass() + " is not supported");
    }
    return loader.generateClass(type, "streamer", // FIXME: cast to GeneratedType: we really should adjust getTypeWithSchema()
    new DataObjectStreamerGenerator<>(registry, (GeneratedType) typeAndSchema.javaType(), (DataNodeContainer) schema, type, startEvent));
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer)

Aggregations

DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)41 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)15 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)14 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)12 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)11 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)10 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)9 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)9 ArrayList (java.util.ArrayList)7 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)7 RestConfModule (org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Test (org.junit.Test)5 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)5 Module (org.opendaylight.yangtools.yang.model.api.Module)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayDeque (java.util.ArrayDeque)3