protected void doLoadFromClasspath ( String policyImpl , IAsyncResultHandler < IPolicy > handler ) { IPolicy rval ; String classname = policyImpl . substring ( 6 ) ; Class < ? > c = null ; // First try a simple Class.forName() try { c = Class . forName ( classname ) ; } catch ( ClassNotFoundException e ) { } // Didn't work? Try using this class's classloader. if ( c == null ) { try { c = getClass ( ) . getClassLoader ( ) . loadClass ( classname ) ; } catch ( ClassNotFoundException e ) { } } // Still didn't work? Try the thread's context classloader. if ( c == null ) { try { c = Thread . currentThread ( ) . getContextClassLoader ( ) . loadClass ( classname ) ; } catch ( ClassNotFoundException e ) { } } if ( c == null ) { handler . handle ( AsyncResultImpl . < IPolicy > create ( new PolicyNotFoundException ( classname ) ) ) ; return ; } try { rval = ( IPolicy ) c . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { handler . handle ( AsyncResultImpl . < IPolicy > create ( new PolicyNotFoundException ( policyImpl , e ) ) ) ; return ; } policyCache . put ( policyImpl , rval ) ; handler . handle ( AsyncResultImpl . create ( rval ) ) ; return ; }
Loads a policy from a class on the classpath .