@Override
    public void generate(HashMap<String, String> sepaParams, OutputStream os, boolean validate) throws Exception {
        Integer maxIndex = SepaUtil.maxIndex(sepaParams);

        //Document
        Document doc = new Document();

        //Customer Credit Transfer Initiation
        doc.setCstmrDrctDbtInitn(new CustomerDirectDebitInitiationV02());
        doc.getCstmrDrctDbtInitn().setGrpHdr(new GroupHeaderSDD());

        final String sepaId = sepaParams.get("sepaid");
        final String pmtInfId = sepaParams.get("pmtinfid");

        //Group Header
        doc.getCstmrDrctDbtInitn().getGrpHdr().setMsgId(sepaId);
        doc.getCstmrDrctDbtInitn().getGrpHdr().setCreDtTm(SepaUtil.createCalendar(null));
        doc.getCstmrDrctDbtInitn().getGrpHdr().setNbOfTxs(String.valueOf(maxIndex != null ? maxIndex + 1 : 1));
        doc.getCstmrDrctDbtInitn().getGrpHdr().setInitgPty(new PartyIdentificationSEPA1());
        doc.getCstmrDrctDbtInitn().getGrpHdr().getInitgPty().setNm(sepaParams.get("src.name"));
        doc.getCstmrDrctDbtInitn().getGrpHdr().setCtrlSum(SepaUtil.sumBtgValue(sepaParams, maxIndex));

        //Payment Information
        ArrayList<PaymentInstructionInformationSDD> pmtInfs =
            (ArrayList<PaymentInstructionInformationSDD>) doc.getCstmrDrctDbtInitn().getPmtInf();
        PaymentInstructionInformationSDD pmtInf = new PaymentInstructionInformationSDD();
        pmtInfs.add(pmtInf);

        pmtInf.setPmtInfId(pmtInfId != null && pmtInfId.length() > 0 ? pmtInfId : sepaId);
        pmtInf.setPmtMtd(PaymentMethod2Code.DD);

        pmtInf.setNbOfTxs(String.valueOf(maxIndex != null ? maxIndex + 1 : 1));
        pmtInf.setCtrlSum(SepaUtil.sumBtgValue(sepaParams, maxIndex));

        pmtInf.setReqdColltnDt(SepaUtil.createCalendar(sepaParams.get("targetdate")));
        pmtInf.setCdtr(new PartyIdentificationSEPA5());
        pmtInf.setCdtrAcct(new CashAccountSEPA1());
        pmtInf.setCdtrAgt(new BranchAndFinancialInstitutionIdentificationSEPA3());

        //Payment Information
        pmtInf.getCdtr().setNm(sepaParams.get("src.name"));

        //Payment Information
        pmtInf.getCdtrAcct().setId(new AccountIdentificationSEPA());
        pmtInf.getCdtrAcct().getId().setIBAN(sepaParams.get("src.iban"));

        //Payment Information
        pmtInf.getCdtrAgt().setFinInstnId(new FinancialInstitutionIdentificationSEPA3());
        String srcBic = sepaParams.get("src.bic");
        if (srcBic != null && srcBic.length() > 0) // BIC ist inzwischen optional
        {
            pmtInf.getCdtrAgt().getFinInstnId().setBIC(srcBic);
        } else {
            pmtInf.getCdtrAgt().getFinInstnId().setOthr(new OthrIdentification());
            pmtInf.getCdtrAgt().getFinInstnId().getOthr().setId(OthrIdentificationCode.NOTPROVIDED);
        }

        //Payment Information - ChargeBearer
        pmtInf.setChrgBr(ChargeBearerTypeSEPACode.SLEV);

        pmtInf.setPmtTpInf(new PaymentTypeInformationSDD());
        pmtInf.getPmtTpInf().setSvcLvl(new ServiceLevel());
        pmtInf.getPmtTpInf().getSvcLvl().setCd("SEPA");
        pmtInf.getPmtTpInf().setLclInstrm(new LocalInstrumentSEPA());
        pmtInf.getPmtTpInf().getLclInstrm().setCd(sepaParams.get("type"));
        pmtInf.getPmtTpInf().setSeqTp(SequenceType1Code.fromValue(sepaParams.get("sequencetype")));

        //Payment Information - Credit Transfer Transaction Information
        ArrayList<DirectDebitTransactionInformationSDD> drctDbtTxInfs =
            (ArrayList<DirectDebitTransactionInformationSDD>) pmtInf.getDrctDbtTxInf();
        if (maxIndex != null) {
            for (int tnr = 0; tnr <= maxIndex; tnr++) {
                drctDbtTxInfs.add(createDirectDebitTransactionInformationSDD(sepaParams, tnr));
            }
        } else {
            drctDbtTxInfs.add(createDirectDebitTransactionInformationSDD(sepaParams, null));
        }

        String batch = SepaUtil.getProperty(sepaParams, "batchbook", null);
        if (batch != null)
            pmtInf.setBtchBookg(batch.equals("1"));

        ObjectFactory of = new ObjectFactory();
        this.marshal(of.createDocument(doc), os, validate);
    }
