private < T , U > T [ ] locateAll ( final ClassLocator locator , final Class < T > clazz , final Consumer < T > bootstrapper ) { Set < Class < ? extends T > > set = locator . subtypeOf ( clazz ) ; if ( ! set . isEmpty ( ) ) { @ SuppressWarnings ( "unchecked" ) T [ ] all = ( T [ ] ) Array . newInstance ( clazz , set . size ( ) ) ; int index = 0 ; Iterator < Class < ? extends T > > iterator = set . iterator ( ) ; while ( iterator . hasNext ( ) ) { Class < ? extends T > c = iterator . next ( ) ; try { T locatedImplementation = DynamicClassFactory . createInstance ( c , clazz ) ; bootstrapper . accept ( locatedImplementation ) ; logger . debug ( "Loaded configuration from: " + c ) ; all [ index ++ ] = locatedImplementation ; } catch ( IllegalArgumentException e ) { throw e ; } catch ( Exception e ) { logger . debug ( "Error reading custom configuration. Going with built in defaults. The error was: " + getCauseMessage ( e ) ) ; } } return all ; } else { logger . debug ( "Did not find custom configuration for {}. Going with built in defaults " , clazz ) ; } return null ; }
Locates an implementation of the given type and executes the consumer if a class of the given type is found