Example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(Object object, ToStringStyle style) 

Source Link

Document

Forwards to ReflectionToStringBuilder.

Usage

From source file:nl.nn.adapterframework.core.IbisException.java

public String getMessage() {
    Throwable throwables[] = getThrowables();
    String result = null;/*from  ww w  .  jav a 2 s.  c  om*/
    String prev_message = null;

    for (int i = getThrowableCount() - 1; i >= 0; i--) {

        String cur_message = getMessage(i);

        //         if (log.isDebugEnabled()) {
        //            log.debug("t["+i+"], ["+ClassUtils.nameOf(throwables[i])+"], cur ["+cur_message+"], prev ["+prev_message+"]");
        //         }          

        String newPart = null;

        // prefix the result with the message of this exception.
        // if the new message ends with the previous, remove the part that is already known
        if (StringUtils.isNotEmpty(cur_message)) {
            newPart = addPart(cur_message, " ", newPart);
            if (StringUtils.isNotEmpty(newPart) && StringUtils.isNotEmpty(prev_message)
                    && newPart.endsWith(prev_message)) {
                newPart = newPart.substring(0, newPart.length() - prev_message.length());
            }
            if (StringUtils.isNotEmpty(newPart) && newPart.endsWith(": ")) {
                newPart = newPart.substring(0, newPart.length() - 2);
            }
            prev_message = cur_message;
        }
        String specificDetails = getExceptionSpecificDetails(throwables[i]);
        if (StringUtils.isNotEmpty(specificDetails)
                && (result == null || result.indexOf(specificDetails) < 0)) {
            newPart = addPart(specificDetails, ": ", newPart);
        }

        if (!(throwables[i] instanceof IbisException)) {
            String exceptionType = "(" + getExceptionType(throwables[i]) + ")";
            newPart = addPart(exceptionType, " ", newPart);
        }
        result = addPart(newPart, ": ", result);
    }

    if (result == null) {
        //          log.debug("no message found, returning fields by inspection");
        // do not replace the following with toString(), this causes an endless loop. GvB
        result = "no message, fields of this exception: "
                + ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
    return result;
}

From source file:no.java.ems.server.restlet.RoomResource.java

public Representation getRepresentation(Variant variant) {
    Serializable resource;/*w  w  w.j a va 2 s .c  o  m*/
    String eventId = (String) getRequest().getAttributes().get(EVENTID);
    if (StringUtils.isBlank(getId())) {
        resource = new ArrayList<Room>(roomDao.getRooms());
    } else {
        resource = roomDao.getRoom(getId());
    }
    if (!StringUtils.isBlank(eventId)) {
        Event event = eventDao.getEvent(eventId);
        if (event != null) {
            resource = new ArrayList<Room>(event.getRooms());
        }
    }
    if (variant.getMediaType().equals(MediaType.APPLICATION_JAVA_OBJECT)) {
        return new ObjectRepresentation(resource);
    } else if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {
        return new StringRepresentation(
                ToStringBuilder.reflectionToString(resource, ToStringStyle.MULTI_LINE_STYLE));
    }
    return super.getRepresentation(variant);
}

From source file:opendbcopy.plugin.model.exception.MissingAttributeException.java

/**
 * DOCUMENT ME!/*  ww w  .ja va 2  s .c o  m*/
 *
 * @return DOCUMENT ME!
 */
public String getAvailableAttributes() {
    return ToStringBuilder.reflectionToString(element.getAttributes(), ToStringStyle.MULTI_LINE_STYLE);
}

From source file:opendbcopy.plugin.model.exception.MissingElementException.java

/**
 * DOCUMENT ME!//from   www.  jav a  2s.  c o m
 *
 * @return DOCUMENT ME!
 */
public String getAvailableElements() {
    if (element == null) {
        return ToStringBuilder.reflectionToString(pluginModel, ToStringStyle.MULTI_LINE_STYLE);
    } else {
        return ToStringBuilder.reflectionToString(element, ToStringStyle.MULTI_LINE_STYLE);
    }
}

From source file:opendbcopy.plugin.model.exception.UnsuppertedElementException.java

/**
 * DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public String getAvailableElements() {
    return ToStringBuilder.reflectionToString(element, ToStringStyle.MULTI_LINE_STYLE);
}

From source file:org.apache.cxf.jaxb.JAXBElementToStringStyleTest.java

@Test
public void testToStringMultiLineStyle() throws Exception {
    String ts = ToStringBuilder.reflectionToString(h, JAXBToStringStyle.MULTI_LINE_STYLE);

    validateHolderString(ts);/*from  w  w w.j  a va  2s.  c  om*/
    validateElementString(ts);
}

From source file:org.apache.cxf.jaxb.JAXBElementToStringStyleTest.java

@Test
public void testToStringSimpleStyle() throws Exception {
    String ts = ToStringBuilder.reflectionToString(h, JAXBToStringStyle.SIMPLE_STYLE);

    // field names are missing
    Assert.assertTrue("has no obj field", ts.indexOf("obj") == -1);
    Assert.assertTrue("has HolderName", ts.indexOf("HolderName") != -1);
    Assert.assertTrue("has SomeText", ts.indexOf("SomeText") != -1);
}

From source file:org.apache.cxf.jaxb.JAXBToStringBuilder.java

public static String valueOf(Object object, ToStringStyle style) {
    if (object instanceof String) {
        return (String) object;
    }/*w w w  .  java2 s  .  c o m*/
    if (object instanceof Collection) {
        object = ((Collection<?>) object).toArray();
    }
    return ToStringBuilder.reflectionToString(object, style);
}

From source file:org.apache.cxf.jaxb.JAXBToStringStyle.java

@Override
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
    if (value instanceof JAXBElement) {
        buffer.append(ToStringBuilder.reflectionToString(value, this));
    } else {/*  ww  w. java 2  s.com*/
        buffer.append(value);
    }
}

From source file:org.apache.hadoop.hbase.rest.model.TestCellModel.java

@Test
public void testToString() throws Exception {
    String expectedColumn = ToStringBuilder.reflectionToString(COLUMN, ToStringStyle.SIMPLE_STYLE);

    CellModel cellModel = buildTestModel();
    System.out.println(cellModel);

    assertTrue(StringUtils.contains(cellModel.toString(), expectedColumn));
}