package at.gv.egovernment.moa.spss.api.xmlbind; import java.util.Iterator; import org.w3c.dom.Document; import org.w3c.dom.Element; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.MOASystemException; import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse; import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponseElement; import at.gv.egovernment.moa.spss.api.common.CheckResult; import at.gv.egovernment.moa.spss.api.common.SignerInfo; /** * Convert a VerifyCMSSignatureResponse API object into its * XML representation, according to the MOA XML schema. * * @author Patrick Peck * @version $Id$ */ public class VerifyCMSSignatureResponseBuilder { /** The XML document containing the response element. */ private Document responseDoc; /** The response VerifyCMSSignatureResponse DOM element. */ private Element responseElem; /** * Create a new VerifyCMSSignatureResponseBuilder: * * @throws MOASystemException An error occurred setting up the resulting * XML document. */ public VerifyCMSSignatureResponseBuilder() throws MOASystemException { responseDoc = ResponseBuilderUtils.createResponse("VerifyCMSSignatureResponse"); responseElem = responseDoc.getDocumentElement(); } /** * Build a document containing a VerifyCMSSignatureResponse * DOM element being the XML representation of the given * VerifyCMSSignatureResponse API object. * * @param response The VerifyCMSSignatureResponse to convert * to XML. * @return A document containing the VerifyCMSSignatureResponse * DOM element. * @throws MOAApplicationException An error occurred building the response. */ public Document build(VerifyCMSSignatureResponse response) throws MOAApplicationException { Iterator iter; for (iter = response.getResponseElements().iterator(); iter.hasNext();) { VerifyCMSSignatureResponseElement responseElement = (VerifyCMSSignatureResponseElement) iter.next(); addResponseElement(responseElement); } return responseDoc; } /** * Add an element to the response. * * @param responseElement The element to add to the response. * @throws MOAApplicationException An error occurred adding the element. */ private void addResponseElement(VerifyCMSSignatureResponseElement responseElement) throws MOAApplicationException { SignerInfo signerInfo = responseElement.getSignerInfo(); CheckResult signatureCheck = responseElement.getSignatureCheck(); CheckResult certCheck = responseElement.getCertificateCheck(); ResponseBuilderUtils.addSignerInfo( responseDoc, responseElem, signerInfo.getSignerCertificate(), signerInfo.isQualifiedCertificate(), signerInfo.isPublicAuthority(), signerInfo.getPublicAuhtorityID()); ResponseBuilderUtils.addCodeInfoElement( responseDoc, responseElem, "SignatureCheck", signatureCheck.getCode(), signatureCheck.getInfo()); ResponseBuilderUtils.addCodeInfoElement( responseDoc, responseElem, "CertificateCheck", certCheck.getCode(), certCheck.getInfo()); } }