All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.yourinspiration.jexpresso.exception.ExceptionHandlerEntry Maven / Gradle / Ivy

Go to download

A java web framework inspired by expressjs to build java web application with minimal effort

There is a newer version: 1.4.2
Show newest version
package de.yourinspiration.jexpresso.exception;

import de.yourinspiration.jexpresso.core.Request;
import de.yourinspiration.jexpresso.core.Response;
import de.yourinspiration.jexpresso.core.RouteHandler;

/**
 * Aggregates the information for exception callback handlers.
 *
 * @author Marcel Härle
 */
public class ExceptionHandlerEntry {

    private final Class exceptionClass;
    private final RouteHandler routeHandler;

    /**
     * Constructs a new object.
     *
     * @param exceptionClass the exception class to be handled
     * @param routeHandler   the callback handler
     */
    public ExceptionHandlerEntry(final Class exceptionClass, final RouteHandler routeHandler) {
        this.exceptionClass = exceptionClass;
        this.routeHandler = routeHandler;
    }

    /**
     * Checks if the exception is the of the same class.
     *
     * @param e the exception to be checked
     * @return returns true if the excpetion class is the same
     */
    public boolean isInstanceOf(final Exception e) {
        return e.getClass().equals(exceptionClass);
    }

    /**
     * Invokes the callback handler.
     *
     * @param request  the request
     * @param response the response
     */
    public void invokeHandler(final Request request, final Response response) {
        routeHandler.handle(request, response);
    }

    @Override
    public String toString() {
        return "[exceptionClass=" + exceptionClass.getName() + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy