Handle empty type in NormalizedNode streaming
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / NormalizedNodeInputStreamReader.java
old mode 100644 (file)
new mode 100755 (executable)
index 4cc63d0..cc74443
@@ -27,6 +27,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -74,16 +75,6 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
     private boolean readSignatureMarker = true;
 
-    /**
-     * Constructs an instance.
-     *
-     * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead.
-     */
-    @Deprecated
-    public NormalizedNodeInputStreamReader(final DataInput input) {
-        this(input, false);
-    }
-
     NormalizedNodeInputStreamReader(final DataInput input, final boolean versionChecked) {
         this.input = Preconditions.checkNotNull(input);
         readSignatureMarker = !versionChecked;
@@ -118,6 +109,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
         if (nodeType == NodeTypes.END_NODE) {
             LOG.trace("End node reached. return");
+            lastLeafSetQName = null;
             return null;
         }
 
@@ -270,7 +262,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
             return codedStringMap.get(input.readInt());
         } else if (valueType == TokenTypes.IS_STRING_VALUE) {
             String value = input.readUTF().intern();
-            codedStringMap.put(Integer.valueOf(codedStringMap.size()), value);
+            codedStringMap.put(codedStringMap.size(), value);
             return value;
         }
 
@@ -305,22 +297,22 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
                 return readObjSet();
 
             case ValueTypes.BOOL_TYPE :
-                return Boolean.valueOf(input.readBoolean());
+                return input.readBoolean();
 
             case ValueTypes.BYTE_TYPE :
-                return Byte.valueOf(input.readByte());
+                return input.readByte();
 
             case ValueTypes.INT_TYPE :
-                return Integer.valueOf(input.readInt());
+                return input.readInt();
 
             case ValueTypes.LONG_TYPE :
-                return Long.valueOf(input.readLong());
+                return input.readLong();
 
             case ValueTypes.QNAME_TYPE :
                 return readQName();
 
             case ValueTypes.SHORT_TYPE :
-                return Short.valueOf(input.readShort());
+                return input.readShort();
 
             case ValueTypes.STRING_TYPE :
                 return input.readUTF();
@@ -342,6 +334,15 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
             case ValueTypes.YANG_IDENTIFIER_TYPE :
                 return readYangInstanceIdentifierInternal();
 
+            case ValueTypes.EMPTY_TYPE:
+            // Leaf nodes no longer allow null values and thus we no longer emit null values. Previously, the "empty"
+            // yang type was represented as null so we translate an incoming null value to Empty. It was possible for
+            // a BI user to set a string leaf to null and we're rolling the dice here but the chances for that are
+            // very low. We'd have to know the yang type but, even if we did, we can't let a null value pass upstream
+            // so we'd have to drop the leaf which might cause other issues.
+            case ValueTypes.NULL_TYPE:
+                return Empty.getInstance();
+
             default :
                 return null;
         }