X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fstream%2FNormalizedNodeInputStreamReader.java;h=2f9403707c79e87a4dc6e12057d14608f85c063d;hb=refs%2Fchanges%2F17%2F78117%2F1;hp=989884cebdfa3d75d159686b92ba1a3cc5927e35;hpb=763995ce31cdaed38be580781df1f5c20edf5225;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java old mode 100644 new mode 100755 index 989884cebd..2f9403707c --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java @@ -10,23 +10,23 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; import java.io.DataInput; import java.io.IOException; import java.io.StringReader; import java.math.BigDecimal; import java.math.BigInteger; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; 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; @@ -108,6 +108,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput if (nodeType == NodeTypes.END_NODE) { LOG.trace("End node reached. return"); + lastLeafSetQName = null; return null; } @@ -212,12 +213,10 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput case NodeTypes.ORDERED_LEAF_SET: LOG.trace("Read ordered leaf set node {}", identifier); - ListNodeBuilder> orderedLeafSetBuilder = - Builders.orderedLeafSetBuilder().withNodeIdentifier(identifier); - orderedLeafSetBuilder = addLeafSetChildren(identifier.getNodeType(), orderedLeafSetBuilder); - return orderedLeafSetBuilder.build(); + return addLeafSetChildren(identifier.getNodeType(), + Builders.orderedLeafSetBuilder().withNodeIdentifier(identifier)).build(); - default : + default: return null; } } @@ -260,7 +259,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; } @@ -295,22 +294,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(); @@ -332,6 +331,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; } @@ -349,12 +357,12 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput final boolean absolute = input.readBoolean(); final int size = input.readInt(); - final Collection qnames = new ArrayList<>(size); + + final Builder qnames = ImmutableList.builderWithExpectedSize(size); for (int i = 0; i < size; ++i) { qnames.add(readQName()); } - - return SchemaPath.create(qnames, absolute); + return SchemaPath.create(qnames.build(), absolute); } @Override @@ -365,13 +373,11 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException { int size = input.readInt(); - - List pathArguments = new ArrayList<>(size); - + final Builder pathArguments = ImmutableList.builderWithExpectedSize(size); for (int i = 0; i < size; i++) { pathArguments.add(readPathArgument()); } - return YangInstanceIdentifier.create(pathArguments); + return YangInstanceIdentifier.create(pathArguments.build()); } private Set readObjSet() throws IOException {