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)}
32       * returns true.
33       *
34       * @param argArray
35       * @return
36       */
37      public static Object[] trimmedCopy(Object[] argArray) {
38          if (argArray == null || argArray.length == 0) {
39              throw new IllegalStateException("non-sensical empty or null argument array");
40          }
41          final int trimemdLen = argArray.length - 1;
42          Object[] trimmed = new Object[trimemdLen];
43          System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
44          return trimmed;
45      }
46  
47      public static Object[] arrangeArguments(Object[] argArray) {
48          return argArray;
49      }
50  
51      public static boolean successfulExtraction(Throwable throwable) {
52          return throwable != null;
53      }
54  }