1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2018 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.vaadin.event.error;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
|
15
|
import com.vaadin.server.ErrorEvent;
|
16
|
import com.vaadin.server.ErrorHandler;
|
17
|
import com.vaadin.ui.Notification;
|
18
|
|
19
|
/**
|
20
|
* @author freimeier
|
21
|
* @date 26.02.2018
|
22
|
*
|
23
|
*/
|
24
|
public class DelegatingErrorHandler implements ErrorHandler{
|
25
|
Map<Class<? extends Exception>, ErrorTypeHandler<? extends Exception>> handlerMap = new HashMap<>();
|
26
|
|
27
|
public <E extends Exception> void registerHandler(Class<E> type, ErrorTypeHandler<E> handler) {
|
28
|
handlerMap.put(type, handler);
|
29
|
}
|
30
|
|
31
|
/* (non-Javadoc)
|
32
|
* @see com.vaadin.server.ErrorHandler#error(com.vaadin.server.ErrorEvent)
|
33
|
*/
|
34
|
@Override
|
35
|
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);
|
40
|
} else {
|
41
|
Notification.show(event.getThrowable().getMessage());
|
42
|
}
|
43
|
}
|
44
|
}
|