if (dispatcher == null) { System.out .println("Error: insufficient option commands to run checker."); printHelp(options); }
    public static void main(String[] args)    {        // set up command line parser        CommandLineParser parser = new PosixParser();        CommandLine line = null;        // create an options object and populate it        Options options = new Options();        options.addOption("l", "looping", false, "Loop through bitstreams");        options.addOption("L", "continuous", false,                "Continuously loop through bitstreams");        options.addOption("h", "help", false, "Help");        options.addOption("d", "duration", true, "Checking duration");        options.addOption("c", "count", true, "Check count");        options.addOption("a", "handle", true, "Specify a handle to check");        options.addOption("e", "errors", false, "Report Errors Only");        OptionBuilder.withArgName("bitstream-ids").hasArgs().withDescription(                "Space separated list of bitstream ids");        Option useBitstreamIds = OptionBuilder.create('b');        options.addOption(useBitstreamIds);        options.addOption("p", "prune", false, "Prune configuration file");        options                .addOption(OptionBuilder                        .withArgName("prune")                        .hasOptionalArgs(1)                        .withDescription(                                "Prune old results (optionally using specified properties file for configuration)")                        .create('p'));        try        {            line = parser.parse(options, args);        }        catch (ParseException e)        {            LOG.fatal(e);            System.exit(1);        }        // user asks for help        if (line.hasOption('h'))        {            printHelp(options);        }        // Prune stage        if (line.hasOption('p'))        {            ResultsPruner rp = null;            try            {                rp = (line.getOptionValue('p') != null) ? ResultsPruner                        .getPruner(line.getOptionValue('p')) : ResultsPruner                        .getDefaultPruner();            }            catch (FileNotFoundException e)            {                e.printStackTrace();                System.exit(1);            }            int count = rp.prune();            System.out.println("Pruned " + count                    + " old results from the database.");        }        Date processStart = Calendar.getInstance().getTime();        BitstreamDispatcher dispatcher = null;        if (line.getOptions().length == 0)        {            dispatcher = new LimitedCountDispatcher(new SimpleDispatcher(                    processStart, false), 1);        }        else        {            // process should loop infinitely through            // most_recent_checksum table            if (line.hasOption('l'))            {                dispatcher = new SimpleDispatcher(processStart, false);             }            else if (line.hasOption('L'))            {                dispatcher = new SimpleDispatcher(processStart, true);            }            else if (line.hasOption('b'))            {                // check only specified bitstream(s)                String[] ids = line.getOptionValues('b');                List idList = new ArrayList(ids.length);                for (int i = 0; i < ids.length; i++)                {                    try                    {                        idList.add(new Integer(ids[i]));                    }                    catch (NumberFormatException nfe)                    {                        System.err.println("The following argument: " + ids[i]                                + " is not an integer");                        System.exit(0);                    }                }                dispatcher = new ListDispatcher(idList);            }            else if (line.hasOption('a'))            {                dispatcher = new HandleDispatcher(line.getOptionValue('a'));            }            else if (line.hasOption('d'))            {                // run checker process for specified duration                try                {                    dispatcher = new LimitedDurationDispatcher(                            new SimpleDispatcher(processStart, true), new Date(                                    System.currentTimeMillis()                                            + Utils.parseDuration(line                                                    .getOptionValue('d'))));                }                catch (Exception e)                {                    LOG.fatal("Couldn't parse " + line.getOptionValue('d')                            + " as a duration: ", e);                    System.exit(0);                }            }            else if (line.hasOption('c'))            {                // run checker process for specified number of bitstreams                dispatcher = new LimitedCountDispatcher(new SimpleDispatcher(                        processStart, false));            }        }        if (dispatcher == null)        {            System.out                    .println("Error: insufficient option commands to run checker.");            printHelp(options);        }        ResultsLogger logger = new ResultsLogger(processStart);        CheckerCommand checker = new CheckerCommand();        // report errors only        if (line.hasOption('e'))        {            checker.setReportErrorsOnly(true);        }        checker.configureLog();        checker.setProcessStartDate(processStart);        checker.setDispatcher(dispatcher);        checker.setCollector(logger);        checker.process();    }