throw new IllegalArgumentException("Param invoice can't be null. I'm trying to add the Recipient object to that object");
}
if(invoiceElement != null && invoiceElement.getName().equalsIgnoreCase("invoice")) {
final Recipient recipient = RecipientFactory.getInstance();
// get name, zip and city from invoice element (these are required)
recipient.setName(getElementValue(invoiceElement, "name", true));
recipient.setZip(getElementValue(invoiceElement, "zip", true));
recipient.setCity(getElementValue(invoiceElement, "city", true));
// get recipientNo, address1, address2, country from the optional element
final Element optionalElement = invoiceElement.getChild("optional");
if(optionalElement == null) {
log.info("No <optional> element in <invoice> element:\n" + XmlUtils.xmlElement2String(invoiceElement, Format.getPrettyFormat()));
}
else {
recipient.setRecipientNo(getElementValue(optionalElement, "recipientNo", false));
recipient.setOrgNo(getElementValue(optionalElement, "recipientOrgNo", false));
recipient.setAddress1(getElementValue(optionalElement, "address1", false));
recipient.setAddress2(getElementValue(optionalElement, "address2", false));
recipient.setCountry(getElementValue(optionalElement, "country", false));
recipient.setEmail(getElementValue(optionalElement, "email", false));
}
// add recipient to invoice
invoice.setRecipient(recipient);
}