public static boolean isCaller ( final String className , final String methodName ) { final Throwable throwable = new Throwable ( ) ; final StackTraceElement [ ] stackElements = throwable . getStackTrace ( ) ; if ( null == stackElements ) { LOGGER . log ( Level . WARN , "Empty call stack" ) ; return false ; } final boolean matchAllMethod = "*" . equals ( methodName ) ; for ( int i = 1 ; i < stackElements . length ; i ++ ) { if ( stackElements [ i ] . getClassName ( ) . equals ( className ) ) { return matchAllMethod ? true : stackElements [ i ] . getMethodName ( ) . equals ( methodName ) ; } } return false ; }
Checks the current method is whether invoked by a caller specified by the given class name and method name .