protected void configureMethodArgs ( Injector injector ) { Class < ? > [ ] types = method . getParameterTypes ( ) ; extractors = new ArgumentExtractor [ types . length ] ; patterns = new String [ types . length ] ; for ( int i = 0 ; i < types . length ; i ++ ) { final Parameter parameter = method . getParameters ( ) [ i ] ; final Class < ? extends Collection > collectionType ; final Class < ? > objectType ; if ( Collection . class . isAssignableFrom ( types [ i ] ) ) { collectionType = ( Class < ? extends Collection > ) types [ i ] ; objectType = getParameterGenericType ( parameter ) ; } else { collectionType = null ; objectType = types [ i ] ; } // determine the appropriate extractor Class < ? extends ArgumentExtractor > extractorType ; if ( FileItem . class == objectType ) { extractorType = FileItemExtractor . class ; } else { extractorType = ControllerUtil . getArgumentExtractor ( parameter ) ; } // instantiate the extractor extractors [ i ] = injector . getInstance ( extractorType ) ; // configure the extractor if ( extractors [ i ] instanceof ConfigurableExtractor < ? > ) { ConfigurableExtractor extractor = ( ConfigurableExtractor ) extractors [ i ] ; Annotation annotation = ClassUtil . getAnnotation ( parameter , extractor . getAnnotationClass ( ) ) ; if ( annotation != null ) { extractor . configure ( annotation ) ; } } if ( extractors [ i ] instanceof SuffixExtractor ) { // the last parameter can be assigned content type suffixes SuffixExtractor extractor = ( SuffixExtractor ) extractors [ i ] ; extractor . setSuffixes ( contentTypeSuffixes ) ; } if ( collectionType != null ) { if ( extractors [ i ] instanceof CollectionExtractor ) { CollectionExtractor extractor = ( CollectionExtractor ) extractors [ i ] ; extractor . setCollectionType ( collectionType ) ; } else { throw new FatalException ( "Controller method '{}' parameter {} of type '{}' does not specify an argument extractor that supports collections!" , Util . toString ( method ) , i + 1 , Util . toString ( collectionType , objectType ) ) ; } } if ( extractors [ i ] instanceof TypedExtractor ) { TypedExtractor extractor = ( TypedExtractor ) extractors [ i ] ; extractor . setObjectType ( objectType ) ; } if ( extractors [ i ] instanceof NamedExtractor ) { // ensure that the extractor has a proper name NamedExtractor namedExtractor = ( NamedExtractor ) extractors [ i ] ; if ( Strings . isNullOrEmpty ( namedExtractor . getName ( ) ) ) { // parameter is not named via annotation // try looking for the parameter name in the compiled .class file if ( parameter . isNamePresent ( ) ) { namedExtractor . setName ( parameter . getName ( ) ) ; } else { log . error ( "Properly annotate your controller methods OR specify the '-parameters' flag for your Java compiler!" ) ; throw new FatalException ( "Controller method '{}' parameter {} of type '{}' does not specify a name!" , Util . toString ( method ) , i + 1 , Util . toString ( collectionType , objectType ) ) ; } } } } }
Configures the controller method arguments .