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

no.difi.certvalidator.parser.ClassRuleParser Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package no.difi.certvalidator.parser;

import no.difi.certvalidator.api.ValidatorRule;
import no.difi.certvalidator.api.ValidatorRuleParser;
import no.difi.certvalidator.jaxb.ClassType;
import no.difi.certvalidator.lang.ValidatorParsingException;
import org.kohsuke.MetaInfServices;

import java.util.Map;

/**
 * @author erlend
 */
@MetaInfServices
public class ClassRuleParser implements ValidatorRuleParser {

    @Override
    public boolean supports(Class cls) {
        return ClassType.class.equals(cls);
    }

    @Override
    public ValidatorRule parse(Object o, Map objectStorage) throws ValidatorParsingException {
        ClassType classType = (ClassType) o;

        try {
            return (ValidatorRule) Class.forName(classType.getValue()).newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new ValidatorParsingException(
                    String.format("Unable to load rule '%s'.", classType.getValue()), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy