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

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

Introduction

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

Prototype

public static String reflectionToString(final Object object) 

Source Link

Document

Uses ReflectionToStringBuilder to generate a toString for the specified object.

Usage

From source file:io.specto.hoverfly.junit.core.model.Request.java

@Override
public String toString() {
    try {/*from   www  .  j av  a 2  s  .  c  o m*/
        return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
    } catch (JsonProcessingException e) {
        return ToStringBuilder.reflectionToString(this);
    }
}

From source file:com.datumbox.framework.common.utilities.PHPMethods.java

/**
 * Returns the contexts of an Objects in a human readable format.
 * /*from  w  ww  .  java  2 s  .c  o m*/
 * @param <T>
 * @param object
 * @return 
 */
public static <T> String var_export(T object) {
    return ToStringBuilder.reflectionToString(object);
}

From source file:blue.orchestra.blueSynthBuilder.BSBCloneTest.java

public void testLoadSave() {
    BSBObjectEntry[] bsbObjects = BSBObjectRegistry.getBSBObjects();

    for (int i = 0; i < bsbObjects.length; i++) {
        BSBObjectEntry entry = bsbObjects[i];

        Class class1 = entry.bsbObjectClass;

        BSBObject bsbObj = null;//from ww w .jav  a  2 s. c  o  m

        try {
            bsbObj = (BSBObject) class1.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        assertNotNull(bsbObj);

        if (bsbObj == null) {
            continue;
        }

        Element elem1 = bsbObj.saveAsXML();

        Method m = null;
        try {
            m = class1.getMethod("loadFromXML", new Class[] { Element.class });
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        BSBObject bsbObj2 = null;

        assertNotNull(m);
        if (m == null) {
            continue;
        }

        try {
            bsbObj2 = (BSBObject) m.invoke(bsbObj, new Object[] { elem1 });
        } catch (IllegalArgumentException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (IllegalAccessException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (InvocationTargetException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

        boolean isEqual = EqualsBuilder.reflectionEquals(bsbObj, bsbObj2);

        if (!isEqual) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("Problem with class: ").append(class1.getName()).append("\n");
            buffer.append("Original Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj)).append("\n");
            buffer.append("Cloned Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj2)).append("\n");

            System.out.println(buffer.toString());

        }

        assertTrue(isEqual);

    }

}

From source file:com.autentia.tnt.faces.components.query.model.SimpleExpression.java

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this).toString();
}

From source file:com.gdn.iam.spring.security.FortressDecisionVoter.java

@Override
@SuppressWarnings("static-access")
public int vote(Authentication authentication, FilterInvocation fi, Collection<ConfigAttribute> attributes) {
    Authentication securityContextAuthentication = SecurityContextHolder.getContext().getAuthentication();
    int result = super.vote(securityContextAuthentication, fi, attributes);
    if (System.getenv(IAM_SECURITY_PARAMETER) != null) {
        LOG.warn("iam security is disable, enable all access mode is enable");
        return result;
    } else {/*from   ww w . ja  v a2s . c o m*/
        LOG.debug("authentication = {}", ToStringBuilder.reflectionToString(securityContextAuthentication));
        LOG.debug("super vote for : {}", result);
        if (super.ACCESS_GRANTED == result) {
            String requestMethod = fi.getRequest().getMethod().toLowerCase();
            String filterUrl = getFilterUrl(fi.getHttpRequest());
            if (filterUrl == null) {
                return result;
            }
            try {
                CasAuthenticationToken casAuthenticationToken = ((CasAuthenticationToken) securityContextAuthentication);
                LOG.debug("assertion : {}",
                        ToStringBuilder.reflectionToString(casAuthenticationToken.getAssertion()));
                String iamSessionXml = (String) casAuthenticationToken.getAssertion().getAttributes()
                        .get(IAM_SESSION_ATTRIBUTE_KEY);
                LOG.debug("iam session xml == {}", iamSessionXml);
                Session iamSession = sessionCache.getIfPresent(casAuthenticationToken.getKeyHash());
                if (iamSession == null) {
                    Unmarshaller unmarshaller = null;
                    try {
                        unmarshaller = context.createUnmarshaller();
                    } catch (JAXBException ex) {
                        LOG.warn("cannot create unmarshaller : ", ex);
                    }
                    iamSession = (Session) unmarshaller.unmarshal(new StringReader(iamSessionXml));
                    sessionCache.put(casAuthenticationToken.getKeyHash(), iamSession);
                }
                StringBuilder sessionPermissionKeyBuilder = new StringBuilder(iamSession.getSessionId())
                        .append(filterUrl).append(requestMethod);
                Boolean isAllowed = accessCache.getIfPresent(sessionPermissionKeyBuilder.toString());
                if (isAllowed == null) {
                    isAllowed = accessManager.checkAccess(iamSession, new Permission(filterUrl, requestMethod));
                    accessCache.put(sessionPermissionKeyBuilder.toString(), isAllowed);
                }
                LOG.debug("{} is {} to access {} with method {}",
                        new Object[] { securityContextAuthentication.getName(),
                                isAllowed ? "granted" : "denied", filterUrl, requestMethod });
                if (isAllowed) {
                    return super.ACCESS_GRANTED;
                }
            } catch (Exception e) {
                LOG.error("catch exception when communicate with iam server", e);
            }
        }
        return super.ACCESS_DENIED;
    }
}

From source file:bizo.common.vo.MemberVo.java

public String toString() {
    return ToStringBuilder.reflectionToString(this);
}

From source file:net.sf.appstatus.batch.jdbc.JdbcBatchProgressMonitor.java

private void updateDb(boolean force) {

    if (force || isLoggable(lastDbSave)) {
        try {//from  www .  j  a  v  a 2  s  .  co m
            lastDbSave = System.currentTimeMillis();
            getBatch().getBdBatch().setStatus(readableStatus());

            // Current Item. 
            String dbCurrentItem = null;
            if (currentItem != null) {
                //Convert to string and ensure max size.
                String toString = currentItem.toString();
                dbCurrentItem = toString.substring(0, Math.min(254, toString.length()));
            }
            getBatch().getBdBatch().setCurrentItem(dbCurrentItem);

            if (!org.apache.commons.lang3.StringUtils.isEmpty(getMainMonitor().getLastMessage())
                    && getMainMonitor().getLastMessage().length() > 1024) {
                getBatch().getBdBatch().setLastMessage(getMainMonitor().getLastMessage().substring(0, 1023));
            } else {
                getBatch().getBdBatch().setLastMessage(getMainMonitor().getLastMessage());
            }
            getBatch().getBdBatch().setStartDate(getMainMonitor().getStartDate());
            getBatch().getBdBatch().setEndDate(getMainMonitor().getEndDate());
            getBatch().getBdBatch().setCurrentTask(taskName);
            getBatch().getBdBatch().setProgress(getMainMonitor().getProgress() == -1f ? -1
                    : getMainMonitor().getProgress() * 100f / getMainMonitor().getTotalWork());
            getBatch().getBdBatch().setLastUpdate(getMainMonitor().getLastUpdate());
            getBatch().getBdBatch().setSuccess(getMainMonitor().isSuccess());
            getBatch().getBdBatch().setReject(
                    StringUtils.collectionToDelimitedString(getMainMonitor().getRejectedItems(), "|"));
            getBatch().getBdBatch().setItemCount(getMainMonitor().getItemCount());
            batchDao.update(getBatch().getBdBatch());
        } catch (Exception e) {
            getLogger().error("Error when updating batch table {}",
                    ToStringBuilder.reflectionToString(getBatch().getBdBatch()), e);
        }
    }
}

From source file:com.replaymod.replaystudio.io.ReplayOutputStream.java

/**
 * Writes the specified packet data to the underlying output stream.
 * @param time The timestamp//from  ww  w. j  a  v a 2 s  .  co  m
 * @param packet The packet
 * @throws IOException - if an I/O error occurs.
 *      In particular, an IOException may be thrown if the output stream has been closed.
 * @see #write(PacketData)
 */
public void write(long time, Packet packet) throws IOException {
    if (duration < time) {
        duration = (int) time;
    }

    ByteBuf encoded = ALLOC.buffer();
    try {
        codec.encode(null, packet, encoded);
    } catch (Exception e) {
        throw new EncoderException(ToStringBuilder.reflectionToString(packet), e);
    }

    ByteBuf compressed;
    if (compression == null) {
        compressed = encoded;
    } else {
        compressed = ALLOC.buffer();
        try {
            compression.encode(null, encoded, compressed);
        } catch (Exception e) {
            throw new EncoderException(ToStringBuilder.reflectionToString(packet), e);
        }
        encoded.release();
    }

    int length = compressed.readableBytes();
    writeInt(out, (int) time);
    writeInt(out, length);
    compressed.readBytes(out, length);

    compressed.release();

    if (packet instanceof ServerSetCompressionPacket) {
        int threshold = ((ServerSetCompressionPacket) packet).getThreshold();
        if (threshold == -1) {
            compression = null;
        } else {
            compression = new StudioCompression(session);
            session.setCompressionThreshold(threshold);
        }
    }
}

From source file:com.kingen.service.org.OrgService.java

private void saveActivitiUser(User user) {
    org.activiti.engine.identity.User activitiUser = identityService.createUserQuery().userId(user.getUserId())
            .singleResult();//  ww  w  .j  a  v  a  2s.  c  o  m
    if (activitiUser == null) {
        activitiUser = identityService.newUser(user.getUserId());
    }
    activitiUser.setFirstName(user.getUsername());
    activitiUser.setLastName(user.getUsername());
    activitiUser.setEmail("");
    activitiUser.setPassword(user.getPassword());
    identityService.saveUser(activitiUser);
    logger.info("add activiti user: {}" + ToStringBuilder.reflectionToString(activitiUser));
}

From source file:com.kingen.service.account.AccountService.java

/**
 * / Activiti {@link org.activiti.engine.identity.User}
 * @param user  , {@link User}/*w w w.  ja  v a  2s  .  com*/
 */
//private ??
private void saveActivitiUser(User user) {
    org.activiti.engine.identity.User activitiUser = identityService.createUserQuery().userId(user.getUserId())
            .singleResult();
    if (activitiUser == null) {
        activitiUser = identityService.newUser(user.getUserId());
    }
    activitiUser.setFirstName(user.getUsername());
    activitiUser.setLastName(user.getUsername());
    activitiUser.setEmail("");
    activitiUser.setPassword(user.getPassword());
    identityService.saveUser(activitiUser);
    logger.info("add activiti user: {}" + ToStringBuilder.reflectionToString(activitiUser));
}