<artifactId>rfc8528-data-api</artifactId>
<version>3.0.3-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>rfc8528-data-util</artifactId>
+ <version>3.0.3-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>rfc8528-model-api</artifactId>
<!-- RFC8528 (mount-point) metamodel support -->
<module>rfc8528-data-api</module>
+ <module>rfc8528-data-util</module>
<module>rfc8528-model-api</module>
<module>rfc8528-parser-support</module>
</modules>
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A mount point with {@code schema-ref} inline, as defined in RFC8528.
+ */
+@Beta
+@NonNullByDefault
+public interface InlineMountPointNode extends MountPointNode {
+
+}
+++ /dev/null
-/*
- * Copyright (c) 2019 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.rfc8528.data.api;
-
-import com.google.common.annotations.Beta;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchema;
-import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaResolver;
-import org.opendaylight.yangtools.rfc8528.model.api.YangLibraryConstants.ContainerName;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
-
-/**
- * A resolver which can resolve the SchemaContext for use with mount point data based on the
- * {@code ietf-yang-library} content of the mountpoint itself. This process requires two steps:
- * <ul>
- * <li>{@link #findSchemaForLibrary(ContainerName)} is invoked to acquire a SchemaContext in which to interpret
- * one of the possible {@code ietf-yang-library} top-level containers.
- * </li>
- * <li>The container is normalized based on the returned context by the user of this interface and then
- * {@link LibraryContext#bindTo(ContainerNode)} is invoked to acquire the MountPointMetadata.
- * </li>
- * </ul>
- */
-@Beta
-public interface InlineMountPointSchemaResolver extends MountPointSchemaResolver {
- @NonNullByDefault
- interface LibraryContext {
- /**
- * Return a SchemaContext capable of parsing the content of YANG Library.
- *
- * @return A SchemaContext instance
- */
- SchemaContext getLibraryContainerSchema();
-
- /**
- * Assemble the SchemaContext for specified normalized YANG Library top-level container.
- *
- * @param container Top-level YANG Library container
- * @return An assembled SchemaContext
- * @throws NullPointerException if container is null
- * @throws YangParserException if the schema context cannot be assembled
- */
- MountPointSchema bindTo(ContainerNode container) throws YangParserException;
- }
-
- /**
- * Return the schema in which YANG Library container content should be interpreted.
- *
- * <p>
- * Note this schema is not guaranteed to contain any augmentations, hence parsing could fail.
- *
- * @param containerName Top-level YANG Library container name
- * @return The LibraryContext to use when interpreting the specified YANG Library container, or empty
- * @throws NullPointerException if container is null
- */
- Optional<LibraryContext> findSchemaForLibrary(@NonNull ContainerName containerName);
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MixinNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+
+/**
+ * Common NormalizedNode representation of a YANG mount point. This interface is not meant to be implemented directly,
+ * but rather used through its specializations like {@link InlineMountPointNode} and {@link SharedSchemaMountPointNode}.
+ *
+ * <p>
+ * Furthermore, these nodes are not meant to be stored in a {@link DataTree} and most NormalizedNode utilities will be
+ * confused when they see them. The purpose of this interface is making data interchange between mount point-aware
+ * components more seamless.
+ */
+@Beta
+public interface MountPointNode extends SchemaContextProvider, MixinNode, DataContainerNode<MountPointIdentifier>,
+ DataContainerChild<MountPointIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
+ @Override
+ default QName getNodeType() {
+ return getIdentifier().getLabel();
+ }
+
+ @Override
+ // FIXME: remove this override when SchemaContextProvider's method has sane semantics.
+ @NonNull SchemaContext getSchemaContext();
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchema;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+@Beta
+@NonNullByDefault
+public interface MountPointNodeFactory extends MountPointSchema {
+
+ MountPointNode createMountPoint(ContainerNode delegate);
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaResolver;
+import org.opendaylight.yangtools.rfc8528.model.api.StaticMountPointSchemaResolver;
+import org.opendaylight.yangtools.rfc8528.model.api.YangLibraryConstants.ContainerName;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
+
+@Beta
+public interface MountPointNodeFactoryResolver extends MountPointSchemaResolver {
+ /**
+ * A resolver which can resolve the SchemaContext for use with mount point data based on the
+ * {@code ietf-yang-library} content of the mountpoint itself. This process requires two steps:
+ * <ul>
+ * <li>{@link #findSchemaForLibrary(ContainerName)} is invoked to acquire a SchemaContext in which to interpret
+ * one of the possible {@code ietf-yang-library} top-level containers.
+ * </li>
+ * <li>The container is normalized based on the returned context by the user of this interface and then
+ * {@link LibraryContext#bindTo(ContainerNode)} is invoked to acquire the MountPointMetadata.
+ * </li>
+ * </ul>
+ */
+ public interface Inline extends MountPointNodeFactoryResolver {
+ @NonNullByDefault
+ interface LibraryContext {
+ /**
+ * Return a SchemaContext capable of parsing the content of YANG Library.
+ *
+ * @return A SchemaContext instance
+ */
+ SchemaContext getLibraryContainerSchema();
+
+ /**
+ * Assemble the SchemaContext for specified normalized YANG Library top-level container.
+ *
+ * @param container Top-level YANG Library container
+ * @return An assembled SchemaContext
+ * @throws NullPointerException if container is null
+ * @throws YangParserException if the schema context cannot be assembled
+ */
+ MountPointNodeFactory bindTo(ContainerNode container) throws YangParserException;
+ }
+
+ /**
+ * Return the schema in which YANG Library container content should be interpreted.
+ *
+ * <p>
+ * Note this schema is not guaranteed to contain any augmentations, hence parsing could fail.
+ *
+ * @param containerName Top-level YANG Library container name
+ * @return The LibraryContext to use when interpreting the specified YANG Library container, or empty
+ * @throws NullPointerException if container is null
+ */
+ Optional<LibraryContext> findSchemaForLibrary(@NonNull ContainerName containerName);
+ }
+
+ @NonNullByDefault
+ interface SharedSchema extends MountPointNodeFactoryResolver, StaticMountPointSchemaResolver {
+
+ @Override
+ MountPointNodeFactory getSchema();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rfc8528.data.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A mount point with {@code schema-ref} shared-schema, as defined in RFC8528.
+ */
+@Beta
+@NonNullByDefault
+public interface SharedSchemaMountPointNode extends MountPointNode {
+ /*
+ * FIXME: consider whether this interface should contain some information based on 'parent-reference':
+ * - List<YangXPathExpression.QualifiedBound> getParentReference()
+ * - the node-set required to maintain referential integrity in the subtree of this node
+ */
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2019 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
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>bundle-parent</artifactId>
+ <version>3.0.3-SNAPSHOT</version>
+ <relativePath>../../bundle-parent</relativePath>
+ </parent>
+
+ <artifactId>rfc8528-data-util</artifactId>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <description>RFC8528 data model utilities</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>concepts</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>rfc8528-data-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Automatic-Module-Name>org.opendaylight.yangtools.rfc8528.data.util</Automatic-Module-Name>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.github.spotbugs</groupId>
+ <artifactId>spotbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2019 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.rcf8528.data.util;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import java.util.Collection;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.rfc8528.data.api.InlineMountPointNode;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointNode;
+import org.opendaylight.yangtools.rfc8528.data.api.SharedSchemaMountPointNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.util.AbstractIdentifiableSchemaContextProvider;
+
+@Beta
+public abstract class ImmutableMountPointNode<M extends MountPointNode, T extends ImmutableMountPointNode<M, T>>
+ extends AbstractIdentifiableSchemaContextProvider<MountPointIdentifier> implements MountPointNode, Immutable {
+ @NonNullByDefault
+ private static final class Inline extends ImmutableMountPointNode<InlineMountPointNode, Inline>
+ implements InlineMountPointNode {
+
+ Inline(final MountPointIdentifier identifier, final SchemaContext schemaContext, final ContainerNode delegate) {
+ super(identifier, schemaContext, delegate);
+ }
+ }
+
+ @NonNullByDefault
+ private static final class SharedSchema extends ImmutableMountPointNode<SharedSchemaMountPointNode, SharedSchema>
+ implements SharedSchemaMountPointNode {
+
+ SharedSchema(final MountPointIdentifier identifier, final SchemaContext schemaContext,
+ final ContainerNode delegate) {
+ super(identifier, schemaContext, delegate);
+ }
+ }
+
+ private final @NonNull ContainerNode delegate;
+
+ ImmutableMountPointNode(final @NonNull MountPointIdentifier identifier,
+ final @NonNull SchemaContext schemaContext, final @NonNull ContainerNode delegate) {
+ super(schemaContext, identifier);
+ this.delegate = requireNonNull(delegate);
+ }
+
+ public static @NonNull InlineMountPointNode inlineOf(final @NonNull MountPointIdentifier identifier,
+ final @NonNull SchemaContext schemaContext, final @NonNull ContainerNode delegate) {
+ return new Inline(identifier, schemaContext, delegate);
+ }
+
+ public static @NonNull SharedSchemaMountPointNode sharedSchemaOf(final @NonNull MountPointIdentifier identifier,
+ final @NonNull SchemaContext schemaContext, final @NonNull ContainerNode delegate) {
+ return new SharedSchema(identifier, schemaContext, delegate);
+ }
+
+ @Override
+ public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
+ return delegate.getValue();
+ }
+
+ @Override
+ public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
+ return delegate.getChild(child);
+ }
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return super.addToStringAttributes(helper).add("delegate", delegate);
+ }
+}
/**
* An entity able to resolve the SchemaContext for embedded mount points. This interface should not be implemented
- * directly, but rather its domain specializations, like {@link StaticMountpointSchemaResolver} should be provided.
+ * directly, but rather its domain specializations, like {@link StaticMountPointSchemaResolver} should be provided.
*/
@Beta
@NonNullByDefault
*/
@Beta
@NonNullByDefault
-public interface StaticMountpointSchemaResolver extends MountPointSchemaResolver {
+public interface StaticMountPointSchemaResolver extends MountPointSchemaResolver {
MountPointSchema getSchema();
}
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
-import org.opendaylight.yangtools.rfc8528.data.api.InlineMountPointSchemaResolver;
-import org.opendaylight.yangtools.rfc8528.data.api.InlineMountPointSchemaResolver.LibraryContext;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointNodeFactoryResolver.Inline;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointNodeFactoryResolver.Inline.LibraryContext;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointStreamWriter;
import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchema;
import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaResolver;
-import org.opendaylight.yangtools.rfc8528.model.api.StaticMountpointSchemaResolver;
+import org.opendaylight.yangtools.rfc8528.model.api.StaticMountPointSchemaResolver;
import org.opendaylight.yangtools.rfc8528.model.api.YangLibraryConstants.ContainerName;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
}
final MountPointSchemaResolver resolver = optResolver.get();
- if (resolver instanceof StaticMountpointSchemaResolver) {
- writeTo(mountWriter, ((StaticMountpointSchemaResolver) resolver).getSchema());
- } else if (resolver instanceof InlineMountPointSchemaResolver) {
- writeInline(mountWriter, (InlineMountPointSchemaResolver) resolver);
+ if (resolver instanceof StaticMountPointSchemaResolver) {
+ writeTo(mountWriter, ((StaticMountPointSchemaResolver) resolver).getSchema());
+ } else if (resolver instanceof Inline) {
+ writeInline(mountWriter, (Inline) resolver);
} else {
throw new IOException("Unhandled resolver " + resolver);
}
}
- private void writeInline(final @NonNull MountPointStreamWriter mountWriter,
- final InlineMountPointSchemaResolver resolver) throws IOException {
+ private void writeInline(final @NonNull MountPointStreamWriter mountWriter, final Inline resolver)
+ throws IOException {
for (Entry<ContainerName, MountPointChild> entry : yangLib.entrySet()) {
final Optional<LibraryContext> optLibContext = resolver.findSchemaForLibrary(entry.getKey());
if (!optLibContext.isPresent()) {