public void prepare ( ) throws ClassNotFoundException , NoSuchMethodException { if ( this . staticMethod != null ) { int lastDotIndex = this . staticMethod . lastIndexOf ( ' ' ) ; if ( lastDotIndex == - 1 || lastDotIndex == this . staticMethod . length ( ) ) { throw new IllegalArgumentException ( "staticMethod must be a fully qualified class plus method name: " + "e.g. 'example.MyExampleClass.myExampleMethod'" ) ; } String className = this . staticMethod . substring ( 0 , lastDotIndex ) ; String methodName = this . staticMethod . substring ( lastDotIndex + 1 ) ; this . targetClass = resolveClassName ( className ) ; this . targetMethod = methodName ; } Class < ? > targetClass = getTargetClass ( ) ; String targetMethod = getTargetMethod ( ) ; if ( targetClass == null ) { throw new IllegalArgumentException ( "Either 'targetClass' or 'targetObject' is required" ) ; } if ( targetMethod == null ) { throw new IllegalArgumentException ( "Property 'targetMethod' is required" ) ; } Object [ ] arguments = getArguments ( ) ; Class < ? > [ ] argTypes = new Class < ? > [ arguments . length ] ; for ( int i = 0 ; i < arguments . length ; ++ i ) { argTypes [ i ] = ( arguments [ i ] != null ? arguments [ i ] . getClass ( ) : Object . class ) ; } // Try to get the exact method first. try { this . methodObject = targetClass . getMethod ( targetMethod , argTypes ) ; } catch ( NoSuchMethodException ex ) { // Just rethrow exception if we can't get any match. this . methodObject = findMatchingMethod ( ) ; if ( this . methodObject == null ) { throw ex ; } } }
Prepare the specified method . The method can be invoked any number of times afterwards .