All Downloads are FREE. Search and download functionalities are using the official Maven repository.

configuration_file_parser.segment.ExportClassesParser Maven / Gradle / Ivy

The newest version!
package configuration_file_parser.segment;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ex.ConfigurationException;

import api.definition.config.IExport;
import configuration_file_parser.ParserConstants;
import constants.BRunnerKeywords;
import export.constants.ExportConstants;

/**
 * Parser for the export formats
 */
public class ExportClassesParser {

	/**
	 * @return the export formats
	 * @param apacheConfigurationObject
	 * @throws ConfigurationException
	 * @throws ClassNotFoundException
	 */
	public static Collection> parse(Configuration apacheConfigurationObject)
			throws ConfigurationException, ClassNotFoundException {
		Set fullPropertyNames = new LinkedHashSet<>();
		Set exportNames = new LinkedHashSet<>();
		apacheConfigurationObject.getKeys(BRunnerKeywords.OuterLevel.EXPORT.kw)
				.forEachRemaining(fullPropertyNames::add);

		for (String name : fullPropertyNames) {
			exportNames.add(name.replace(BRunnerKeywords.OuterLevel.EXPORT.kw + ".", ""));
		}

		Collection> exportClasses = new HashSet<>();
		for (String exportNickname : exportNames) {
			Class exportClass = (Class) ExportConstants
					.getClassByName(exportNickname);

			exportClasses.add(exportClass);
		}

		if (exportClasses.isEmpty()) {
			exportClasses.add(ParserConstants.getDefaultExporter());
		}

		return exportClasses;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy