configuration_file_parser.segment.ExportClassesParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brunner-core-parser Show documentation
Show all versions of brunner-core-parser Show documentation
Parser module for the BRunner project
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 extends IExport> exportClass = (Class extends IExport>) ExportConstants
.getClassByName(exportNickname);
exportClasses.add(exportClass);
}
if (exportClasses.isEmpty()) {
exportClasses.add(ParserConstants.getDefaultExporter());
}
return exportClasses;
}
}