PKIXBuilderParameters params =
new PKIXBuilderParameters(trustStore, selector);
for (int j = 0; j < certStores.length; j++) {
params.addCertStore(certStores[j]);
}
PKIXCertPathBuilderResult result;
try {
result = (PKIXCertPathBuilderResult)
CertPathBuilder.getInstance("PKIX").build(params);
} catch (CertPathBuilderException e) {
logger.log(Levels.HANDLED,
"exception building certificate path", e);
return null;
}
List certs = result.getCertPath().getCertificates();
return certs.isEmpty() ?
result.getTrustAnchor().getTrustedCert() :
(Certificate) certs.get(0);
}