View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  /**
17   * Builder for {@link ThrowableProxyVO} that instantiates an instance and
18   * populates its fields one by one.
19   *
20   * <p>Use this when assembling a {@link ThrowableProxyVO} from individual
21   * values. To copy an existing {@link IThrowableProxy}, prefer
22   * {@link ThrowableProxyVO#build(IThrowableProxy)}.</p>
23   *
24   * <p>Typical usage:</p>
25   * <pre>
26   * ThrowableProxyVO vo = ThrowableProxyVO.builder()
27   *     .setClassName("java.lang.RuntimeException")
28   *     .setMessage("boom")
29   *     .setStackTraceElementProxyArray(steps)
30   *     .build();
31   * </pre>
32   *
33   * @author Ceki G&uuml;lc&uuml;
34   * @since 1.6.2
35   * @see ThrowableProxyVO#build(IThrowableProxy)
36   */
37  public class ThrowableProxyVOBuilder {
38  
39      private final ThrowableProxyVO throwableProxyVO;
40  
41      public ThrowableProxyVOBuilder() {
42          this.throwableProxyVO = new ThrowableProxyVO();
43      }
44  
45      public ThrowableProxyVOBuilder setClassName(String className) {
46          throwableProxyVO.setClassName(className);
47          return this;
48      }
49  
50      public ThrowableProxyVOBuilder setMessage(String message) {
51          throwableProxyVO.setMessage(message);
52          return this;
53      }
54  
55      public ThrowableProxyVOBuilder setOverridingMessage(String overridingMessage) {
56          throwableProxyVO.setOverridingMessage(overridingMessage);
57          return this;
58      }
59  
60      public ThrowableProxyVOBuilder setCommonFramesCount(int commonFramesCount) {
61          throwableProxyVO.setCommonFramesCount(commonFramesCount);
62          return this;
63      }
64  
65      public ThrowableProxyVOBuilder setStackTraceElementProxyArray(
66              StackTraceElementProxy[] stackTraceElementProxyArray) {
67          throwableProxyVO.setStackTraceElementProxyArray(stackTraceElementProxyArray);
68          return this;
69      }
70  
71      public ThrowableProxyVOBuilder setCause(IThrowableProxy cause) {
72          throwableProxyVO.setCause(cause);
73          return this;
74      }
75  
76      public ThrowableProxyVOBuilder setSuppressed(IThrowableProxy[] suppressed) {
77          throwableProxyVO.setSuppressed(suppressed);
78          return this;
79      }
80  
81      public ThrowableProxyVOBuilder setCyclic(boolean cyclic) {
82          throwableProxyVO.setCyclic(cyclic);
83          return this;
84      }
85  
86      /**
87       * Returns the constructed {@link ThrowableProxyVO} instance.
88       *
89       * @return the value object with fields set so far
90       */
91      public ThrowableProxyVO build() {
92          return throwableProxyVO;
93      }
94  }