Example usage for org.apache.commons.scxml ErrorReporter onError

List of usage examples for org.apache.commons.scxml ErrorReporter onError

Introduction

In this page you can find the example usage for org.apache.commons.scxml ErrorReporter onError.

Prototype

void onError(String errCode, String errDetail, Object errCtx);

Source Link

Document

Handler for reporting an error.

Usage

From source file:alma.acs.nc.sm.generic.AcsScxmlDispatchingAction.java

public void execute(final EventDispatcher evtDispatcher, final ErrorReporter errRep,
        final SCInstance scInstance, final Log appLog, final Collection derivedEvents)
        throws ModelException, SCXMLExpressionException {

    try {/*www  . j  a  v a2s .co  m*/
        getActionDispatcher(scInstance);
    } catch (Exception ex) {
        errRep.onError(ErrorConstants.UNDEFINED_VARIABLE,
                "Failed to get UserActionDispatcher object from root context.", ex);
    }

    if (disp != null && action != null) {
        // forward the action call to the dispatcher
        disp.execute(action, evtDispatcher, errRep, scInstance, derivedEvents);
    } else {
        errRep.onError(ErrorConstants.UNDEFINED_VARIABLE,
                "Failed to get UserActionDispatcher object from root context.", null);
    }
}

From source file:alma.acs.nc.sm.generic.AcsScxmlActionDispatcher.java

/**
 * Generic action handler, dispatches to the right handler based on action type.
 * <p>/*w  w w  .j  a v  a2  s . co m*/
 * TODO: org.apache.commons.scxml.env.SimpleErrorReporter#onError prints the class name of the "Object errCtx".
 *       Currently we'd get NPE or useless info.
 */
public void execute(A action, final EventDispatcher evtDispatcher, final ErrorReporter errRep,
        final SCInstance scInstance, final Collection<TriggerEvent> derivedEvents)
        throws ModelException, SCXMLExpressionException {
    AcsScxmlActionExecutor<A> handler = getActionHandler(action);
    if (handler != null) {
        boolean handledAction = false;
        try {
            handledAction = handler.execute(action, evtDispatcher, errRep, scInstance, derivedEvents);
        } catch (AcsJStateMachineActionEx ex) {
            handledAction = true;

            if (actionExceptionHandler != null) { // handler is optional
                // ex will be thrown at the user
                actionExceptionHandler.setActionException(ex);
            } else {
                logger.log(Level.WARNING,
                        "Handler " + handler.getClass() + " failed to execute action " + action.name(), ex);
            }

            // TODO: define and fire a standardized internal error event so that the state machine
            // can reflect the problem and can be maneuvered out of the error again by the user 
        }
        if (!handledAction) {
            errRep.onError(ErrorConstants.UNKNOWN_ACTION,
                    "Handler " + handler.getClass() + " handler unexpectedly did not handle action ", action);
        }
    } else {
        errRep.onError(ErrorConstants.UNKNOWN_ACTION, "No handler registered for action " + action.name(),
                null);
    }
}