private static < E > E getEndpoint ( Class < E > type , String name , Reflections reflections ) { E result = null ; // Get concrete subclasses: Set < Class < ? extends E > > foundClasses = reflections . getSubTypesOf ( type ) ; Set < Class < ? extends E > > endpointClasses = new HashSet <> ( ) ; for ( Class < ? extends E > clazz : foundClasses ) { if ( ! Modifier . isAbstract ( clazz . getModifiers ( ) ) ) { endpointClasses . add ( clazz ) ; } } // Filter out any default routes: //log.info("Filtering " + type.getName()); Iterator < Class < ? extends E > > iterator = endpointClasses . iterator ( ) ; while ( iterator . hasNext ( ) ) { Class < ? extends E > next = iterator . next ( ) ; if ( StringUtils . startsWithIgnoreCase ( next . getName ( ) , "com.github.davidcarboni.restolino.routes." ) ) { //log.info("Filtered out " + next.getName()); iterator . remove ( ) ; } //else { //log.info("Filtered in " + next.getName()); //} } //log.info("Filtered."); if ( endpointClasses . size ( ) != 0 ) { // Dump multiple endpoints: if ( endpointClasses . size ( ) > 1 ) { log . info ( "Warning: found multiple candidates for {} endpoint: {}" , name , endpointClasses ) ; } // Instantiate the endpoint if possible: try { result = endpointClasses . iterator ( ) . next ( ) . newInstance ( ) ; } catch ( Exception e ) { log . info ( "Error: cannot instantiate {} endpoint class {}" , name , endpointClasses . iterator ( ) . next ( ) ) ; e . printStackTrace ( ) ; } } return result ; }
Locates a single endpoint class .