import com.google.common.base.Preconditions;
import java.net.URI;
-import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
* @param id InstanceIdentifier
* @throws XMLStreamException
*/
- public static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull InstanceIdentifier id) throws XMLStreamException {
+ public static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull YangInstanceIdentifier id) throws XMLStreamException {
Preconditions.checkNotNull(writer, "Writer may not be null");
Preconditions.checkNotNull(id, "Variable should contain instance of instance identifier and can't be null");
}
writer.writeStartElement(pfx, qname.getLocalName(), ns);
+ writeValue(writer, data, schema);
+ writer.writeEndElement();
+ }
+
+ /**
+ * Write a value into a XML stream writer. This method assumes the start and end of element is
+ * emitted by the caller.
+ *
+ * @param writer XML Stream writer
+ * @param data data node
+ * @param schema Schema node
+ * @throws XMLStreamException if an encoding problem occurs
+ */
+ public void writeValue(final XMLStreamWriter writer, final @Nonnull Node<?> data, final SchemaNode schema) throws XMLStreamException {
if (data instanceof AttributesContainer && ((AttributesContainer) data).getAttributes() != null) {
RandomPrefix randomPrefix = new RandomPrefix();
for (Entry<QName, String> attribute : ((AttributesContainer) data).getAttributes().entrySet()) {
writeElement(writer, child, childSchema);
}
}
-
- writer.writeEndElement();
}
@VisibleForTesting
* emitted by the caller.
*
* @param writer XML Stream writer
- * @param data data node
- * @param schema Schema node
+ * @param type data type
+ * @param value data value
* @throws XMLStreamException if an encoding problem occurs
*/
public void writeValue(final @Nonnull XMLStreamWriter writer, final @Nonnull TypeDefinition<?> type, final Object value) throws XMLStreamException {
}
private static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull InstanceIdentifierTypeDefinition type, final @Nonnull Object value) throws XMLStreamException {
- if (value instanceof InstanceIdentifier) {
- write(writer, (InstanceIdentifier)value);
+ if (value instanceof YangInstanceIdentifier) {
+ write(writer, (YangInstanceIdentifier)value);
} else {
LOG.debug("Value of {}:{} is not an InstanceIdentifier but {}", type.getQName().getNamespace(), type.getQName().getLocalName(), value.getClass());
writer.writeCharacters(String.valueOf(value));