Example usage for org.apache.commons.lang3.exception ExceptionContext addContextValue

List of usage examples for org.apache.commons.lang3.exception ExceptionContext addContextValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionContext addContextValue.

Prototype

ExceptionContext addContextValue(String label, Object value);

Source Link

Document

Adds a contextual label-value pair into this context.

Usage

From source file:org.force66.cxfutils.reflect.ReflectUtils.java

public static void reflectionAppendContextValues(ExceptionContext context, Object embeddedInfo, String label) {
    Validate.notNull(context, "Null context not allowed.");
    Validate.notEmpty(label, "Null or blank label not allowed.");
    if (embeddedInfo == null) {
        context.addContextValue(label, embeddedInfo);
        return;// ww  w . j  a va  2 s .c  o  m
    }

    List<Field> fieldList = FieldUtils.getAllFieldsList(embeddedInfo.getClass());
    Object fieldValue;
    String fieldLabel;

    for (Field field : fieldList) {
        fieldLabel = label + "." + field.getName();
        fieldValue = readField(field, embeddedInfo);
        if (fieldValue instanceof Collection) {
            reflectionAppendContextValues(context, (Collection) fieldValue, fieldLabel);

        } else if (field.getType().isPrimitive() || field.getType().getPackage().getName().startsWith("java")) {
            context.addContextValue(fieldLabel, fieldValue);
        } else {
            reflectionAppendContextValues(context, fieldValue, fieldLabel);
        }
    }
}