Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj, String nullStr) 

Source Link

Document

Gets the toString of an Object returning a specified text if null input.

 ObjectUtils.toString(null, null)           = null ObjectUtils.toString(null, "null")         = "null" ObjectUtils.toString("", "null")           = "" ObjectUtils.toString("bat", "null")        = "bat" ObjectUtils.toString(Boolean.TRUE, "null") = "true" 

Usage

From source file:org.marketcetera.ors.RequestHandler.java

private void receiveMessageOrderEnvelope(OrderEnvelope msgEnv) {
    Messages.RH_RECEIVED_MESSAGE.info(this, msgEnv);
    Order msg = null;/*  w  w w.  j av  a2 s  . c om*/
    UserID actorID = null;
    BrokerID bID = null;
    Broker b = null;
    Message qMsg = null;
    Message qMsgToSend = null;
    Message qMsgReply = null;
    boolean responseExpected = false;
    OrderInfo orderInfo = null;
    try {
        // Reject null message envelopes.
        if (msgEnv == null) {
            throw new I18NException(Messages.RH_NULL_MESSAGE_ENVELOPE);
        }
        ThreadedMetric.begin(
                (msgEnv.getOrder() instanceof OrderBase) ? ((OrderBase) msgEnv.getOrder()).getOrderID() : null);
        // Reject null messages.

        msg = msgEnv.getOrder();
        if (msg == null) {
            throw new I18NException(Messages.RH_NULL_MESSAGE);
        }

        // Reject invalid sessions.

        SessionInfo sessionInfo = getUserManager().getSessionInfo(msgEnv.getSessionId());
        if (sessionInfo == null) {
            throw new I18NException(new I18NBoundMessage1P(Messages.RH_SESSION_EXPIRED, msgEnv.getSessionId()));
        }
        actorID = (UserID) sessionInfo.getValue(SessionInfo.ACTOR_ID);
        RequestInfo requestInfo = new RequestInfoImpl(sessionInfo);
        ThreadedMetric.event("requestHandler.sessionInfoObtained"); //$NON-NLS-1$

        // Reject messages of unsupported types.

        if (!(msg instanceof OrderSingle) && !(msg instanceof OrderCancel) && !(msg instanceof OrderReplace)
                && !(msg instanceof FIXOrder)) {
            throw new I18NException(Messages.RH_UNSUPPORTED_MESSAGE);
        }
        Order oMsg = (Order) msg;

        // Identify broker.

        bID = oMsg.getBrokerID();
        if (bID == null) {
            bID = getSelector().chooseBroker(oMsg);
        }
        if (bID == null) {
            throw new I18NException(Messages.RH_UNKNOWN_BROKER);
        }
        requestInfo.setValue(RequestInfo.BROKER_ID, bID);

        // Ensure broker ID maps to existing broker.

        b = getBrokers().getBroker(bID);
        if (b == null) {
            throw new I18NException(Messages.RH_UNKNOWN_BROKER_ID);
        }
        requestInfo.setValue(RequestInfo.BROKER, b);
        requestInfo.setValue(RequestInfo.FIX_MESSAGE_FACTORY, b.getFIXMessageFactory());
        ThreadedMetric.event("requestHandler.brokerSelected"); //$NON-NLS-1$

        // Convert to a QuickFIX/J message.

        try {
            qMsg = FIXConverter.toQMessage(b.getFIXMessageFactory(), b.getDataDictionary(), oMsg);
        } catch (I18NException ex) {
            throw new I18NException(ex, Messages.RH_CONVERSION_FAILED);
        }
        orderInfo = getPersister().addOutgoingOrder(qMsg, actorID);
        b.logMessage(qMsg);
        ThreadedMetric.event("requestHandler.orderConverted"); //$NON-NLS-1$

        // Ensure broker is available.

        if (!b.getLoggedOn()) {
            throw new I18NException(Messages.RH_UNAVAILABLE_BROKER);
        }

        // Ensure the order is allowed.

        try {
            getAllowedOrders().assertAccepted(qMsg);
        } catch (CoreException ex) {
            throw new I18NException(ex, Messages.RH_ORDER_DISALLOWED);
        }
        ThreadedMetric.event("requestHandler.orderAllowed"); //$NON-NLS-1$

        // Apply message modifiers.

        if (b.getModifiers() != null) {
            requestInfo.setValue(RequestInfo.CURRENT_MESSAGE, qMsg);
            try {
                b.getModifiers().modifyMessage(requestInfo);
            } catch (I18NException ex) {
                throw new I18NException(ex, Messages.RH_MODIFICATION_FAILED);
            }
            qMsg = requestInfo.getValueIfInstanceOf(RequestInfo.CURRENT_MESSAGE, Message.class);
        }
        ThreadedMetric.event("requestHandler.modifiersApplied"); //$NON-NLS-1$

        // Apply order routing.

        if (b.getRoutes() != null) {
            try {
                b.getRoutes().modifyMessage(qMsg, b.getFIXMessageAugmentor());
            } catch (I18NException ex) {
                throw new I18NException(ex, Messages.RH_ROUTING_FAILED);
            }
        }
        ThreadedMetric.event("requestHandler.orderRoutingApplied"); //$NON-NLS-1$

        // Apply pre-sending message modifiers.

        if (b.getPreSendModifiers() != null) {
            qMsgToSend = (Message) qMsg.clone();
            requestInfo.setValue(RequestInfo.CURRENT_MESSAGE, qMsgToSend);
            try {
                try {
                    b.getPreSendModifiers().modifyMessage(requestInfo);
                } catch (I18NException ex) {
                    throw new I18NException(ex, Messages.RH_PRE_SEND_MODIFICATION_FAILED);
                }
                qMsgToSend = requestInfo.getValueIfInstanceOf(RequestInfo.CURRENT_MESSAGE, Message.class);
            } finally {
                requestInfo.setValue(RequestInfo.CURRENT_MESSAGE, qMsg);
            }
        } else {
            qMsgToSend = qMsg;
        }
        ThreadedMetric.event("requestHandler.preSendModifiersApplied"); //$NON-NLS-1$

        // Send message to QuickFIX/J.

        try {
            getSender().sendToTarget(qMsgToSend, b.getSessionID());
        } catch (SessionNotFound ex) {
            throw new I18NException(ex, Messages.RH_UNAVAILABLE_BROKER);
        }
        responseExpected = true;
        ThreadedMetric.event("requestHandler.orderSent"); //$NON-NLS-1$

        // Compose ACK execution report (with pending status).

        try {
            qMsgReply = createExecutionReport(b, qMsg);
            if (qMsgReply == null) {
                Messages.RH_ACK_FAILED_WARN.warn(this, msg, qMsg, b.toString());
            }
        } catch (FieldNotFound ex) {
            throw new I18NException(ex, Messages.RH_ACK_FAILED);
        } catch (CoreException ex) {
            throw new I18NException(ex, Messages.RH_ACK_FAILED);
        }
    } catch (I18NException ex) {
        Messages.RH_MESSAGE_PROCESSING_FAILED.error(this, ex, msg, qMsg, qMsgToSend,
                ObjectUtils.toString(b, ObjectUtils.toString(bID)));
        qMsgReply = createRejection(ex, b, msg);
    } finally {
        if (orderInfo != null) {
            orderInfo.setResponseExpected(responseExpected);
        }
    }
    ThreadedMetric.event("requestHandler.replyComposed"); //$NON-NLS-1$

    boolean msgAckExpected = false;
    Principals principals;
    try {

        // If the reply could not be created, we are done (a
        // warning/error has already been reported).

        if (qMsgReply == null) {
            return;
        }
        if (SLF4JLoggerProxy.isDebugEnabled(this)) {
            Messages.RH_ANALYZED_MESSAGE.debug(this,
                    new AnalyzedMessage(getBestDataDictionary(b), qMsgReply).toString());
        }

        // Convert reply to FIX Agnostic messsage.

        principals = getPersister().getPrincipals(qMsgReply, true);
        msgAckExpected = true;
        ThreadedMetric.event("requestHandler.principalsFetched"); //$NON-NLS-1$
    } finally {
        if (orderInfo != null) {
            orderInfo.setAckExpected(msgAckExpected);
        }
    }

    TradeMessage reply;
    try {
        reply = FIXConverter.fromQMessage(qMsgReply, Originator.Server, bID, principals.getActorID(),
                principals.getViewerID());
    } catch (MessageCreationException ex) {
        Messages.RH_REPORT_FAILED.error(this, ex, qMsgReply);
        return;
    }
    ThreadedMetric.event("requestHandler.replyConverted"); //$NON-NLS-1$

    // Persist and send reply.

    getPersister().persistReply(reply);
    Messages.RH_SENDING_REPLY.info(this, reply);
    ThreadedMetric.event("requestHandler.replyPersisted"); //$NON-NLS-1$
    getUserManager().convertAndSend(reply);
    ThreadedMetric.end(METRIC_CONDITION_RH);
}

