Move NetconfMessage into netconf.api.messages
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / NetconfMessageToXMLEncoder.java
index 608f1998296f33a0bbb70b4cdf856d4b3b88d096..8da680040e58342a76de09bf363b72d519abd8a7 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netconf.nettyutil.handler;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufOutputStream;
 import io.netty.channel.ChannelHandlerContext;
@@ -17,10 +16,12 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.StandardCharsets;
+import java.util.Optional;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-import org.opendaylight.netconf.api.NetconfMessage;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Comment;
@@ -28,23 +29,24 @@ import org.w3c.dom.Comment;
 public class NetconfMessageToXMLEncoder extends MessageToByteEncoder<NetconfMessage> {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageToXMLEncoder.class);
 
-    private final Optional<String> clientId;
+    private final @Nullable String clientId;
 
     public NetconfMessageToXMLEncoder() {
-        this(Optional.<String>absent());
+        this(Optional.empty());
     }
 
     public NetconfMessageToXMLEncoder(final Optional<String> clientId) {
-        this.clientId = clientId;
+        this.clientId = clientId.orElse(null);
     }
 
     @Override
     @VisibleForTesting
-    public void encode(final ChannelHandlerContext ctx, final NetconfMessage msg, final ByteBuf out) throws IOException, TransformerException {
+    public void encode(final ChannelHandlerContext ctx, final NetconfMessage msg, final ByteBuf out)
+            throws IOException, TransformerException {
         LOG.trace("Sent to encode : {}", msg);
 
-        if (clientId.isPresent()) {
-            Comment comment = msg.getDocument().createComment("clientId:" + clientId.get());
+        if (clientId != null) {
+            Comment comment = msg.getDocument().createComment("clientId:" + clientId);
             msg.getDocument().appendChild(comment);
         }
 
@@ -53,7 +55,8 @@ public class NetconfMessageToXMLEncoder extends MessageToByteEncoder<NetconfMess
 
             // Using custom BufferedWriter that does not provide newLine method as performance improvement
             // see javadoc for BufferedWriter
-            StreamResult result = new StreamResult(new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)));
+            StreamResult result =
+                    new StreamResult(new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)));
             DOMSource source = new DOMSource(msg.getDocument());
             ThreadLocalTransformers.getPrettyTransformer().transform(source, result);
         }