Search in sources :

Example 1 with GenericExceptionHandler

use of com.haulmont.cuba.gui.exception.GenericExceptionHandler in project cuba by cuba-platform.

the class ExceptionHandlers method createByConfiguration.

/**
 * Create all handlers defined by <code>ExceptionHandlersConfiguration</code> beans in spring.xml and
 * GUI handlers defined as Spring-beans.
 */
public void createByConfiguration() {
    removeAll();
    // Desktop handlers
    Map<String, ExceptionHandlersConfiguration> map = AppBeans.getAll(ExceptionHandlersConfiguration.class);
    // Project-level handlers must run before platform-level
    List<ExceptionHandlersConfiguration> configurations = new ArrayList<>(map.values());
    Collections.reverse(configurations);
    for (ExceptionHandlersConfiguration conf : configurations) {
        for (Class aClass : conf.getHandlerClasses()) {
            try {
                handlers.add(ReflectionHelper.<ExceptionHandler>newInstance(aClass));
            } catch (NoSuchMethodException e) {
                log.error("Unable to instantiate " + aClass, e);
            }
        }
    }
    // GUI handlers
    Map<String, GenericExceptionHandler> handlerMap = AppBeans.getAll(GenericExceptionHandler.class);
    List<GenericExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
    Collections.sort(handlers, new OrderComparator());
    for (GenericExceptionHandler handler : handlers) {
        addHandler(handler);
    }
}
Also used : GenericExceptionHandler(com.haulmont.cuba.gui.exception.GenericExceptionHandler) OrderComparator(org.springframework.core.OrderComparator)

Example 2 with GenericExceptionHandler

use of com.haulmont.cuba.gui.exception.GenericExceptionHandler in project cuba by cuba-platform.

the class ExceptionHandlers method createByConfiguration.

/**
 * Create all Web handlers defined by <code>ExceptionHandlersConfiguration</code> beans in spring.xml and
 * GUI handlers defined as Spring-beans.
 */
public void createByConfiguration() {
    removeAll();
    // Web handlers
    Map<String, ExceptionHandlersConfiguration> map = AppBeans.getAll(ExceptionHandlersConfiguration.class);
    // Project-level handlers must run before platform-level
    List<ExceptionHandlersConfiguration> configurations = new ArrayList<>(map.values());
    Collections.reverse(configurations);
    for (ExceptionHandlersConfiguration conf : configurations) {
        for (Class aClass : conf.getHandlerClasses()) {
            try {
                addHandler(ReflectionHelper.<ExceptionHandler>newInstance(aClass));
            } catch (NoSuchMethodException e) {
                log.error("Unable to instantiate {}", aClass, e);
            }
        }
    }
    // GUI handlers
    Map<String, GenericExceptionHandler> handlerMap = AppBeans.getAll(GenericExceptionHandler.class);
    List<GenericExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
    handlers.sort(new OrderComparator());
    for (GenericExceptionHandler handler : handlers) {
        addHandler(handler);
    }
}
Also used : GenericExceptionHandler(com.haulmont.cuba.gui.exception.GenericExceptionHandler) OrderComparator(org.springframework.core.OrderComparator)

Example 3 with GenericExceptionHandler

use of com.haulmont.cuba.gui.exception.GenericExceptionHandler in project cuba by cuba-platform.

the class ExceptionHandlers method handle.

/**
 * Delegates exception handling to registered handlers.
 * @param event error event generated by Vaadin
 */
public void handle(ErrorEvent event) {
    for (ExceptionHandler handler : handlers) {
        if (handler.handle(event, app))
            return;
    }
    WebWindowManager wm = app.getWindowManager();
    if (wm != null) {
        for (GenericExceptionHandler handler : genericHandlers) {
            if (handler.handle(event.getThrowable(), wm))
                return;
        }
    }
    defaultHandler.handle(event, app);
}
Also used : GenericExceptionHandler(com.haulmont.cuba.gui.exception.GenericExceptionHandler) WebWindowManager(com.haulmont.cuba.web.WebWindowManager) GenericExceptionHandler(com.haulmont.cuba.gui.exception.GenericExceptionHandler)

Aggregations

GenericExceptionHandler (com.haulmont.cuba.gui.exception.GenericExceptionHandler)3 OrderComparator (org.springframework.core.OrderComparator)2 WebWindowManager (com.haulmont.cuba.web.WebWindowManager)1