public void driver ( String [ ] args ) throws Throwable { // Make sure they gave us a program name. if ( args . length == 0 ) { System . out . println ( "An example program must be given as the" + " first argument." ) ; printUsage ( programs ) ; throw new IllegalArgumentException ( "An example program must be given " + "as the first argument." ) ; } // And that it is good. ProgramDescription pgm = programs . get ( args [ 0 ] ) ; if ( pgm == null ) { System . out . println ( "Unknown program '" + args [ 0 ] + "' chosen." ) ; printUsage ( programs ) ; throw new IllegalArgumentException ( "Unknown program '" + args [ 0 ] + "' chosen." ) ; } // Remove the leading argument and call main String [ ] new_args = new String [ args . length - 1 ] ; for ( int i = 1 ; i < args . length ; ++ i ) { new_args [ i - 1 ] = args [ i ] ; } pgm . invoke ( new_args ) ; }
This is a driver for the example programs . It looks at the first command line argument and tries to find an example program with that name . If it is found it calls the main method in that class with the rest of the command line arguments .