Search in sources :

Example 1 with MapExceptionEntry

use of org.activiti.bpmn.model.MapExceptionEntry in project Activiti by Activiti.

the class ActivitiMapExceptionParser method parseChildElement.

@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!(parentElement instanceof Activity))
        return;
    String errorCode = xtr.getAttributeValue(null, MAP_EXCEPTION_ERRORCODE);
    String andChildren = xtr.getAttributeValue(null, MAP_EXCEPTION_ANDCHILDREN);
    String exceptionClass = xtr.getElementText();
    boolean hasChildrenBool = false;
    if (StringUtils.isEmpty(andChildren) || andChildren.toLowerCase().equals("false")) {
        hasChildrenBool = false;
    } else if (andChildren.toLowerCase().equals("true")) {
        hasChildrenBool = true;
    } else {
        throw new XMLException("'" + andChildren + "' is not valid boolean in mapException with errorCode=" + errorCode + " and class=" + exceptionClass);
    }
    if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(errorCode.trim())) {
        throw new XMLException("No errorCode defined mapException with errorCode=" + errorCode + " and class=" + exceptionClass);
    }
    ((Activity) parentElement).getMapExceptions().add(new MapExceptionEntry(errorCode, exceptionClass, hasChildrenBool));
}
Also used : XMLException(org.activiti.bpmn.exceptions.XMLException) Activity(org.activiti.bpmn.model.Activity) MapExceptionEntry(org.activiti.bpmn.model.MapExceptionEntry)

Example 2 with MapExceptionEntry

use of org.activiti.bpmn.model.MapExceptionEntry in project Activiti by Activiti.

the class ErrorPropagation method mapException.

public static boolean mapException(Exception e, ActivityExecution execution, List<MapExceptionEntry> exceptionMap, boolean wrapped) throws Exception {
    if (exceptionMap == null) {
        return false;
    }
    if (wrapped && e instanceof PvmException) {
        e = (Exception) ((PvmException) e).getCause();
    }
    String defaultMap = null;
    for (MapExceptionEntry me : exceptionMap) {
        String exceptionClass = me.getClassName();
        String errorCode = me.getErrorCode();
        // save the first mapping with no exception class as default map
        if (StringUtils.isNotEmpty(errorCode) && StringUtils.isEmpty(exceptionClass) && defaultMap == null) {
            defaultMap = errorCode;
            continue;
        }
        // ignore if error code or class are not defined
        if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(exceptionClass))
            continue;
        if (e.getClass().getName().equals(exceptionClass)) {
            propagateError(errorCode, execution);
            return true;
        }
        if (me.isAndChildren()) {
            Class<?> exceptionClassClass = ReflectUtil.loadClass(exceptionClass);
            if (exceptionClassClass.isAssignableFrom(e.getClass())) {
                propagateError(errorCode, execution);
                return true;
            }
        }
    }
    if (defaultMap != null) {
        propagateError(defaultMap, execution);
        return true;
    }
    return false;
}
Also used : MapExceptionEntry(org.activiti.bpmn.model.MapExceptionEntry) PvmException(org.activiti.engine.impl.pvm.PvmException)

Aggregations

MapExceptionEntry (org.activiti.bpmn.model.MapExceptionEntry)2 XMLException (org.activiti.bpmn.exceptions.XMLException)1 Activity (org.activiti.bpmn.model.Activity)1 PvmException (org.activiti.engine.impl.pvm.PvmException)1