This reorganizes AbstractNormalizedNodeDataOutput so that it
implements all NormalizedNodeDataOutput with final methods,
deferring implementation as need to abstract methods.
This way we have precisely one implementation of public methods,
making it easy to audit for correctness. Furthermore it eliminates
writeAugmentationIdentifier() override in NeonSR2 writer.
It also introduces writeQNameInternal(), which skips header checks,
as the call sites have already performed those checks.
Change-Id: Icb4a7e994c04e3d52bd561d99c7743dfdfd88738
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rawOuput.writeBoolean((Boolean) value);
break;
case ValueTypes.QNAME_TYPE:
rawOuput.writeBoolean((Boolean) value);
break;
case ValueTypes.QNAME_TYPE:
- writeQName((QName) value);
+ writeQNameInternal((QName) value);
break;
case ValueTypes.INT_TYPE:
rawOuput.writeInt((Integer) value);
break;
case ValueTypes.INT_TYPE:
rawOuput.writeInt((Integer) value);
- protected abstract short streamVersion();
-
- abstract void writeString(@NonNull String string) throws IOException;
-
@Override
public final void write(final int value) throws IOException {
ensureHeaderWritten();
@Override
public final void write(final int value) throws IOException {
ensureHeaderWritten();
- private NormalizedNodeWriter normalizedNodeWriter() {
+ @Override
+ public final void writeQName(final QName qname) throws IOException {
+ ensureHeaderWritten();
+ writeQNameInternal(qname);
+ }
+
+ @Override
+ public final void writeNormalizedNode(final NormalizedNode<?, ?> node) throws IOException {
+ ensureHeaderWritten();
if (normalizedNodeWriter == null) {
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(this);
}
if (normalizedNodeWriter == null) {
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(this);
}
+ normalizedNodeWriter.write(node);
+ }
- return normalizedNodeWriter;
+ @Override
+ public final void writePathArgument(final PathArgument pathArgument) throws IOException {
+ ensureHeaderWritten();
+ writePathArgumentInternal(pathArgument);
- public void writeNormalizedNode(final NormalizedNode<?, ?> node) throws IOException {
+ public final void writeYangInstanceIdentifier(final YangInstanceIdentifier identifier) throws IOException {
- normalizedNodeWriter().write(node);
+ writeYangInstanceIdentifierInternal(identifier);
+ }
+
+ @Override
+ public final void writeSchemaPath(final SchemaPath path) throws IOException {
+ ensureHeaderWritten();
+ output.writeBoolean(path.isAbsolute());
+
+ final Collection<QName> qnames = path.getPath();
+ output.writeInt(qnames.size());
+ for (QName qname : qnames) {
+ writeQNameInternal(qname);
+ }
+ }
+
+ @Override
+ public final void close() throws IOException {
+ flush();
// lastLeafSetQName is set if the parent LeafSetNode was previously written. Otherwise this is a
// stand alone LeafSetEntryNode so write out it's name here.
if (lastLeafSetQName == null) {
// lastLeafSetQName is set if the parent LeafSetNode was previously written. Otherwise this is a
// stand alone LeafSetEntryNode so write out it's name here.
if (lastLeafSetQName == null) {
- writeQName(name.getNodeType());
+ writeQNameInternal(name.getNodeType());
- @Override
- public void close() throws IOException {
- flush();
- }
-
@Override
public void flush() throws IOException {
if (output instanceof OutputStream) {
@Override
public void flush() throws IOException {
if (output instanceof OutputStream) {
// First write the type of node
output.writeByte(nodeType);
// Write Start Tag
// First write the type of node
output.writeByte(nodeType);
// Write Start Tag
- writeQName(arg.getNodeType());
+ writeQNameInternal(arg.getNodeType());
}
final void writeObjSet(final Set<?> set) throws IOException {
}
final void writeObjSet(final Set<?> set) throws IOException {
- @Override
- public void writeSchemaPath(final SchemaPath path) throws IOException {
- ensureHeaderWritten();
- output.writeBoolean(path.isAbsolute());
-
- final Collection<QName> qnames = path.getPath();
- output.writeInt(qnames.size());
- for (QName qname : qnames) {
- writeQName(qname);
- }
- }
-
- @Override
- public void writeYangInstanceIdentifier(final YangInstanceIdentifier identifier) throws IOException {
- ensureHeaderWritten();
- writeYangInstanceIdentifierInternal(identifier);
- }
-
final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
Collection<PathArgument> pathArguments = identifier.getPathArguments();
output.writeInt(pathArguments.size());
final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
Collection<PathArgument> pathArguments = identifier.getPathArguments();
output.writeInt(pathArguments.size());
- @Override
- public void writePathArgument(final PathArgument pathArgument) throws IOException {
- ensureHeaderWritten();
- writePathArgumentInternal(pathArgument);
- }
-
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST",
justification = "The casts in the switch clauses are indirectly confirmed via the determination of 'type'.")
final void writePathArgumentInternal(final PathArgument pathArgument) throws IOException {
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST",
justification = "The casts in the switch clauses are indirectly confirmed via the determination of 'type'.")
final void writePathArgumentInternal(final PathArgument pathArgument) throws IOException {
-
- byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
-
+ final byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
output.writeByte(type);
switch (type) {
case PathArgumentTypes.NODE_IDENTIFIER:
output.writeByte(type);
switch (type) {
case PathArgumentTypes.NODE_IDENTIFIER:
NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument;
NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument;
-
- writeQName(nodeIdentifier.getNodeType());
+ writeQNameInternal(nodeIdentifier.getNodeType());
case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES:
case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES:
NodeIdentifierWithPredicates nodeIdentifierWithPredicates =
(NodeIdentifierWithPredicates) pathArgument;
NodeIdentifierWithPredicates nodeIdentifierWithPredicates =
(NodeIdentifierWithPredicates) pathArgument;
- writeQName(nodeIdentifierWithPredicates.getNodeType());
-
+ writeQNameInternal(nodeIdentifierWithPredicates.getNodeType());
writeKeyValueMap(nodeIdentifierWithPredicates.entrySet());
break;
writeKeyValueMap(nodeIdentifierWithPredicates.entrySet());
break;
-
- case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE :
-
+ case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE:
NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument;
NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument;
-
- writeQName(nodeWithValue.getNodeType());
+ writeQNameInternal(nodeWithValue.getNodeType());
writeObject(nodeWithValue.getValue());
break;
writeObject(nodeWithValue.getValue());
break;
-
- case PathArgumentTypes.AUGMENTATION_IDENTIFIER :
-
+ case PathArgumentTypes.AUGMENTATION_IDENTIFIER:
// No Qname in augmentation identifier
writeAugmentationIdentifier((AugmentationIdentifier) pathArgument);
break;
// No Qname in augmentation identifier
writeAugmentationIdentifier((AugmentationIdentifier) pathArgument);
break;
throw new IllegalStateException("Unknown node identifier type is found : "
+ pathArgument.getClass().toString());
}
throw new IllegalStateException("Unknown node identifier type is found : "
+ pathArgument.getClass().toString());
}
if (!entrySet.isEmpty()) {
output.writeInt(entrySet.size());
for (Entry<QName, Object> entry : entrySet) {
if (!entrySet.isEmpty()) {
output.writeInt(entrySet.size());
for (Entry<QName, Object> entry : entrySet) {
- writeQName(entry.getKey());
+ writeQNameInternal(entry.getKey());
writeObject(entry.getValue());
}
} else {
writeObject(entry.getValue());
}
} else {
- void writeAugmentationIdentifier(final AugmentationIdentifier aid) throws IOException {
+ final void defaultWriteAugmentationIdentifier(final @NonNull AugmentationIdentifier aid) throws IOException {
final Set<QName> qnames = aid.getPossibleChildNames();
// Write each child's qname separately, if list is empty send count as 0
if (!qnames.isEmpty()) {
output.writeInt(qnames.size());
for (QName qname : qnames) {
final Set<QName> qnames = aid.getPossibleChildNames();
// Write each child's qname separately, if list is empty send count as 0
if (!qnames.isEmpty()) {
output.writeInt(qnames.size());
for (QName qname : qnames) {
+ writeQNameInternal(qname);
}
} else {
LOG.debug("augmentation node does not have any child");
}
} else {
LOG.debug("augmentation node does not have any child");
+ abstract short streamVersion();
+
+ abstract void writeString(@NonNull String string) throws IOException;
+
+ abstract void writeQNameInternal(@NonNull QName qname) throws IOException;
+
+ abstract void writeAugmentationIdentifier(@NonNull AugmentationIdentifier aid) throws IOException;
+
abstract void writeObject(@NonNull DataOutput output, @NonNull Object value) throws IOException;
private void writeObject(final Object value) throws IOException {
abstract void writeObject(@NonNull DataOutput output, @NonNull Object value) throws IOException;
private void writeObject(final Object value) throws IOException {
import java.io.IOException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import java.io.IOException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
/**
* NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in
/**
* NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in
- protected short streamVersion() {
+ short streamVersion() {
return TokenTypes.LITHIUM_VERSION;
}
@Override
return TokenTypes.LITHIUM_VERSION;
}
@Override
- public void writeQName(final QName qname) throws IOException {
+ void writeQNameInternal(final QName qname) throws IOException {
defaultWriteQName(qname);
}
defaultWriteQName(qname);
}
void writeModule(final QNameModule module) throws IOException {
defaultWriteModule(module);
}
void writeModule(final QNameModule module) throws IOException {
defaultWriteModule(module);
}
+
+ @Override
+ void writeAugmentationIdentifier(final AugmentationIdentifier aid) throws IOException {
+ defaultWriteAugmentationIdentifier(aid);
+ }
- protected short streamVersion() {
+ short streamVersion() {
return TokenTypes.NEON_SR2_VERSION;
}
@Override
return TokenTypes.NEON_SR2_VERSION;
}
@Override
- public void writeQName(final QName qname) throws IOException {
+ void writeQNameInternal(final QName qname) throws IOException {
final Integer value = qnameCodeMap.get(qname);
if (value == null) {
// Fresh QName, remember it and emit as three strings
final Integer value = qnameCodeMap.get(qname);
if (value == null) {
// Fresh QName, remember it and emit as three strings
// Fresh AugmentationIdentifier, remember it and emit as three strings
aidCodeMap.put(aid, aidCodeMap.size());
writeByte(TokenTypes.IS_AUGMENT_VALUE);
// Fresh AugmentationIdentifier, remember it and emit as three strings
aidCodeMap.put(aid, aidCodeMap.size());
writeByte(TokenTypes.IS_AUGMENT_VALUE);
- super.writeAugmentationIdentifier(aid);
+ defaultWriteAugmentationIdentifier(aid);
} else {
// We have already seen this AugmentationIdentifier: write its code
writeByte(TokenTypes.IS_AUGMENT_CODE);
} else {
// We have already seen this AugmentationIdentifier: write its code
writeByte(TokenTypes.IS_AUGMENT_CODE);