Example usage for org.apache.commons.cli ParseException addSuppressed

List of usage examples for org.apache.commons.cli ParseException addSuppressed

Introduction

In this page you can find the example usage for org.apache.commons.cli ParseException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:de.ncoder.studipsync.ui.StandardUIAdapter.java

public static UIAdapter getUIAdapter(String type) throws ParseException {
    if (type != null) {
        try {//from   www  .  java2  s .  c  om
            StandardUIAdapter ui = valueOf(type);
            ui.init();
            return ui;
        } catch (IllegalArgumentException earg) {
            try {
                return loadUIAdapter(type);
            } catch (ClassNotFoundException eclass) {
                ParseException pe = new ParseException(
                        type + " is neither an UIType nor can it be resolved to a Java class.");
                pe.initCause(eclass);
                pe.addSuppressed(earg);
                throw pe;
            }
        }
    } else {
        return getDefaultUIAdapter();
    }
}

From source file:de.ncoder.studipsync.storage.StandardPathResolver.java

public static PathResolver getPathResolver(String type) throws ParseException {
    if (type != null) {
        try {//from www .  ja  va2  s.c  o m
            return valueOf(type);
        } catch (IllegalArgumentException earg) {
            try {
                return loadPathResolver(type);
            } catch (ClassNotFoundException eclass) {
                ParseException pe = new ParseException(
                        type + " is neither an UIType nor can it be resolved to a Java class.");
                pe.initCause(eclass);
                pe.addSuppressed(earg);
                throw pe;
            }
        }
    } else {
        return getDefaultPathResolver();
    }
}

From source file:de.haber.xmind2latex.cli.CliParameters.java

/**
 * Creates a {@link XMindToLatexExporter} for the given arguments.
 * //from w w  w . j a va 2s.c o  m
 * @param args Arguments to configure this {@link XMindToLatexExporter}.
 * 
 * @return A created {@link XMindToLatexExporter} or null, if no {@link CliParameters#INPUT} parameter is used.
 * 
 * @throws ParseException, NumberFormatException for invalid arguments
 * @throws ConfigurationException for invalid input files
 * @throws IllegalArgumentException if the given input file does not exist
 */
public static XMindToLatexExporter build(String[] args) throws ParseException {
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args, false);

    if (cmd.getOptions().length == 0) {
        throw new ParseException("Parameter -" + INPUT + " expected.");
    }

    if (cmd.hasOption(VERSION)) {
        printVersion();
    }

    CliParameters.validateNumberOfArguments(cmd, INPUT, options);
    if (cmd.hasOption(INPUT)) {
        File in = new File(cmd.getOptionValue(INPUT));
        Builder builder = new Builder(in);
        if (cmd.hasOption(FORCE)) {
            CliParameters.validateNumberOfArguments(cmd, FORCE, options);
            builder.overwritesExistingFiles(true);
        }

        File out;
        if (cmd.hasOption(OUTPUT)) {
            CliParameters.validateNumberOfArguments(cmd, OUTPUT, options);
            out = new File(cmd.getOptionValue(OUTPUT));
            builder.withTargetFile(out);
        }

        if (cmd.hasOption(TEMPLATE_LEVEL)) {
            CliParameters.validateNumberOfArguments(cmd, TEMPLATE_LEVEL, options);

            String level = cmd.getOptionValue(TEMPLATE_LEVEL);
            try {
                int levelAsInt = Integer.parseInt(level);
                if (levelAsInt < 0) {
                    throw new NumberFormatException();
                }
                builder.withMaxLevel(levelAsInt);
            } catch (NumberFormatException e) {
                ParseException ex = new ParseException(
                        "The level argument of option " + TEMPLATE_LEVEL + " has to be a positive integer.");
                ex.addSuppressed(e);
                throw ex;
            }

        }
        if (cmd.hasOption(HELP)) {
            CliParameters.validateNumberOfArguments(cmd, HELP, options);

            showHelp();
        }

        if (cmd.hasOption(ENVIRONMENT)) {
            CliParameters.validateNumberOfArguments(cmd, ENVIRONMENT, options);

            String[] env = cmd.getOptionValues(ENVIRONMENT);
            for (int i = 0; i + 2 < env.length; i = i + 3) {
                String level = env[i];
                String start = env[i + 1];
                String end = env[i + 2];
                try {
                    int levelAsInt = Integer.parseInt(level);
                    builder.withEnvironmentTemplates(levelAsInt, start, end);
                } catch (NumberFormatException e) {
                    ParseException ex = new ParseException(
                            "The level argument of option " + ENVIRONMENT + " has to be an integer.");
                    ex.addSuppressed(e);
                    throw ex;
                }
            }
        }
        if (cmd.hasOption(LEVEL)) {
            CliParameters.validateNumberOfArguments(cmd, LEVEL, options);

            String[] tmp = cmd.getOptionValues(LEVEL);

            for (int i = 0; i + 1 < tmp.length; i = i + 2) {
                String level = tmp[i];
                String template = tmp[i + 1];
                try {
                    int levelAsInt = Integer.parseInt(level);
                    builder.withTemplate(levelAsInt, template);
                } catch (NumberFormatException e) {
                    ParseException ex = new ParseException(
                            "The level argument of option " + LEVEL + " has to be an integer.");
                    ex.addSuppressed(e);
                    throw ex;
                }
            }
        }
        return builder.build();
    } else {
        return null;
    }
}