@ Override public void generate ( HashMap < String , String > sepaParams , OutputStream os , boolean validate ) throws Exception { Integer maxIndex = SepaUtil . maxIndex ( sepaParams ) ; Document doc = new Document ( ) ; doc . setCstmrDrctDbtInitn ( new CustomerDirectDebitInitiationV02 ( ) ) ; doc . getCstmrDrctDbtInitn ( ) . setGrpHdr ( new GroupHeaderSDD ( ) ) ; final String sepaId = sepaParams . get ( "sepaid" ) ; final String pmtInfId = sepaParams . get ( "pmtinfid" ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . setMsgId ( sepaId ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . setCreDtTm ( SepaUtil . createCalendar ( null ) ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . setNbOfTxs ( String . valueOf ( maxIndex != null ? maxIndex + 1 : 1 ) ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . setInitgPty ( new PartyIdentificationSEPA1 ( ) ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . getInitgPty ( ) . setNm ( sepaParams . get ( "src.name" ) ) ; doc . getCstmrDrctDbtInitn ( ) . getGrpHdr ( ) . setCtrlSum ( SepaUtil . sumBtgValue ( sepaParams , maxIndex ) ) ; ArrayList < PaymentInstructionInformationSDD > pmtInfs = ( ArrayList < PaymentInstructionInformationSDD > ) doc . getCstmrDrctDbtInitn ( ) . getPmtInf ( ) ; PaymentInstructionInformationSDD pmtInf = new PaymentInstructionInformationSDD ( ) ; pmtInfs . add ( pmtInf ) ; pmtInf . setPmtInfId ( pmtInfId != null && pmtInfId . length ( ) > 0 ? pmtInfId : sepaId ) ; pmtInf . setPmtMtd ( PaymentMethod2Code . DD ) ; pmtInf . setNbOfTxs ( String . valueOf ( maxIndex != null ? maxIndex + 1 : 1 ) ) ; pmtInf . setCtrlSum ( SepaUtil . sumBtgValue ( sepaParams , maxIndex ) ) ; pmtInf . setReqdColltnDt ( SepaUtil . createCalendar ( sepaParams . get ( "targetdate" ) ) ) ; pmtInf . setCdtr ( new PartyIdentificationSEPA5 ( ) ) ; pmtInf . setCdtrAcct ( new CashAccountSEPA1 ( ) ) ; pmtInf . setCdtrAgt ( new BranchAndFinancialInstitutionIdentificationSEPA3 ( ) ) ; pmtInf . getCdtr ( ) . setNm ( sepaParams . get ( "src.name" ) ) ; pmtInf . getCdtrAcct ( ) . setId ( new AccountIdentificationSEPA ( ) ) ; pmtInf . getCdtrAcct ( ) . getId ( ) . setIBAN ( sepaParams . get ( "src.iban" ) ) ; pmtInf . getCdtrAgt ( ) . setFinInstnId ( new FinancialInstitutionIdentificationSEPA3 ( ) ) ; String srcBic = sepaParams . get ( "src.bic" ) ; if ( srcBic != null && srcBic . length ( ) > 0 ) { pmtInf . getCdtrAgt ( ) . getFinInstnId ( ) . setBIC ( srcBic ) ; } else { pmtInf . getCdtrAgt ( ) . getFinInstnId ( ) . setOthr ( new OthrIdentification ( ) ) ; pmtInf . getCdtrAgt ( ) . getFinInstnId ( ) . getOthr ( ) . setId ( OthrIdentificationCode . NOTPROVIDED ) ; } pmtInf . setChrgBr ( ChargeBearerTypeSEPACode . SLEV ) ; pmtInf . setPmtTpInf ( new PaymentTypeInformationSDD ( ) ) ; pmtInf . getPmtTpInf ( ) . setSvcLvl ( new ServiceLevel ( ) ) ; pmtInf . getPmtTpInf ( ) . getSvcLvl ( ) . setCd ( "SEPA" ) ; pmtInf . getPmtTpInf ( ) . setLclInstrm ( new LocalInstrumentSEPA ( ) ) ; pmtInf . getPmtTpInf ( ) . getLclInstrm ( ) . setCd ( sepaParams . get ( "type" ) ) ; pmtInf . getPmtTpInf ( ) . setSeqTp ( SequenceType1Code . fromValue ( sepaParams . get ( "sequencetype" ) ) ) ; ArrayList < DirectDebitTransactionInformationSDD > drctDbtTxInfs = ( ArrayList < DirectDebitTransactionInformationSDD > ) pmtInf . getDrctDbtTxInf ( ) ; if ( maxIndex != null ) { for ( int tnr = 0 ; tnr <= maxIndex ; tnr ++ ) { drctDbtTxInfs . add ( createDirectDebitTransactionInformationSDD ( sepaParams , tnr ) ) ; } } else { drctDbtTxInfs . add ( createDirectDebitTransactionInformationSDD ( sepaParams , null ) ) ; } String batch = SepaUtil . getProperty ( sepaParams , "batchbook" , null ) ; if ( batch != null ) pmtInf . setBtchBookg ( batch . equals ( "1" ) ) ; ObjectFactory of = new ObjectFactory ( ) ; this . marshal ( of . createDocument ( doc ) , os , validate ) ; }
@see PainGeneratorIf#generate(Object, OutputStream, boolean)