X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fstream%2FNormalizedNodeInputStreamReader.java;h=831c5162628fdb7cc8af80690c539868c305513f;hp=8a114893e66b7c0bca923af23f2c69323e1925d8;hb=244ee83be8c1180ea1845b8768503c8013b0dc7f;hpb=2cf4749c41aa32c6b77064fc1ae0e231adc4a5f4 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 index 8a114893e6..831c516262 100644 --- 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 @@ -17,6 +17,7 @@ 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; @@ -39,6 +40,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; @@ -46,12 +48,10 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** - * NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children nodes. - * This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except END_NODE. - * If a node can have children, then that node's end is calculated based on appearance of END_NODE. - * + * NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children + * nodes. This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except + * END_NODE. If a node can have children, then that node's end is calculated based on appearance of END_NODE. */ - public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput { private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeInputStreamReader.class); @@ -67,6 +67,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private NormalizedNodeAttrBuilder> leafBuilder; + @SuppressWarnings("rawtypes") private NormalizedNodeAttrBuilder> leafSetEntryBuilder; private final StringBuilder reusableStringBuilder = new StringBuilder(50); @@ -74,6 +75,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private boolean readSignatureMarker = true; /** + * Constructs an instance. + * * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead. */ @Deprecated @@ -93,7 +96,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput } private void readSignatureMarkerAndVersionIfNeeded() throws IOException { - if(readSignatureMarker) { + if (readSignatureMarker) { readSignatureMarker = false; final byte marker = input.readByte(); @@ -113,24 +116,24 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput // each node should start with a byte byte nodeType = input.readByte(); - if(nodeType == NodeTypes.END_NODE) { + if (nodeType == NodeTypes.END_NODE) { LOG.debug("End node reached. return"); return null; } - switch(nodeType) { + switch (nodeType) { case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); LOG.debug("Reading augmentation node {} ", augIdentifier); - return addDataContainerChildren(Builders.augmentationBuilder(). - withNodeIdentifier(augIdentifier)).build(); + return addDataContainerChildren(Builders.augmentationBuilder() + .withNodeIdentifier(augIdentifier)).build(); case NodeTypes.LEAF_SET_ENTRY_NODE : QName name = lastLeafSetQName; - if(name == null) { + if (name == null) { name = readQName(); } @@ -147,8 +150,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput LOG.debug("Reading map entry node {} ", entryIdentifier); - return addDataContainerChildren(Builders.mapEntryBuilder(). - withNodeIdentifier(entryIdentifier)).build(); + return addDataContainerChildren(Builders.mapEntryBuilder() + .withNodeIdentifier(entryIdentifier)).build(); default : return readNodeIdentifierDependentNode(nodeType, new NodeIdentifier(readQName())); @@ -157,16 +160,17 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private NormalizedNodeAttrBuilder> leafBuilder() { - if(leafBuilder == null) { + if (leafBuilder == null) { leafBuilder = Builders.leafBuilder(); } return leafBuilder; } + @SuppressWarnings("rawtypes") private NormalizedNodeAttrBuilder> leafSetEntryBuilder() { - if(leafSetEntryBuilder == null) { + if (leafSetEntryBuilder == null) { leafSetEntryBuilder = Builders.leafSetEntryBuilder(); } @@ -176,7 +180,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private NormalizedNode readNodeIdentifierDependentNode(final byte nodeType, final NodeIdentifier identifier) throws IOException { - switch(nodeType) { + switch (nodeType) { case NodeTypes.LEAF_NODE : LOG.debug("Read leaf node {}", identifier); // Read the object value @@ -188,33 +192,28 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput case NodeTypes.MAP_NODE : LOG.debug("Read map node {}", identifier); - return addDataContainerChildren(Builders.mapBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.mapBuilder().withNodeIdentifier(identifier)).build(); - case NodeTypes.CHOICE_NODE : + case NodeTypes.CHOICE_NODE: LOG.debug("Read choice node {}", identifier); - return addDataContainerChildren(Builders.choiceBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.choiceBuilder().withNodeIdentifier(identifier)).build(); - case NodeTypes.ORDERED_MAP_NODE : + case NodeTypes.ORDERED_MAP_NODE: LOG.debug("Reading ordered map node {}", identifier); - return addDataContainerChildren(Builders.orderedMapBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.orderedMapBuilder().withNodeIdentifier(identifier)).build(); - case NodeTypes.UNKEYED_LIST : + case NodeTypes.UNKEYED_LIST: LOG.debug("Read unkeyed list node {}", identifier); - return addDataContainerChildren(Builders.unkeyedListBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.unkeyedListBuilder().withNodeIdentifier(identifier)).build(); - case NodeTypes.UNKEYED_LIST_ITEM : + case NodeTypes.UNKEYED_LIST_ITEM: LOG.debug("Read unkeyed list item node {}", identifier); - return addDataContainerChildren(Builders.unkeyedListEntryBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.unkeyedListEntryBuilder() + .withNodeIdentifier(identifier)).build(); - case NodeTypes.CONTAINER_NODE : + case NodeTypes.CONTAINER_NODE: LOG.debug("Read container node {}", identifier); - return addDataContainerChildren(Builders.containerBuilder(). - withNodeIdentifier(identifier)).build(); + return addDataContainerChildren(Builders.containerBuilder().withNodeIdentifier(identifier)).build(); case NodeTypes.LEAF_SET : LOG.debug("Read leaf set node {}", identifier); @@ -252,25 +251,24 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput String namespace = readCodedString(); String revision = readCodedString(); - String qName; - if(!Strings.isNullOrEmpty(revision)) { - qName = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG). - append(revision).append(')').append(localName).toString(); + String qname; + if (!Strings.isNullOrEmpty(revision)) { + qname = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG).append(revision) + .append(')').append(localName).toString(); } else { - qName = reusableStringBuilder.append('(').append(namespace).append(')'). - append(localName).toString(); + qname = reusableStringBuilder.append('(').append(namespace).append(')').append(localName).toString(); } reusableStringBuilder.delete(0, reusableStringBuilder.length()); - return QNameFactory.create(qName); + return QNameFactory.create(qname); } private String readCodedString() throws IOException { byte valueType = input.readByte(); - if(valueType == TokenTypes.IS_CODE_VALUE) { + if (valueType == TokenTypes.IS_CODE_VALUE) { return codedStringMap.get(input.readInt()); - } else if(valueType == TokenTypes.IS_STRING_VALUE) { + } else if (valueType == TokenTypes.IS_STRING_VALUE) { String value = input.readUTF().intern(); codedStringMap.put(Integer.valueOf(codedStringMap.size()), value); return value; @@ -279,11 +277,11 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput return null; } - private Set readQNameSet() throws IOException{ + private Set readQNameSet() throws IOException { // Read the children count int count = input.readInt(); Set children = new HashSet<>(count); - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { children.add(readQName()); } return children; @@ -293,7 +291,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput int count = input.readInt(); Map keyValueMap = new HashMap<>(count); - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { keyValueMap.put(readQName(), readObject()); } @@ -302,7 +300,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private Object readObject() throws IOException { byte objectType = input.readByte(); - switch(objectType) { + switch (objectType) { case ValueTypes.BITS_TYPE: return readObjSet(); @@ -355,6 +353,20 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput return new String(bytes, StandardCharsets.UTF_8); } + @Override + public SchemaPath readSchemaPath() throws IOException { + readSignatureMarkerAndVersionIfNeeded(); + + final boolean absolute = input.readBoolean(); + final int size = input.readInt(); + final Collection qnames = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + qnames.add(readQName()); + } + + return SchemaPath.create(qnames, absolute); + } + @Override public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException { readSignatureMarkerAndVersionIfNeeded(); @@ -366,7 +378,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput List pathArguments = new ArrayList<>(size); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { pathArguments.add(readPathArgument()); } return YangInstanceIdentifier.create(pathArguments); @@ -375,7 +387,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private Set readObjSet() throws IOException { int count = input.readInt(); Set children = new HashSet<>(count); - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { children.add(readCodedString()); } return children; @@ -386,7 +398,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput // read Type int type = input.readByte(); - switch(type) { + switch (type) { case PathArgumentTypes.AUGMENTATION_IDENTIFIER : return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); @@ -415,7 +427,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput LeafSetEntryNode child = (LeafSetEntryNode)readNormalizedNodeInternal(); - while(child != null) { + while (child != null) { builder.withChild(child); child = (LeafSetEntryNode)readNormalizedNodeInternal(); } @@ -429,7 +441,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput NormalizedNode child = readNormalizedNodeInternal(); - while(child != null) { + while (child != null) { builder.addChild(child); child = readNormalizedNodeInternal(); } @@ -437,21 +449,21 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput } @Override - public void readFully(final byte[] b) throws IOException { + public void readFully(final byte[] value) throws IOException { readSignatureMarkerAndVersionIfNeeded(); - input.readFully(b); + input.readFully(value); } @Override - public void readFully(final byte[] b, final int off, final int len) throws IOException { + public void readFully(final byte[] str, final int off, final int len) throws IOException { readSignatureMarkerAndVersionIfNeeded(); - input.readFully(b, off, len); + input.readFully(str, off, len); } @Override - public int skipBytes(final int n) throws IOException { + public int skipBytes(final int num) throws IOException { readSignatureMarkerAndVersionIfNeeded(); - return input.skipBytes(n); + return input.skipBytes(num); } @Override