* @param schemaNode Schema node that describes the value
* @param value data value
* @param parent module QName owning the leaf definition
+ * @return String characters to be written
* @throws XMLStreamException if an encoding problem occurs
*/
- void writeValue(final @NonNull ValueWriter writer, final @NonNull SchemaNode schemaNode,
+ String encodeValue(final @NonNull ValueWriter writer, final @NonNull SchemaNode schemaNode,
final @NonNull Object value, final QNameModule parent) throws XMLStreamException {
checkArgument(schemaNode instanceof TypedDataSchemaNode,
"Unable to write value for node %s, only nodes of type: leaf and leaf-list can be written at this point",
type = getBaseTypeForLeafRef(schemaNode, (LeafrefTypeDefinition) type);
}
- writeValue(writer, type, value, parent);
+ return encodeValue(writer, type, value, parent);
}
/**
* @param type data type. In case of leaf ref this should be the type of leaf being referenced
* @param value data value
* @param parent optional parameter of a module QName owning the leaf definition
+ * @return String characters to be written
* @throws XMLStreamException if an encoding problem occurs
*/
- private void writeValue(final @NonNull ValueWriter writer, final @NonNull TypeDefinition<?> type,
+ private String encodeValue(final @NonNull ValueWriter writer, final @NonNull TypeDefinition<?> type,
final @NonNull Object value, final QNameModule parent) throws XMLStreamException {
if (type instanceof IdentityrefTypeDefinition) {
- write(writer, (IdentityrefTypeDefinition) type, value, parent);
+ return encode(writer, (IdentityrefTypeDefinition) type, value, parent);
} else if (type instanceof InstanceIdentifierTypeDefinition) {
- write(writer, (InstanceIdentifierTypeDefinition) type, value);
+ return encode(writer, (InstanceIdentifierTypeDefinition) type, value);
} else {
- writer.writeCharacters(serialize(type, value));
+ return serialize(type, value);
}
}
}
@VisibleForTesting
- static void write(final @NonNull ValueWriter writer, final @NonNull IdentityrefTypeDefinition type,
+ static String encode(final @NonNull ValueWriter writer, final @NonNull IdentityrefTypeDefinition type,
final @NonNull Object value, final QNameModule parent) throws XMLStreamException {
if (value instanceof QName) {
final QName qname = (QName) value;
//in case parent is present and same as element namespace write value without namespace
if (qname.getNamespace().equals(parent.getNamespace())) {
- writer.writeCharacters(qname.getLocalName());
- } else {
- final String ns = qname.getNamespace().toString();
- final String prefix = "x";
- writer.writeNamespace(prefix, ns);
- writer.writeCharacters(prefix + ':' + qname.getLocalName());
+ return qname.getLocalName();
}
- } else {
- final QName qname = type.getQName();
- LOG.debug("Value of {}:{} is not a QName but {}", qname.getNamespace(), qname.getLocalName(),
- value.getClass());
- writer.writeToStringCharacters(value);
+
+ final String ns = qname.getNamespace().toString();
+ final String prefix = "x";
+ writer.writeNamespace(prefix, ns);
+ return prefix + ':' + qname.getLocalName();
}
+
+ final QName qname = type.getQName();
+ LOG.debug("Value of {}:{} is not a QName but {}", qname.getNamespace(), qname.getLocalName(), value.getClass());
+ return value.toString();
}
- private void write(final @NonNull ValueWriter writer, final @NonNull InstanceIdentifierTypeDefinition type,
+ private String encode(final @NonNull ValueWriter writer, final @NonNull InstanceIdentifierTypeDefinition type,
final @NonNull Object value) throws XMLStreamException {
if (value instanceof YangInstanceIdentifier) {
- writeInstanceIdentifier(writer, (YangInstanceIdentifier)value);
- } else {
- final QName qname = type.getQName();
- LOG.warn("Value of {}:{} is not an InstanceIdentifier but {}", qname.getNamespace(), qname.getLocalName(),
- value.getClass());
- writer.writeToStringCharacters(value);
+ return encodeInstanceIdentifier(writer, (YangInstanceIdentifier)value);
}
+
+ final QName qname = type.getQName();
+ LOG.warn("Value of {}:{} is not an InstanceIdentifier but {}", qname.getNamespace(), qname.getLocalName(),
+ value.getClass());
+ return value.toString();
}
abstract @NonNull TypeDefinition<?> getBaseTypeForLeafRef(SchemaNode schemaNode,
@NonNull LeafrefTypeDefinition type);
- abstract void writeInstanceIdentifier(@NonNull ValueWriter writer, YangInstanceIdentifier value)
+ abstract String encodeInstanceIdentifier(@NonNull ValueWriter writer, YangInstanceIdentifier value)
throws XMLStreamException;
}