Project

General

Profile

« Previous | Next » 

Revision b5d06161

Added by Andreas Kohlbecker over 5 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
          }
src/main/java/eu/etaxonomy/cdm/vaadin/event/error/ErrorTypeHandler.java
13 13
import com.vaadin.server.ErrorHandler;
14 14

  
15 15
/**
16
 * see {@link DelegatingErrorHandler}
17
 *
16 18
 * @author freimeier
17 19
 * @date 26.02.2018
18 20
 *
19 21
 */
20 22
public abstract class ErrorTypeHandler<E extends Exception> implements ErrorHandler {
21 23

  
24
    private static final long serialVersionUID = 1782060185842059311L;
25

  
22 26
    /* (non-Javadoc)
23 27
     * @see com.vaadin.server.ErrorHandler#error(com.vaadin.server.ErrorEvent)
24 28
     */
src/main/java/eu/etaxonomy/cdm/vaadin/event/error/HibernateSystemErrorHandler.java
23 23
 */
24 24
public class HibernateSystemErrorHandler extends ErrorTypeHandler<HibernateSystemException>{
25 25

  
26
    private static final long serialVersionUID = -5703485298578474572L;
27

  
26 28
    /* (non-Javadoc)
27 29
     * @see eu.etaxonomy.cdm.vaadin.util.errorhandler.ErrorTypeHandler#handleError(com.vaadin.server.ErrorEvent)
28 30
     */

Also available in: Unified diff