@ SuppressWarnings ( "unchecked" ) public < B , T extends B , D extends B > B resolveBeanWithDefaultClass ( Class < T > typeToResolve , Class < D > defaultType ) { // if type to resolve is null, do nothing, not even the default if ( typeToResolve == null ) { return null ; } // get candidate resolve types Set < Bean < ? > > candidates = this . manager . getBeans ( typeToResolve ) ; // if no candidates are available, resolve // using next class up if ( ! candidates . iterator ( ) . hasNext ( ) ) { this . logger . trace ( "No candidates for: {}" , typeToResolve . getName ( ) ) ; // try and resolve only the default type return resolveBeanWithDefaultClass ( defaultType , null ) ; } this . logger . trace ( "Requesting resolution on: {}" , typeToResolve . getName ( ) ) ; // get candidate Bean < ? > bean = candidates . iterator ( ) . next ( ) ; CreationalContext < ? > context = this . manager . createCreationalContext ( bean ) ; Type type = ( Type ) bean . getTypes ( ) . iterator ( ) . next ( ) ; B result = ( B ) this . manager . getReference ( bean , type , context ) ; this . logger . trace ( "Resolved to: {}" , result . getClass ( ) . getName ( ) ) ; return result ; }
Resolve managed bean for given type