View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 v1.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  public class EventArgUtil {
17  
18      public static final Throwable extractThrowable(Object[] argArray) {
19          if (argArray == null || argArray.length == 0) {
20              return null;
21          }
22  
23          final Object lastEntry = argArray[argArray.length - 1];
24          if (lastEntry instanceof Throwable) {
25              return (Throwable) lastEntry;
26          }
27          return null;
28      }
29  
30      /**
31       * This method should be called only if {@link #successfulExtraction(Throwable)} returns true.
32       *
33       * @param argArray
34       * @return
35       */
36      public static Object[] trimmedCopy(Object[] argArray) {
37          if (argArray == null || argArray.length == 0) {
38              throw new IllegalStateException("non-sensical empty or null argument array");
39          }
40          final int trimemdLen = argArray.length - 1;
41          Object[] trimmed = new Object[trimemdLen];
42          System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
43          return trimmed;
44      }
45  
46      public static Object[] arrangeArguments(Object[] argArray) {
47          return argArray;
48      }
49  
50      public static boolean successfulExtraction(Throwable throwable) {
51          return throwable != null;
52      }
53  }