private static < T > T getSystemTool ( Class < T > clazz , String moduleName , String className ) { if ( useLegacy ) { try { return Class . forName ( className , true , ClassLoader . getSystemClassLoader ( ) ) . asSubclass ( clazz ) . getConstructor ( ) . newInstance ( ) ; } catch ( ReflectiveOperationException e ) { throw new Error ( e ) ; } } try { ServiceLoader < T > sl = ServiceLoader . load ( clazz , ClassLoader . getSystemClassLoader ( ) ) ; for ( Iterator < T > iter = sl . iterator ( ) ; iter . hasNext ( ) ; ) { T tool = iter . next ( ) ; if ( matches ( tool , moduleName ) ) return tool ; } } catch ( ServiceConfigurationError e ) { throw new Error ( e ) ; } return null ; }
Get an instance of a system tool using the service loader .