public static Class < ? > resolveCaller ( ) { Class < ? > callerClass = null ; StackTraceElement [ ] stackTraces = Thread . currentThread ( ) . getStackTrace ( ) ; int stackSize = stackTraces . length ; // StackTrace is below. So check from 3rd element. // 1st:java.lang.Thread // 2nd:ResourceResolver#resolveCaller(this method) for ( int stackIndex = 2 ; stackIndex < stackSize ; stackIndex ++ ) { StackTraceElement stackTrace = stackTraces [ stackIndex ] ; String callerClassName = stackTrace . getClassName ( ) ; if ( StringUtils . equals ( ResourceResolver . class . getName ( ) , callerClassName ) == false ) { try { callerClass = Class . forName ( callerClassName ) ; break ; } catch ( ClassNotFoundException ex ) { return null ; } } } return callerClass ; }
Return caller class calling this class s method .