Bump MRI upstreams
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / rest / impl / NormalizedNodeJsonBodyWriter.java
index 216d77f068475cee685e47d353879c1380c8e26a..b671833c2510a8b20ace4d48d789542ab6805931 100644 (file)
@@ -7,7 +7,6 @@
  */
 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;
@@ -25,6 +24,7 @@ import javax.ws.rs.core.MultivaluedMap;
 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;
@@ -32,8 +32,8 @@ import org.opendaylight.netconf.util.NetconfUtil;
 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;
@@ -57,8 +57,12 @@ import org.xml.sax.SAXException;
  */
 @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;
@@ -97,8 +101,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
         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();
         }
@@ -106,7 +109,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
 
     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)) {
             /*
@@ -116,13 +119,13 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
             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) {
@@ -157,24 +160,22 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
 
     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);