Search in sources :

Example 1 with MountPointChild

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointChild in project yangtools by opendaylight.

the class AbstractDynamicMountPointContextFactory method createContext.

@Override
public final MountPointContext createContext(final Map<ContainerName, MountPointChild> libraryContainers, final MountPointChild schemaMounts) throws YangParserException {
    for (Entry<ContainerName, MountPointChild> entry : libraryContainers.entrySet()) {
        // Context for the specific code word
        final Optional<EffectiveModelContext> optLibContext = findSchemaForLibrary(entry.getKey());
        if (optLibContext.isEmpty()) {
            LOG.debug("YANG Library context for mount point {} container {} not found", getIdentifier(), entry.getKey());
            continue;
        }
        final NormalizedNode libData;
        try {
            libData = entry.getValue().normalizeTo(optLibContext.get());
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret yang-library data", e);
        }
        if (!(libData instanceof ContainerNode)) {
            throw new YangParserException("Invalid yang-library non-container " + libData);
        }
        final EffectiveModelContext schemaContext = bindLibrary(entry.getKey(), (ContainerNode) libData);
        if (schemaMounts == null) {
            return new EmptyMountPointContext(schemaContext);
        }
        final NormalizedNode mountData;
        try {
            mountData = schemaMounts.normalizeTo(schemaContext);
        } catch (IOException e) {
            throw new YangParserException("Failed to interpret schema-mount data", e);
        }
        if (!(mountData instanceof ContainerNode)) {
            throw new YangParserException("Invalid schema-mount non-container " + mountData);
        }
        return createMountPointContext(schemaContext, (ContainerNode) mountData);
    }
    throw new YangParserException("Failed to interpret " + libraryContainers);
}
Also used : ContainerName(org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName) MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 2 with MountPointChild

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointChild in project yangtools by opendaylight.

the class MountPointData method setContainer.

public void setContainer(@NonNull final ContainerName containerName, @NonNull final MountPointChild data) {
    final MountPointChild prev = yangLib.putIfAbsent(containerName, requireNonNull(data));
    checkState(prev == null, "Attempted to duplicate container %s data %s with %s", containerName, prev, data);
    addChild(data);
}
Also used : MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild)

Example 3 with MountPointChild

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointChild in project yangtools by opendaylight.

the class MountPointData method write.

void write(@NonNull final NormalizedNodeStreamWriter writer) throws IOException {
    final StreamWriterMountPointExtension mountWriter = writer.getExtensions().getInstance(StreamWriterMountPointExtension.class);
    if (mountWriter == null) {
        LOG.debug("Writer {} does not support mount points, ignoring data in {}", writer, getIdentifier());
        return;
    }
    final MountPointContext mountCtx;
    try {
        mountCtx = contextFactory.createContext(yangLib, schemaMounts);
    } catch (YangParserException e) {
        throw new IOException("Failed to resolve mount point " + getIdentifier(), e);
    }
    try (NormalizedNodeStreamWriter nestedWriter = mountWriter.startMountPoint(getIdentifier(), mountCtx)) {
        for (MountPointChild child : children) {
            child.writeTo(nestedWriter, mountCtx);
        }
    }
}
Also used : NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) MountPointChild(org.opendaylight.yangtools.rfc8528.data.api.MountPointChild) IOException(java.io.IOException) StreamWriterMountPointExtension(org.opendaylight.yangtools.rfc8528.data.api.StreamWriterMountPointExtension) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException)

Aggregations

MountPointChild (org.opendaylight.yangtools.rfc8528.data.api.MountPointChild)3 IOException (java.io.IOException)2 YangParserException (org.opendaylight.yangtools.yang.parser.api.YangParserException)2 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)1 StreamWriterMountPointExtension (org.opendaylight.yangtools.rfc8528.data.api.StreamWriterMountPointExtension)1 ContainerName (org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1