Example usage for org.apache.commons.configuration MapConfiguration getProperty

List of usage examples for org.apache.commons.configuration MapConfiguration getProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration MapConfiguration getProperty.

Prototype

public Object getProperty(String key) 

Source Link

Usage

From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java

private MapConfiguration generateAndValidateConfig(CommandLine cmdLine) throws ParseException {
    Preconditions.checkNotNull(cmdLine);
    MapConfiguration ret = new MapConfiguration(Maps.<String, Object>newHashMap());

    for (Option option : cmdLine.getOptions()) {
        ret.addProperty(option.getLongOpt(), option.getValue());
    }//from   ww w . j a va 2s .  c  o  m

    if (null == ret.getProperty(OPT_INPUT_MDL.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing mdl file " + "location");
    } else {
        String fileName = ret.getString(OPT_INPUT_MDL.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("MDL file '" + fileName + "' does not " + "exist");
        } else if (!file.isFile()) {
            throw new ParseException("MDL file '" + fileName + "' is not a " + "file");
        }
    }

    if (null == ret.getProperty(OPT_INPUT_FIXTURE.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing fixture file " + "location");
    } else {
        String fileName = ret.getString(OPT_INPUT_FIXTURE.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("Fixture file '" + fileName + "' does not " + "exist");
        } else if (!file.isFile()) {
            throw new ParseException("Fixture file '" + fileName + "' is not a " + "file");
        }
    }

    if (null != ret.getProperty(OPT_INPUT_CONVENTIONS.getLongOpt())) {
        String fileName = ret.getString(OPT_INPUT_CONVENTIONS.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("Conventions file '" + fileName + "' does " + "not exist");
        } else if (!file.isFile()) {
            throw new ParseException("Conventions file '" + fileName + "' is " + "not a file");
        }
    }

    if (null == ret.getProperty(OPT_ADAPTER_CLASS.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing adapter class");
    } else {
        String className = ret.getString(OPT_ADAPTER_CLASS.getLongOpt());
        try {
            Class<?> adapterClass = this.getClass().getClassLoader().loadClass(className);
            if (!MetricFixtureAdapter.class.isAssignableFrom(adapterClass)) {
                throw new ParseException("Adapter class " + className + "is of the " + "wrong type");
            }
            ret.addProperty(ADAPTER_CLASS_CONFIG, adapterClass);
        } catch (ClassNotFoundException e) {
            throw new ParseException("Unknown metric adapter " + className);
        }
    }
    return ret;
}

From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java

private MetricFixtureAdapter newMetricFixtureAdapter(MapConfiguration config, OutputStream out,
        OutputStream err) throws IllegalAccessException, InstantiationException {
    Preconditions.checkNotNull(config);//  w w  w.j  a v  a2 s .co m
    Preconditions.checkNotNull(out);
    Preconditions.checkNotNull(err);
    // All implementations of the MetricFixtureAdapter must have a no-argument
    // c'tor.
    LOG.info("Instantiating new metric fixture of class " + config.getString(OPT_ADAPTER_CLASS.getLongOpt()));
    Class<?> adapterClass = (Class<?>) config.getProperty(ADAPTER_CLASS_CONFIG);
    Preconditions.checkNotNull(adapterClass);
    return (MetricFixtureAdapter) adapterClass.newInstance();
}