public Command findCommand ( String name , ClassLoader cl ) { synchronized ( commandCache ) { if ( ! commandCache . containsKey ( name ) ) { try { Command commandInstance = ( Command ) Class . forName ( name , true , cl ) . newInstance ( ) ; commandCache . put ( name , commandInstance ) ; } catch ( Exception ex ) { throw new IllegalArgumentException ( "Unknown Command implementation with name '" + name + "'" ) ; } } else { Command cmd = commandCache . get ( name ) ; if ( ! cmd . getClass ( ) . getClassLoader ( ) . equals ( cl ) ) { commandCache . remove ( name ) ; try { Command commandInstance = ( Command ) Class . forName ( name , true , cl ) . newInstance ( ) ; commandCache . put ( name , commandInstance ) ; } catch ( Exception ex ) { throw new IllegalArgumentException ( "Unknown Command implementation with name '" + name + "'" ) ; } } } } return commandCache . get ( name ) ; }
Finds command by FQCN and if not found loads the class and store the instance in the cache .