private CertificateToken dealSignature(final AdvancedSignature signature,final XmlSignature xmlSignature){
  final AdvancedSignature masterSignature=signature.getMasterSignature();
  if (masterSignature != null) {
    xmlSignature.setType(AttributeValue.COUNTERSIGNATURE);
    xmlSignature.setParentId(masterSignature.getId());
  }
  performStructuralValidation(signature,xmlSignature);
  performSignatureCryptographicValidation(signature,xmlSignature);
  xmlSignature.setId(signature.getId());
  xmlSignature.setDateTime(signature.getSigningTime());
  final SignatureLevel dataFoundUpToLevel=signature.getDataFoundUpToLevel();
  final String value=dataFoundUpToLevel == null ? "UNKNOWN" : dataFoundUpToLevel.name();
  xmlSignature.setSignatureFormat(value);
  dealWithSignatureProductionPlace(signature,xmlSignature);
  dealWithCommitmentTypeIndication(signature,xmlSignature);
  dealWithClaimedRole(signature,xmlSignature);
  final String contentType=signature.getContentType();
  xmlSignature.setContentType(contentType);
  final String contentIdentifier=signature.getContentIdentifier();
  xmlSignature.setContentIdentifier(contentIdentifier);
  final String contentHints=signature.getContentHints();
  xmlSignature.setContentHints(contentHints);
  dealWithCertifiedRole(signature,xmlSignature);
  final CertificateValidity certificateValidity=dealSigningCertificate(signature,xmlSignature);
  final XmlBasicSignatureType xmlBasicSignature=getXmlBasicSignatureType(xmlSignature);
  final EncryptionAlgorithm encryptionAlgorithm=signature.getEncryptionAlgorithm();
  final String encryptionAlgorithmString=encryptionAlgorithm == null ? "?" : encryptionAlgorithm.getName();
  xmlBasicSignature.setEncryptionAlgoUsedToSignThisToken(encryptionAlgorithmString);
  final CertificateToken signingCertificateToken=certificateValidity == null ? null : certificateValidity.getCertificateToken();
  final int keyLength=signingCertificateToken == null ? 0 : DSSPKUtils.getPublicKeySize(signingCertificateToken.getPublicKey());
  xmlBasicSignature.setKeyLengthUsedToSignThisToken(String.valueOf(keyLength));
  final DigestAlgorithm digestAlgorithm=signature.getDigestAlgorithm();
  final String digestAlgorithmString=digestAlgorithm == null ? "?" : digestAlgorithm.getName();
  xmlBasicSignature.setDigestAlgoUsedToSignThisToken(digestAlgorithmString);
  xmlSignature.setBasicSignature(xmlBasicSignature);
  dealSignatureScope(xmlSignature,signature);
  return signingCertificateToken;
}

private CertificateToken dealSignature ( final AdvancedSignature signature , final XmlSignature xmlSignature ) { final AdvancedSignature masterSignature = signature . getMasterSignature ( ) ; if ( masterSignature != null ) { xmlSignature . setType ( AttributeValue . COUNTERSIGNATURE ) ; xmlSignature . setParentId ( masterSignature . getId ( ) ) ; } performStructuralValidation ( signature , xmlSignature ) ; performSignatureCryptographicValidation ( signature , xmlSignature ) ; xmlSignature . setId ( signature . getId ( ) ) ; xmlSignature . setDateTime ( signature . getSigningTime ( ) ) ; final SignatureLevel dataFoundUpToLevel = signature . getDataFoundUpToLevel ( ) ; final String value = dataFoundUpToLevel == null ? "UNKNOWN" : dataFoundUpToLevel . name ( ) ; xmlSignature . setSignatureFormat ( value ) ; dealWithSignatureProductionPlace ( signature , xmlSignature ) ; dealWithCommitmentTypeIndication ( signature , xmlSignature ) ; dealWithClaimedRole ( signature , xmlSignature ) ; final String contentType = signature . getContentType ( ) ; xmlSignature . setContentType ( contentType ) ; final String contentIdentifier = signature . getContentIdentifier ( ) ; xmlSignature . setContentIdentifier ( contentIdentifier ) ; final String contentHints = signature . getContentHints ( ) ; xmlSignature . setContentHints ( contentHints ) ; dealWithCertifiedRole ( signature , xmlSignature ) ; final CertificateValidity certificateValidity = dealSigningCertificate ( signature , xmlSignature ) ; final XmlBasicSignatureType xmlBasicSignature = getXmlBasicSignatureType ( xmlSignature ) ; final EncryptionAlgorithm encryptionAlgorithm = signature . getEncryptionAlgorithm ( ) ; final String encryptionAlgorithmString = encryptionAlgorithm == null ? "?" : encryptionAlgorithm . getName ( ) ; xmlBasicSignature . setEncryptionAlgoUsedToSignThisToken ( encryptionAlgorithmString ) ; final CertificateToken signingCertificateToken = certificateValidity == null ? null : certificateValidity . getCertificateToken ( ) ; final int keyLength = signingCertificateToken == null ? 0 : DSSPKUtils . getPublicKeySize ( signingCertificateToken . getPublicKey ( ) ) ; xmlBasicSignature . setKeyLengthUsedToSignThisToken ( String . valueOf ( keyLength ) ) ; final DigestAlgorithm digestAlgorithm = signature . getDigestAlgorithm ( ) ; final String digestAlgorithmString = digestAlgorithm == null ? "?" : digestAlgorithm . getName ( ) ; xmlBasicSignature . setDigestAlgoUsedToSignThisToken ( digestAlgorithmString ) ; xmlSignature . setBasicSignature ( xmlBasicSignature ) ; dealSignatureScope ( xmlSignature , signature ) ; return signingCertificateToken ; }
this method deals with the basic signature data . the retrieved information is transformed to the jaxb object . the signing certificate token is returned if found .
