001/* 
002 * JKNIV, utils - Helper utilities for jdk code.
003 * 
004 * Copyright (C) 2017, the original author or authors.
005 *
006 * This library is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 2.1 of the License.
010 * 
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with this library; if not, write to the Free Software Foundation, Inc., 
018 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
019 */
020package net.sf.jkniv.exception;
021
022/**
023 *  Helper to handle exceptions at configurable way keeping the code clean.
024 *  
025 * @author Alisson Gomes
026 *
027 */
028public interface HandleableException
029{
030    /**
031     * Mapping {@code root} checked exception to {@code translateTo} unchecked.
032     * 
033     * @param root checked exception expected
034     * @param translateTo translate to another unchecked exception
035     * @param message content of exception
036     * @return a reference to this object.
037     */
038    HandleableException config(Class<? extends Exception> root, Class<? extends RuntimeException> translateTo, String message);
039    
040    /**
041     * Mapping {@code root} checked exception to unchecked, {@code RuntimeException}.
042     * 
043     * @param root checked exception expected
044     * @param message content of exception
045     * @return a reference to this object.
046     */
047    HandleableException config(Class<? extends Exception> root, String message);
048
049    void handle(Exception catched);
050
051    void handle(Exception catched, String message);
052
053    /**
054     * Throw a Default Exception with a specific message using the specified formatted string and arguments. 
055     * @param message a format message, like: {@code can not found method %s for class %s}
056     * @param args Arguments referenced by the format specifiers in the format string.
057     */
058    void throwMessage(String message, Object... args); // TODO unit test
059
060    Class<? extends RuntimeException> getDefaultException();
061
062    HandleableException mute();
063    
064    HandleableException mute(Class<? extends Exception> ex);
065    
066    // TODO implements new methods muteAsWarn, muteAsInfo
067    // TODO implements config exception to rethrow them (just
068    
069    boolean isMute();
070    
071    boolean isMute(Class<? extends Exception> ex);
072    
073    HandleableException logInfoOn();
074
075    HandleableException logInfoOff();
076}