BaseCommand tools = getInstance();
ToolCommandListener outputListener = new SysOutListener(); ToolCommandListener errorListener = new SysErrListener(); ToolCommandListener exceptionListener = new ExceptionListener();  BaseCommand tools = null; try { tools = getInstance(); } catch ( Exception e ) { System.err.println( "An error has occurred. Apache DS Tools must quit." + "\nError: " + e.getMessage() ); System.exit( 1 ); }
    public static void main( String[] args ) throws Exception    {        BaseCommand tools = getInstance();                if ( !BaseCommand.hasBannerOption( args ) )        {            tools.printBanner();        }        if ( args.length == 0 )        {            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );            System.exit( 1 );        }        // help is a special command         String command = args[0].toLowerCase();        if ( "help".equals( command ) )        {            CommandLine cmdline = tools.getCommandLine( command, args );            if ( cmdline.getArgs().length > 1 )            {                tools.helpOnCommand( cmdline.getArgs()[1] );                System.exit( 0 );            }            else            {                tools.printUsage();                System.exit( 0 );            }        }        else if ( command.equals( "-version" ) )        {            System.out.println( tools.getProductCommand() + " version " + tools.getProductVersion() );            System.exit( 0 );        }        ToolCommand cmd = ( ToolCommand ) tools.getCommands().get( command );        if ( cmd == null )        {            System.err.println( "Unknown command: " + args[0] );            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );            System.exit( 1 );        }        CommandLine cmdline = tools.getCommandLine( command, args );        if ( cmdline.hasOption( 'd' ) )        {            cmd.setDebugEnabled( true );            BaseCommand.dumpArgs( "raw command line arguments: ", args );            BaseCommand.dumpArgs( "parsed arguments: ", cmdline.getArgs() );        }        cmd.setQuietEnabled( cmdline.hasOption( 'q' ) );        cmd.setDebugEnabled( cmdline.hasOption( 'd' ) );        cmd.setVerboseEnabled( cmdline.hasOption( 'v' ) );        cmd.setVersion( tools.getProductVersion() );        if ( cmdline.getOptionValue( 'i' ) != null )        {            cmd.setLayout( cmdline.getOptionValue( 'i' ) );            if ( !cmd.isQuietEnabled() )            {                System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );            }            ApplicationContext factory = null;            URL configUrl = cmd.getLayout().getConfigurationFile().toURL();            factory = new FileSystemXmlApplicationContext( configUrl.toString() );            cmd.setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );        }        else if ( cmdline.hasOption( 'c' ) )        {            System.err.println( "forced configuration load (-c) requires the -i option" );            System.exit( 1 );        }        cmd.execute( cmdline );    }