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

com.soento.core.exception.ServiceException Maven / Gradle / Ivy

package com.soento.core.exception;

import com.soento.core.lang.Message;
import com.soento.core.support.MessageSourceAccessor;

/**
 * @author soento
 */
public class ServiceException extends RuntimeException {
    private Message message;

    public ServiceException() {
        super();
    }

    public ServiceException(Message message) {
        super(message.getMessage());
        this.message = message;
    }

    public ServiceException(Message message, Throwable cause) {
        super(message.getMessage(), cause);
        this.message = message;
    }

    public static ServiceException build(String code, String content) {
        Message message = new Message();
        message.setCode(code);
        message.setContent(content);
        return new ServiceException(message);
    }

    public static ServiceException build(MessageSourceAccessor msa, String code, String... args) {
        Message message = new Message();
        message.setCode(code);
        message.setContent(msa.getMessage(code, args));
        return new ServiceException(message);
    }

    public static ServiceException build(Throwable cause, String code, String content) {
        Message message = new Message();
        message.setCode(code);
        message.setContent(content);
        return new ServiceException(message, cause);
    }

    public static ServiceException build(Throwable cause, MessageSourceAccessor msa, String code, String... args) {
        Message message = new Message();
        message.setCode(code);
        message.setContent(msa.getMessage(code, args));
        return new ServiceException(message, cause);
    }

    public Message message() {
        return message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy