Search in sources :

Example 1 with UiExceptionHandler

use of com.haulmont.cuba.gui.exception.UiExceptionHandler 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, UiExceptionHandler> handlerMap = AppBeans.getAll(UiExceptionHandler.class);
    List<UiExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
    Collections.sort(handlers, new OrderComparator());
    for (UiExceptionHandler handler : handlers) {
        addHandler(handler);
    }
}
Also used : UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) OrderComparator(org.springframework.core.OrderComparator)

Example 2 with UiExceptionHandler

use of com.haulmont.cuba.gui.exception.UiExceptionHandler 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;
        }
    }
    AppUI ui = app.getAppUI();
    if (ui != null) {
        for (UiExceptionHandler handler : genericHandlers) {
            if (handler.handle(event.getThrowable(), ui)) {
                return;
            }
        }
    }
    defaultHandler.handle(event, app);
}
Also used : UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) AppUI(com.haulmont.cuba.web.AppUI)

Example 3 with UiExceptionHandler

use of com.haulmont.cuba.gui.exception.UiExceptionHandler 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 = beanLocator.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 {
                ExceptionHandler handler = ReflectionHelper.<ExceptionHandler>newInstance(aClass);
                if (handler instanceof BeanLocatorAware) {
                    ((BeanLocatorAware) handler).setBeanLocator(beanLocator);
                }
                addHandler(handler);
            } catch (NoSuchMethodException e) {
                log.error("Unable to instantiate {}", aClass, e);
            }
        }
    }
    // GUI handlers
    Map<String, UiExceptionHandler> handlerMap = beanLocator.getAll(UiExceptionHandler.class);
    List<UiExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
    handlers.sort(new OrderComparator());
    for (UiExceptionHandler handler : handlers) {
        addHandler(handler);
    }
}
Also used : ArrayList(java.util.ArrayList) UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) OrderComparator(org.springframework.core.OrderComparator) UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) BeanLocatorAware(com.haulmont.cuba.core.sys.BeanLocatorAware)

Aggregations

UiExceptionHandler (com.haulmont.cuba.gui.exception.UiExceptionHandler)3 OrderComparator (org.springframework.core.OrderComparator)2 BeanLocatorAware (com.haulmont.cuba.core.sys.BeanLocatorAware)1 AppUI (com.haulmont.cuba.web.AppUI)1 ArrayList (java.util.ArrayList)1