Search in sources :

Example 11 with ContainerLike

use of org.opendaylight.yangtools.yang.model.api.ContainerLike 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

ContainerLike (org.opendaylight.yangtools.yang.model.api.ContainerLike)11 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)8 QName (org.opendaylight.yangtools.yang.common.QName)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)6 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)5 Module (org.opendaylight.yangtools.yang.model.api.Module)5 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)4 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)4 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)4 DOMSource (javax.xml.transform.dom.DOMSource)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)3 XmlParserStream (org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream)3 ImmutableNormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter)3 NormalizedNodeResult (org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult)3 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)3