/**
   * Adds all the service entries (current and history) of all the providers of the trusted list to
   * the list of CertificateSource
   *
   * @param trustStatusList
   */
  private void loadAllCertificatesFromOneTSL(final TrustStatusList trustStatusList) {

    for (final TrustServiceProvider trustServiceProvider :
        trustStatusList.getTrustServicesProvider()) {

      for (final AbstractTrustService trustService : trustServiceProvider.getTrustServiceList()) {

        if (LOG.isTraceEnabled()) {
          LOG.trace("### " + trustService.getServiceName());
          LOG.trace("------> " + trustService.getType());
          LOG.trace("------> " + trustService.getStatus());
        }

        for (final Object digitalIdentity : trustService.getDigitalIdentity()) {

          try {

            X509Certificate x509Certificate = null;
            if (digitalIdentity instanceof X509Certificate) {

              x509Certificate = (X509Certificate) digitalIdentity;
            } else if (digitalIdentity instanceof X500Principal) {

              final X500Principal x500Principal = (X500Principal) digitalIdentity;
              final List<CertificateToken> certificateTokens = certPool.get(x500Principal);
              if (certificateTokens.size() > 0) {
                x509Certificate = certificateTokens.get(0).getCertificate();
              } else {
                LOG.warn(
                    "There is currently no certificate with the given X500Principal: '{}' within the certificate pool!",
                    x500Principal);
              }
            }
            if (x509Certificate != null) {

              addCertificate(
                  x509Certificate,
                  trustService,
                  trustServiceProvider,
                  trustStatusList.isWellSigned());
            }
          } catch (DSSException e) {

            // There is a problem when loading the certificate, we continue with the next one.
            LOG.warn(e.getLocalizedMessage());
          }
        }
      }
    }
  }
  /**
   * This method return the service info object enclosing the certificate.
   *
   * @param trustedService Object defining the trusted service
   * @param tsProvider Object defining the trusted service provider, must be the parent of the
   *     trusted service
   * @param tlWellSigned Indicates if the signature of trusted list is valid
   * @return
   */
  private ServiceInfo getServiceInfo(
      final AbstractTrustService trustedService,
      final TrustServiceProvider tsProvider,
      final boolean tlWellSigned) {

    // System.out.println("--- > ServiceName: " + trustedService.getServiceName());
    final ServiceInfo serviceInfo = trustedService.createServiceInfo();

    serviceInfo.setServiceName(trustedService.getServiceName());
    serviceInfo.setStatus(trustedService.getStatus());
    serviceInfo.setStatusStartDate(trustedService.getStatusStartDate());
    serviceInfo.setStatusEndDate(trustedService.getStatusEndDate());
    serviceInfo.setType(trustedService.getType());

    serviceInfo.setTspElectronicAddress(tsProvider.getElectronicAddress());
    serviceInfo.setTspName(tsProvider.getName());
    serviceInfo.setTspPostalAddress(tsProvider.getPostalAddress());
    serviceInfo.setTspTradeName(tsProvider.getTradeName());

    serviceInfo.setTlWellSigned(tlWellSigned);

    return serviceInfo;
  }