public Object invoke ( String methodName , Object ... args ) throws ReflectorException { if ( object == null ) { logger . error ( "object is null: did you specify it using the 'inspect()' method?" ) ; throw new ReflectorException ( "object is null: did you specify it using the 'inspect()' method?" ) ; } if ( ! Strings . isValid ( methodName ) ) { logger . error ( "method name is null or not valid" ) ; throw new ReflectorException ( "method name is null or not valid" ) ; } Method method = null ; Object result = null ; boolean needReprotect = false ; try { method = object . getClass ( ) . getMethod ( methodName ) ; if ( accessPrivateMembers ) { needReprotect = unprotect ( method ) ; } result = method . invoke ( object , args ) ; } catch ( Exception e ) { logger . error ( "error invoking method '" + methodName + "'" , e ) ; throw new ReflectorException ( "error invoking method '" + methodName + "'" , e ) ; } finally { if ( needReprotect ) { protect ( method ) ; } } return result ; }
Invokes a method on the object under inspection .