001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v2.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.spi;
015
016/**
017 * Builder for {@link ThrowableProxyVO} that instantiates an instance and
018 * populates its fields one by one.
019 *
020 * <p>Use this when assembling a {@link ThrowableProxyVO} from individual
021 * values. To copy an existing {@link IThrowableProxy}, prefer
022 * {@link ThrowableProxyVO#build(IThrowableProxy)}.</p>
023 *
024 * <p>Typical usage:</p>
025 * <pre>
026 * ThrowableProxyVO vo = ThrowableProxyVO.builder()
027 *     .setClassName("java.lang.RuntimeException")
028 *     .setMessage("boom")
029 *     .setStackTraceElementProxyArray(steps)
030 *     .build();
031 * </pre>
032 *
033 * @author Ceki G&uuml;lc&uuml;
034 * @since 1.6.2
035 * @see ThrowableProxyVO#build(IThrowableProxy)
036 */
037public class ThrowableProxyVOBuilder {
038
039    private final ThrowableProxyVO throwableProxyVO;
040
041    public ThrowableProxyVOBuilder() {
042        this.throwableProxyVO = new ThrowableProxyVO();
043    }
044
045    public ThrowableProxyVOBuilder setClassName(String className) {
046        throwableProxyVO.setClassName(className);
047        return this;
048    }
049
050    public ThrowableProxyVOBuilder setMessage(String message) {
051        throwableProxyVO.setMessage(message);
052        return this;
053    }
054
055    public ThrowableProxyVOBuilder setOverridingMessage(String overridingMessage) {
056        throwableProxyVO.setOverridingMessage(overridingMessage);
057        return this;
058    }
059
060    public ThrowableProxyVOBuilder setCommonFramesCount(int commonFramesCount) {
061        throwableProxyVO.setCommonFramesCount(commonFramesCount);
062        return this;
063    }
064
065    public ThrowableProxyVOBuilder setStackTraceElementProxyArray(
066            StackTraceElementProxy[] stackTraceElementProxyArray) {
067        throwableProxyVO.setStackTraceElementProxyArray(stackTraceElementProxyArray);
068        return this;
069    }
070
071    public ThrowableProxyVOBuilder setCause(IThrowableProxy cause) {
072        throwableProxyVO.setCause(cause);
073        return this;
074    }
075
076    public ThrowableProxyVOBuilder setSuppressed(IThrowableProxy[] suppressed) {
077        throwableProxyVO.setSuppressed(suppressed);
078        return this;
079    }
080
081    public ThrowableProxyVOBuilder setCyclic(boolean cyclic) {
082        throwableProxyVO.setCyclic(cyclic);
083        return this;
084    }
085
086    /**
087     * Returns the constructed {@link ThrowableProxyVO} instance.
088     *
089     * @return the value object with fields set so far
090     */
091    public ThrowableProxyVO build() {
092        return throwableProxyVO;
093    }
094}