*/
package org.opendaylight.netconf.sal.rest.impl;
-import com.google.common.base.Optional;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.OutputStream;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import javax.xml.stream.XMLStreamException;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.sal.rest.api.Draft02;
import org.opendaylight.netconf.sal.rest.api.RestconfNormalizedNodeWriter;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
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;
*/
@Deprecated
@Provider
-@Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON,
- Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON })
+@Produces({
+ Draft02.MediaTypes.API + RestconfService.JSON,
+ Draft02.MediaTypes.DATA + RestconfService.JSON,
+ Draft02.MediaTypes.OPERATION + RestconfService.JSON,
+ MediaType.APPLICATION_JSON
+})
public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<NormalizedNodeContext> {
private static final int DEFAULT_INDENT_SPACES_NUM = 2;
try (JsonWriter jsonWriter = createJsonWriter(entityStream, context.getWriterParameters().isPrettyPrint())) {
jsonWriter.beginObject();
writeNormalizedNode(
- jsonWriter, path, identifierCtx, data,
- Optional.fromNullable(context.getWriterParameters().getDepth()));
+ jsonWriter, path, identifierCtx, data, context.getWriterParameters().getDepth());
jsonWriter.endObject();
jsonWriter.flush();
}
private static void writeNormalizedNode(final JsonWriter jsonWriter, SchemaPath path,
final InstanceIdentifierContext<SchemaNode> context, NormalizedNode<?, ?> data,
- final Optional<Integer> depth) throws IOException {
+ final @Nullable Integer depth) throws IOException {
final RestconfNormalizedNodeWriter nnWriter;
if (SchemaPath.ROOT.equals(path)) {
/*
nnWriter = createNormalizedNodeWriter(context,path,jsonWriter, depth);
if (data instanceof ContainerNode) {
writeChildren(nnWriter,(ContainerNode) data);
- } else if (data instanceof AnyXmlNode) {
+ } else if (data instanceof DOMSourceAnyxmlNode) {
try {
writeChildren(nnWriter,
(ContainerNode) NetconfUtil.transformDOMSourceToNormalizedNode(
- context.getSchemaContext(), ((AnyXmlNode)data).getValue()).getResult());
+ context.getSchemaContext(), ((DOMSourceAnyxmlNode)data).getValue()).getResult());
} catch (XMLStreamException | URISyntaxException | SAXException e) {
- throw new RuntimeException(e);
+ throw new IOException("Cannot write anyxml.", e);
}
}
} else if (context.getSchemaNode() instanceof RpcDefinition) {
private static RestconfNormalizedNodeWriter createNormalizedNodeWriter(
final InstanceIdentifierContext<SchemaNode> context, final SchemaPath path, final JsonWriter jsonWriter,
- final Optional<Integer> depth) {
+ final @Nullable Integer depth) {
final SchemaNode schema = context.getSchemaNode();
final JSONCodecFactory codecs = getCodecFactory(context);
final URI initialNs;
if (schema instanceof DataSchemaNode && !((DataSchemaNode)schema).isAugmenting()
- && !(schema instanceof SchemaContext)) {
- initialNs = schema.getQName().getNamespace();
- } else if (schema instanceof RpcDefinition) {
+ && !(schema instanceof SchemaContext) || schema instanceof RpcDefinition) {
initialNs = schema.getQName().getNamespace();
} else {
initialNs = null;
}
final NormalizedNodeStreamWriter streamWriter =
JSONNormalizedNodeStreamWriter.createNestedWriter(codecs, path, initialNs, jsonWriter);
- if (depth.isPresent()) {
- return DepthAwareNormalizedNodeWriter.forStreamWriter(streamWriter, depth.get());
+ if (depth != null) {
+ return DepthAwareNormalizedNodeWriter.forStreamWriter(streamWriter, depth);
}
return RestconfDelegatingNormalizedNodeWriter.forStreamWriter(streamWriter);