package org.ovirt.engine.core.vdsbroker.xmlrpc;

import java.util.Map;

public class XmlRpcObjectDescriptor {
    public static void toStringBuilder(Map<String, ?> map, StringBuilder builder) {
        if (map == null)
            return;

        for (Map.Entry<String, ?> entry : map.entrySet()) {
            if (entry.getValue() instanceof Map) {
                builder.append(String.format("%1$s:", entry.getKey()));
                builder.append("\n");
                toStringBuilder((Map<String, Object>) entry.getValue(), builder);
                builder.append("\n");
            } else if (!(entry.getValue() instanceof String) && entry.getValue() instanceof Iterable) {
                builder.append(String.format("%1$s:", entry.getKey()));
                builder.append("\n");
                toStringBuilder((Iterable) (entry.getValue()), builder);
                builder.append("\n");
            } else {
                builder.append(String.format("%1$s = %2$s", entry.getKey(), entry.getValue().toString()));
                builder.append("\n");
            }
        }
    }

    public static void toStringBuilder(Map[] xmlRpc, StringBuilder builder) {
        if (xmlRpc == null)
            return;

        for (Map entry : xmlRpc) {
            toStringBuilder(entry, builder);
        }
    }

    private static void toStringBuilder(Iterable xmlRpc, StringBuilder builder) {
        if (xmlRpc == null)
            return;

        for (Object value : xmlRpc) {
            if (value instanceof Iterable) {
                toStringBuilder((Iterable) (value), builder);
            } else {
                builder.append(value.toString());
                builder.append("\n");
            }
        }
    }

}

@@ -42,16 +42,41 @@
 mlrpc;%0A%0A
+import java.util.Arrays;%0A
 import j
@@ -916,32 +916,325 @@
 r.append(%22%5Cn%22);%0A
+            %7D else if (entry.getValue() instanceof Object%5B%5D) %7B%0A                builder.append(String.format(%22%251$s:%22, entry.getKey()));%0A                builder.append(%22%5Cn%22);%0A                builder.append(Arrays.deepToString((Object%5B%5D) entry.getValue()));%0A                builder.append(%22%5Cn%22);%0A
             %7D el

support printing arrays in vdsm resposne