Search in sources :

Example 1 with DynaClass

use of org.apache.commons.beanutils.DynaClass in project sonarqube by SonarSource.

the class DynaActionForm method toString.

// --------------------------------------------------------- Public Methods
/**
     * <p>Render a String representation of this object.</p>
     *
     * @return A string representation of this object.
     */
public String toString() {
    StringBuffer sb = new StringBuffer("DynaActionForm[dynaClass=");
    DynaClass dynaClass = getDynaClass();
    if (dynaClass == null) {
        return sb.append("null]").toString();
    }
    sb.append(dynaClass.getName());
    DynaProperty[] props = dynaClass.getDynaProperties();
    if (props == null) {
        props = new DynaProperty[0];
    }
    for (int i = 0; i < props.length; i++) {
        sb.append(',');
        sb.append(props[i].getName());
        sb.append('=');
        Object value = get(props[i].getName());
        if (value == null) {
            sb.append("<NULL>");
        } else if (value.getClass().isArray()) {
            int n = Array.getLength(value);
            sb.append("{");
            for (int j = 0; j < n; j++) {
                if (j > 0) {
                    sb.append(',');
                }
                sb.append(Array.get(value, j));
            }
            sb.append("}");
        } else if (value instanceof List) {
            int n = ((List) value).size();
            sb.append("{");
            for (int j = 0; j < n; j++) {
                if (j > 0) {
                    sb.append(',');
                }
                sb.append(((List) value).get(j));
            }
            sb.append("}");
        } else if (value instanceof Map) {
            int n = 0;
            Iterator keys = ((Map) value).keySet().iterator();
            sb.append("{");
            while (keys.hasNext()) {
                if (n > 0) {
                    sb.append(',');
                }
                n++;
                Object key = keys.next();
                sb.append(key);
                sb.append('=');
                sb.append(((Map) value).get(key));
            }
            sb.append("}");
        } else {
            sb.append(value);
        }
    }
    sb.append("]");
    return (sb.toString());
}
Also used : DynaProperty(org.apache.commons.beanutils.DynaProperty) DynaClass(org.apache.commons.beanutils.DynaClass) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 DynaClass (org.apache.commons.beanutils.DynaClass)1 DynaProperty (org.apache.commons.beanutils.DynaProperty)1