2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.legacy;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableMap;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
17 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 * A RFC8040 overlay over {@link NormalizedNodeContext}. This represents a NormalizedNode along with further messy
24 * details needed to deal with the payload.
26 public final class NormalizedNodePayload extends NormalizedNodeContext {
27 private NormalizedNodePayload(final InstanceIdentifierContext<?> context,
28 final NormalizedNode data, final QueryParameters writerParameters,
29 final ImmutableMap<String, Object> headers) {
30 super(context, data, writerParameters, headers);
33 public static @NonNull NormalizedNodePayload empty(final InstanceIdentifierContext<?> path) {
34 return new NormalizedNodePayload(requireNonNull(path), null, QueryParameters.empty(), ImmutableMap.of());
37 public static @NonNull NormalizedNodePayload of(final InstanceIdentifierContext<?> path,
38 final NormalizedNode data) {
39 return new NormalizedNodePayload(requireNonNull(path), requireNonNull(data), QueryParameters.empty(),
43 public static @NonNull NormalizedNodePayload ofNullable(final InstanceIdentifierContext<?> path,
44 final NormalizedNode data) {
45 return data == null ? empty(path) : of(path, data);
48 public static @NonNull NormalizedNodePayload ofLocation(final InstanceIdentifierContext<?> path,
49 final NodeIdentifier leafId, final URI location) {
50 return new NormalizedNodePayload(requireNonNull(path), ImmutableNodes.leafNode(leafId, location.toString()),
51 QueryParameters.empty(), ImmutableMap.of("Location", location));
54 @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Ensured via constructor")
56 public QueryParameters getWriterParameters() {
57 return (QueryParameters) super.getWriterParameters();