no.difi.certvalidator.ValidatorBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-certvalidator Show documentation
Show all versions of commons-certvalidator Show documentation
Rule engine for creation of certificate validator.
package no.difi.certvalidator;
import no.difi.certvalidator.api.ValidatorRule;
import no.difi.certvalidator.structure.Junction;
import java.util.ArrayList;
import java.util.List;
/**
* Builder for creation of validators.
*/
public class ValidatorBuilder {
/**
* Point of entry.
*
* @return Builder instance.
*/
public static ValidatorBuilder newInstance() {
return new ValidatorBuilder();
}
private List validatorRules = new ArrayList();
private ValidatorBuilder() {
// No action
}
/**
* Append validator instance to validator.
*
* @param validatorRule Configured validator.
* @return Builder instance.
*/
public ValidatorBuilder addRule(ValidatorRule validatorRule) {
validatorRules.add(validatorRule);
return this;
}
/**
* Generates a ValidatorHelper instance containing defined validator(s).
*
* @return Validator ready for use.
*/
public Validator build() {
if (validatorRules.size() == 1)
return new Validator(validatorRules.get(0));
return new Validator(Junction.and(validatorRules.toArray(new ValidatorRule[validatorRules.size()])));
}
}