/** * Saves this collection by creating new attachment and deleting removed ones. * * @throws Exception the exception */ public void save() throws Exception { ArrayList<Attachment> attachments = new ArrayList<Attachment>(); for (Attachment attachment : this.getRemovedItems()) { if (!attachment.isNew()) { attachments.add(attachment); } } // If any, delete them by calling the DeleteAttachment web method. if (attachments.size() > 0) { this.internalDeleteAttachments(attachments); } attachments.clear(); // Retrieve a list of attachments that have to be created. for (Attachment attachment : this) { if (attachment.isNew()) { attachments.add(attachment); } } // If there are any, create them by calling the CreateAttachment web // method. if (attachments.size() > 0) { if (this.owner.isAttachment()) { this.internalCreateAttachments(this.owner.getParentAttachment().getId(), attachments); } else { this.internalCreateAttachments(this.owner.getId().getUniqueId(), attachments); } } // Process all of the item attachments in this collection. for (Attachment attachment : this) { ItemAttachment itemAttachment = (ItemAttachment) ((attachment instanceof ItemAttachment) ? attachment : null); if (itemAttachment != null) { // Bug E14:80864: Make sure item was created/loaded before // trying to create/delete sub-attachments if (itemAttachment.getItem() != null) { // Create/delete any sub-attachments itemAttachment.getItem().getAttachments().save(); // Clear the item's change log itemAttachment.getItem().clearChangeLog(); } } } super.clearChangeLog(); }
/** * * Loads from XML. * * @param reader the reader * @param localElementName the local element name * @throws Exception the exception */ @Override protected void loadFromXml(EwsServiceXmlReader reader, String localElementName) throws Exception { reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types, localElementName); reader.readStartElement(XmlNamespace.Types, this.getInnerCollectionXmlElementName()); super.loadFromXml(reader, this.getInnerCollectionXmlElementName()); reader.readEndElementIfNecessary(XmlNamespace.Types, this.getInnerCollectionXmlElementName()); reader.read(); if (reader.isStartElement(XmlNamespace.Types, XmlElementNames.UnknownEntries)) { do { reader.read(); if (reader.isStartElement(XmlNamespace.Types, XmlElementNames.UnknownEntry)) { this.unknownEntries.add(reader.readElementValue()); } } while (!reader.isEndElement(XmlNamespace.Types, XmlElementNames.UnknownEntries)); } }