private static void initMapDefinedHandler ( Map < String , Object > handler ) { // If the handler is a map, the keys are the class name, values are the // parameters. for ( Map . Entry < String , Object > entry : handler . entrySet ( ) ) { Tuple < String , Class > namedClass = splitClassAndName ( entry . getKey ( ) ) ; // If the values in the config are a map, construct the object using named // parameters. if ( entry . getValue ( ) instanceof Map ) { HttpHandler httpHandler ; try { httpHandler = ( HttpHandler ) ServiceUtil . constructByNamedParams ( namedClass . second , ( Map ) entry . getValue ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( "Could not construct a handler with values provided as a map: " + namedClass . second ) ; } registerMiddlewareHandler ( httpHandler ) ; handlers . put ( namedClass . first , httpHandler ) ; handlerListById . put ( namedClass . first , Collections . singletonList ( httpHandler ) ) ; } else if ( entry . getValue ( ) instanceof List ) { // If the values in the config are a list, call the constructor of the handler // with those fields. HttpHandler httpHandler ; try { httpHandler = ( HttpHandler ) ServiceUtil . constructByParameterizedConstructor ( namedClass . second , ( List ) entry . getValue ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( "Could not construct a handler with values provided as a list: " + namedClass . second ) ; } registerMiddlewareHandler ( httpHandler ) ; handlers . put ( namedClass . first , httpHandler ) ; handlerListById . put ( namedClass . first , Collections . singletonList ( httpHandler ) ) ; } } }
Helper method for generating the instance of a handler from its map definition in config . Ie . No mapped values for setters or list of constructor fields .