From source file:org.marketcetera.util.quickfix.AnalyzedField.java

/**
 * Returns the receiver's QuickFIX/J field value in string form.
 *
 * @return The value. It may be null./* w ww . j a  va 2s  .  c  o m*/
 */

public String getQFieldValueAsString() {
    return ObjectUtils.toString(getQFieldValue(), null);
}

From source file:org.openhab.binding.upb.internal.UPBBinding.java

private void parseConfiguration(final Map<String, Object> configuration) {
    port = ObjectUtils.toString(configuration.get("port"), null);
    network = Integer.valueOf(ObjectUtils.toString(configuration.get("network"), "0")).byteValue();

    logger.debug("Parsed UPB configuration:");
    logger.debug("Serial port: {}", port);
    logger.debug("UPB Network: {}", network & 0xff);

}

From source file:org.openmrs.module.simplelabentry.web.taglib.GroupedOrderTag.java

public int doStartTag() {

    StringBuffer sb = new StringBuffer();
    try {//from w  w  w  .  ja va2 s.  c  o  m
        log.debug("In OpenOrderTag");
        SimpleLabEntryService ls = (SimpleLabEntryService) Context.getService(SimpleLabEntryService.class);
        ORDER_STATUS status = "open".equals(limit) ? ORDER_STATUS.CURRENT
                : "closed".equals(limit) ? ORDER_STATUS.COMPLETE : ORDER_STATUS.NOTVOIDED;
        List<Order> openOrders = ls.getLabOrders(null, null, null, status, null);

        log.debug("Found " + openOrders.size() + " open orders.");

        Map<String, Integer> numVal = new HashMap<String, Integer>();
        Map<String, String> groupNameVal = new LinkedHashMap<String, String>();
        Set<String> locations = new TreeSet<String>();

        for (Order o : openOrders) {
            log.debug(o.getStartDate());
            StringBuffer groupName = new StringBuffer();
            groupName.append(ObjectUtils.toString(o.getEncounter().getLocation().getName(), "?") + " ");
            groupName.append(Context.getDateFormat().format(
                    o.getStartDate() != null ? o.getStartDate() : o.getEncounter().getEncounterDatetime())
                    + " ");
            groupName.append(StringUtils.isBlank(o.getConcept().getName().getShortName())
                    ? o.getConcept().getName().getName()
                    : o.getConcept().getName().getShortName());
            locations.add(o.getEncounter().getLocation().getName());
            StringBuffer groupVal = new StringBuffer();
            groupVal.append(ObjectUtils.toString(o.getEncounter().getLocation().getLocationId(), "?") + ".");
            groupVal.append(Context.getDateFormat().format(
                    o.getStartDate() != null ? o.getStartDate() : o.getEncounter().getEncounterDatetime())
                    + ".");
            groupVal.append(o.getConcept().getConceptId());

            if (!groupNameVal.containsKey(groupName.toString()))
                groupNameVal.put(groupName.toString(), groupVal.toString());

            Integer orderCount = numVal.get(groupName.toString());
            if (orderCount == null) {
                orderCount = new Integer(0);
            }
            numVal.put(groupName.toString(), ++orderCount);
        }
        log.debug("Grouped orders = " + groupNameVal);

        sb.append("<select name=\"" + name + "\" " + javascript + "\">");
        sb.append("<option value=\"\"></option>");
        for (String loc : locations) {
            for (String name : groupNameVal.keySet()) {
                if (name.contains(loc)) {
                    String val = groupNameVal.get(name);
                    Integer count = numVal.get(name);
                    sb.append("<option value=\"" + val + "\"" + (val.equals(defaultValue) ? " selected" : "")
                            + ">" + name + " (" + count + ")" + "</option>");
                }
            }
        }
        sb.append("</select>");
    } catch (Exception e) {
        sb = new StringBuffer("ERROR RENDERING TAG");
        log.error("ERROR RENDERING GroupedOrderTag", e);
    }

    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException e) {
        log.error(e);
    }

    return SKIP_BODY;
}