@ SuppressWarnings ( "unchecked" ) private void getConstructor ( ) { Class < ? extends Logger > c = DefaultLogger . class ; String className = System . getProperty ( "net.spy.log.LoggerImpl" ) ; if ( className != null ) { try { c = ( Class < ? extends Logger > ) Class . forName ( className ) ; } catch ( NoClassDefFoundError e ) { System . err . println ( "Warning: " + className + " not found while initializing" + " net.spy.compat.log.LoggerFactory" ) ; e . printStackTrace ( ) ; c = DefaultLogger . class ; } catch ( ClassNotFoundException e ) { System . err . println ( "Warning: " + className + " not found while initializing" + " net.spy.compat.log.LoggerFactory" ) ; e . printStackTrace ( ) ; c = DefaultLogger . class ; } } // Find the best constructor try { // Try to find a constructor that takes a single string Class < ? > [ ] args = { String . class } ; instanceConstructor = c . getConstructor ( args ) ; } catch ( NoSuchMethodException e ) { try { // Try to find an empty constructor Class < ? > [ ] args = { } ; instanceConstructor = c . getConstructor ( args ) ; } catch ( NoSuchMethodException e2 ) { System . err . println ( "Warning: " + className + " has no appropriate constructor, using defaults." ) ; // Try to find a constructor that takes a single string try { Class < ? > [ ] args = { String . class } ; instanceConstructor = DefaultLogger . class . getConstructor ( args ) ; } catch ( NoSuchMethodException e3 ) { // This shouldn't happen. throw new NoSuchMethodError ( "There used to be a constructor that " + "takes a single String on " + DefaultLogger . class + ", but I " + "can't find one now." ) ; } // SOL } // No empty constructor } // No constructor that takes a string }
Find the appropriate constructor