Project

General

Profile

« Previous | Next » 

Revision b5d06161

Added by Andreas Kohlbecker about 6 years ago

ref #7241 documentation, adding serial ids, fixing logging

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/event/error/DelegatingErrorHandler.java
12 12
import java.util.HashMap;
13 13
import java.util.Map;
14 14

  
15
import org.apache.log4j.Logger;
16

  
15 17
import com.vaadin.server.ErrorEvent;
16 18
import com.vaadin.server.ErrorHandler;
17 19
import com.vaadin.ui.Notification;
18 20

  
19 21
/**
22
 * Vaadin allows setting an com.vaadin.server.ErrorHandler for UIs and components.
23
 * The caveat with this built in approach is that there is only one {@link com.vaadin.server.ErrorHandler}
24
 * for any type of errors. This <code>DelegatingErrorHandler</code> allows registering handlers for specific types of errors.
25
 *
26
 * see https://dev.e-taxonomy.eu/redmine/issues/7241
27
 *
20 28
 * @author freimeier
21 29
 * @date 26.02.2018
22 30
 *
23 31
 */
24 32
public class DelegatingErrorHandler implements ErrorHandler{
33

  
34
    private static final long serialVersionUID = 3378605204517477112L;
35

  
25 36
    Map<Class<? extends Exception>, ErrorTypeHandler<? extends Exception>> handlerMap = new HashMap<>();
26 37

  
27 38
    public <E extends Exception> void  registerHandler(Class<E> type, ErrorTypeHandler<E> handler) {
......
33 44
     */
34 45
    @Override
35 46
    public void error(ErrorEvent event) {
36
        System.out.println(event.getThrowable().getCause().getClass());
37
        Throwable cause = event.getThrowable().getCause();
38
        if(handlerMap.get(cause.getClass()) != null){
39
            handlerMap.get(cause.getClass()).error(event);
47

  
48
        Class<? extends Throwable> errorClass = event.getThrowable().getCause().getClass();
49
        Logger.getLogger(this.getClass()).debug(errorClass);
50
        if(handlerMap.get(errorClass) != null){
51
            handlerMap.get(errorClass).error(event);
40 52
          } else {
41 53
            Notification.show(event.getThrowable().getMessage());
42 54
          }

Also available in: Unified diff