import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
import org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException;
import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
- final Object childNode = ((DataContainerNode) result).body().iterator().next();
+ final var childNode = ((DataContainerNode) result).body().iterator().next();
if (isPost) {
iiToDataList.add(result.getIdentifier());
}
- result = (NormalizedNode) childNode;
+ result = childNode;
}
if (isPost) {
iiToDataList.add(new NodeIdentifier(result.getIdentifier().getNodeType()));
iiToDataList.add(result.getIdentifier());
} else {
- final List<? extends @NonNull EffectiveStatement<?, ?>> parentPath = parentSchema.statementPath();
+ final var parentPath = parentSchema.statementPath();
if (parentPath.isEmpty() || !(parentPath.get(parentPath.size() - 1) instanceof OperationDefinition)) {
iiToDataList.add(result.getIdentifier());
}
}
- } else {
- if (result instanceof MapNode) {
- result = Iterables.getOnlyElement(((MapNode) result).body());
- }
+ } else if (result instanceof MapNode map) {
+ result = Iterables.getOnlyElement(map.body());
}
// FIXME: can result really be null?
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
final NormalizedNode data, final DepthParam depth, final List<Set<QName>> fields) throws IOException {
final SchemaNode schemaNode = context.getSchemaNode();
final RestconfNormalizedNodeWriter nnWriter;
- if (schemaNode instanceof RpcDefinition) {
- final var rpc = (RpcDefinition) schemaNode;
+ if (schemaNode instanceof RpcDefinition rpc) {
final var stack = SchemaInferenceStack.of(context.getSchemaContext());
stack.enterSchemaTree(rpc.getQName());
stack.enterSchemaTree(rpc.getOutput().getQName());
- /*
- * RpcDefinition is not supported as initial codec in JSONStreamWriter,
- * so we need to emit initial output declaration..
- */
+ // RpcDefinition is not supported as initial codec in JSONStreamWriter, so we need to emit initial output
+ // declaration
nnWriter = createNormalizedNodeWriter(
context,
stack.toInference(),
jsonWriter.beginObject();
writeChildren(nnWriter, (ContainerNode) data);
jsonWriter.endObject();
- } else if (schemaNode instanceof ActionDefinition) {
- /*
- * ActionDefinition is not supported as initial codec in JSONStreamWriter,
- * so we need to emit initial output declaration..
- */
- final var action = (ActionDefinition) schemaNode;
+ } else if (schemaNode instanceof ActionDefinition action) {
+ // ActionDefinition is not supported as initial codec in JSONStreamWriter, so we need to emit initial output
+ // declaration
final var stack = context.inference().toSchemaInferenceStack();
stack.enterSchemaTree(action.getOutput().getQName());
}
nnWriter = createNormalizedNodeWriter(context, stack.toInference(), jsonWriter, depth, fields);
- if (data instanceof MapEntryNode) {
+ if (data instanceof MapEntryNode mapEntry) {
// Restconf allows returning one list item. We need to wrap it
// in map node in order to serialize it properly
nnWriter.write(ImmutableNodes.mapNodeBuilder(data.getIdentifier().getNodeType())
- .withChild((MapEntryNode) data)
+ .withChild(mapEntry)
.build());
} else {
nnWriter.write(data);
private static void writeChildren(final RestconfNormalizedNodeWriter nnWriter, final ContainerNode data)
throws IOException {
- for (final DataContainerChild child : data.body()) {
+ for (var child : data.body()) {
nnWriter.write(child);
}
}
DataSchemaNode schemaNode;
final List<PathArgument> iiToDataList = new ArrayList<>();
Inference inference;
- if (schemaNodeContext instanceof OperationDefinition) {
- schemaNode = ((OperationDefinition) schemaNodeContext).getInput();
+ if (schemaNodeContext instanceof OperationDefinition oper) {
+ schemaNode = oper.getInput();
final var stack = pathContext.inference().toSchemaInferenceStack();
stack.enterSchemaTree(schemaNode.getQName());
inference = stack.toInference();
- } else if (schemaNodeContext instanceof DataSchemaNode) {
- schemaNode = (DataSchemaNode) schemaNodeContext;
+ } else if (schemaNodeContext instanceof DataSchemaNode data) {
+ schemaNode = data;
final String docRootElm = doc.getDocumentElement().getLocalName();
final XMLNamespace docRootNamespace = XMLNamespace.of(doc.getDocumentElement().getNamespaceURI());
// the new XML parser always returns a MapNode with one MapEntryNode inside.
// However, the old XML parser returned a MapEntryNode directly in this place.
// Therefore we now have to extract the MapEntryNode from the parsed MapNode.
- if (parsed instanceof MapNode) {
- final MapNode mapNode = (MapNode) parsed;
+ if (parsed instanceof MapNode mapNode) {
// extracting the MapEntryNode
parsed = mapNode.body().iterator().next();
}
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import javanet.staxutils.IndentingXMLStreamWriter;
import javax.ws.rs.Produces;
return;
}
if (httpHeaders != null) {
- for (final Map.Entry<String, Object> entry : context.getNewHeaders().entrySet()) {
+ for (var entry : context.getNewHeaders().entrySet()) {
httpHeaders.add(entry.getKey(), entry.getValue());
}
}
final RestconfNormalizedNodeWriter nnWriter;
final SchemaNode schemaNode = pathContext.getSchemaNode();
- if (schemaNode instanceof RpcDefinition) {
+ if (schemaNode instanceof RpcDefinition rpc) {
// RpcDefinition is not supported as initial codec in XMLStreamWriter, so we need to emit initial output
// declaration.
- final var rpc = (RpcDefinition) schemaNode;
final var stack = SchemaInferenceStack.of(pathContext.getSchemaContext());
stack.enterSchemaTree(rpc.getQName());
stack.enterSchemaTree(rpc.getOutput().getQName());
nnWriter = createNormalizedNodeWriter(xmlWriter, stack.toInference(), depth, fields);
writeElements(xmlWriter, nnWriter, (ContainerNode) data);
- } else if (schemaNode instanceof ActionDefinition) {
+ } else if (schemaNode instanceof ActionDefinition action) {
// ActionDefinition is not supported as initial codec in XMLStreamWriter, so we need to emit initial output
// declaration.
- final var action = (ActionDefinition) schemaNode;
final var stack = pathContext.inference().toSchemaInferenceStack();
stack.enterSchemaTree(action.getOutput().getQName());
}
nnWriter = createNormalizedNodeWriter(xmlWriter, stack.toInference(), depth, fields);
- if (data instanceof MapEntryNode) {
+ if (data instanceof MapEntryNode mapEntry) {
// Restconf allows returning one list item. We need to wrap it
// in map node in order to serialize it properly
nnWriter.write(ImmutableNodes.mapNodeBuilder(data.getIdentifier().getNodeType())
- .addChild((MapEntryNode) data)
+ .addChild(mapEntry)
.build());
} else if (isRoot) {
- if (data instanceof ContainerNode && ((ContainerNode) data).isEmpty()) {
- writeEmptyDataNode(xmlWriter, data);
+ if (data instanceof ContainerNode container && container.isEmpty()) {
+ writeEmptyDataNode(xmlWriter, container);
} else {
writeAndWrapInDataNode(xmlWriter, nnWriter, data);
}
}
}
- private static void writeEmptyDataNode(final XMLStreamWriter xmlWriter, final NormalizedNode data)
+ private static void writeEmptyDataNode(final XMLStreamWriter xmlWriter, final ContainerNode data)
throws IOException {
final QName nodeType = data.getIdentifier().getNodeType();
final String namespace = nodeType.getNamespace().toString();
try {
xmlWriter.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, nodeType.getLocalName(), namespace);
xmlWriter.writeDefaultNamespace(namespace);
- for (final NormalizedNode child : data.body()) {
+ for (var child : data.body()) {
nnWriter.write(child);
}
nnWriter.flush();