import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
-final class SchemaAwareXMLStreamNormalizedNodeStreamWriter extends XMLStreamNormalizedNodeStreamWriter<SchemaNode>
- implements SchemaContextProvider {
+final class SchemaAwareXMLStreamNormalizedNodeStreamWriter
+ extends XMLStreamNormalizedNodeStreamWriter<TypedDataSchemaNode> implements SchemaContextProvider {
private final SchemaTracker tracker;
private final SchemaAwareXMLStreamWriterUtils streamUtils;
}
@Override
- String encodeValue(final ValueWriter xmlWriter, final Object value, final SchemaNode schemaNode)
+ String encodeValue(final ValueWriter xmlWriter, final Object value, final TypedDataSchemaNode schemaNode)
throws XMLStreamException {
- return streamUtils.encodeValue(xmlWriter, schemaNode, value, schemaNode.getQName().getModule());
+ return streamUtils.encodeValue(xmlWriter, schemaNode, schemaNode.getType(), value,
+ schemaNode.getQName().getModule());
}
@Override
final Optional<AnnotationSchemaNode> optAnnotation = AnnotationSchemaNode.find(streamUtils.getSchemaContext(),
qname);
if (optAnnotation.isPresent()) {
- return streamUtils.encodeValue(xmlWriter, optAnnotation.get(), value, qname.getModule());
+ final AnnotationSchemaNode schema = optAnnotation.get();
+ return streamUtils.encodeValue(xmlWriter, schema, schema.getType(), value, qname.getModule());
}
checkArgument(!qname.getRevision().isPresent(), "Failed to find bound annotation %s", qname);
public void scalarValue(final Object value) throws IOException {
final Object current = tracker.getParent();
if (current instanceof TypedDataSchemaNode) {
- writeValue(value, (SchemaNode) current);
+ writeValue(value, (TypedDataSchemaNode) current);
} else if (current instanceof AnydataSchemaNode) {
anydataValue(value);
} else {
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.VisibleForTesting;
import javax.xml.stream.XMLStreamException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeAware;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
*
* @param writer XML Stream writer
* @param schemaNode Schema node that describes the value
+ * @param type Schema type definition
* @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
*/
- String encodeValue(final @NonNull ValueWriter writer, final @NonNull SchemaNode schemaNode,
- final @NonNull Object value, final QNameModule parent) throws XMLStreamException {
- checkArgument(schemaNode instanceof TypeAware,
- "Unable to write value for node %s, only nodes of type: leaf, leaf-list and annotations can be written "
- + "at this point", schemaNode.getQName());
-
- TypeDefinition<?> type = ((TypeAware) schemaNode).getType();
- if (type instanceof LeafrefTypeDefinition) {
- type = getBaseTypeForLeafRef(schemaNode, (LeafrefTypeDefinition) type);
- }
-
- return encodeValue(writer, type, value, parent);
+ String encodeValue(final @NonNull ValueWriter writer,final @NonNull SchemaNode schemaNode,
+ final TypeDefinition<?> type, final @NonNull Object value, final QNameModule parent)
+ throws XMLStreamException {
+ return type instanceof LeafrefTypeDefinition
+ ? encodeValue(writer, getBaseTypeForLeafRef(schemaNode, (LeafrefTypeDefinition) type), value, parent)
+ : encodeValue(writer, type, value, parent);
}
/**