001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, 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 v1.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 016public class EventArgUtil { 017 018 public static final Throwable extractThrowable(Object[] argArray) { 019 if (argArray == null || argArray.length == 0) { 020 return null; 021 } 022 023 final Object lastEntry = argArray[argArray.length - 1]; 024 if (lastEntry instanceof Throwable) { 025 return (Throwable) lastEntry; 026 } 027 return null; 028 } 029 030 /** 031 * This method should be called only if {@link #successfulExtraction(Throwable)} 032 * returns true. 033 * 034 * @param argArray 035 * @return 036 */ 037 public static Object[] trimmedCopy(Object[] argArray) { 038 if (argArray == null || argArray.length == 0) { 039 throw new IllegalStateException("non-sensical empty or null argument array"); 040 } 041 final int trimemdLen = argArray.length - 1; 042 Object[] trimmed = new Object[trimemdLen]; 043 System.arraycopy(argArray, 0, trimmed, 0, trimemdLen); 044 return trimmed; 045 } 046 047 public static Object[] arrangeArguments(Object[] argArray) { 048 return argArray; 049 } 050 051 public static boolean successfulExtraction(Throwable throwable) { 052 return throwable != null; 053 } 054}