/** * Sets the isDirty flag to true and triggers dispatch of the change event * to the owner of the property bag. Changed must be called whenever an * operation that changes the state of this property bag is performed (e.g. * adding or removing a property). */ public void changed() { this.isDirty = true; this.getOwner().changed(); }
/** * Initializes a ComplexProperty instance. When a property is inserted into * the bag, it needs to be initialized in order for changes that occur on * that property to be properly detected and dispatched. * * @param complexProperty The ComplexProperty instance to initialize. */ private void initComplexProperty(ComplexProperty complexProperty) { if (complexProperty != null) { complexProperty.addOnChangeEvent(this); if (complexProperty instanceof IOwnedProperty) { IOwnedProperty ownedProperty = (IOwnedProperty) complexProperty; ownedProperty.setOwner(this.getOwner()); } } }
/** * Writes the EWS update operations corresponding to the changes that * occurred in the bag to XML. * * @param writer The writer to write the updates to. * @throws Exception the exception */ public void writeToXmlForUpdate(EwsServiceXmlWriter writer) throws Exception { writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getChangeXmlElementName()); this.getOwner().getId().writeToXml(writer); writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Updates); for (PropertyDefinition propertyDefinition : this.addedProperties) { this.writeSetUpdateToXml(writer, propertyDefinition); } for (PropertyDefinition propertyDefinition : this.modifiedProperties) { this.writeSetUpdateToXml(writer, propertyDefinition); } Iterator<Entry<PropertyDefinition, Object>> it = this.deletedProperties .entrySet().iterator(); while (it.hasNext()) { Entry<PropertyDefinition, Object> property = it.next(); this.writeDeleteUpdateToXml(writer, property.getKey(), property .getValue()); } writer.writeEndElement(); writer.writeEndElement(); }
/** * Checks if is requested property. * * @param propertyDefinition the property definition * @return true, if is requested property */ private boolean isRequestedProperty(PropertyDefinition propertyDefinition) { // If no requested property set, then property wasn't requested. if (this.requestedPropertySet == null) { return false; } // If base property set is all first-class property, use the // appropriate list of // property definitions to see if this property was requested. // Otherwise, property had // to be explicitly requested and needs to be listed in // AdditionalProperties. if (this.requestedPropertySet.getBasePropertySet() == BasePropertySet.FirstClassProperties) { List<PropertyDefinition> firstClassProps = this.onlySummaryPropertiesRequested ? this .getOwner().getSchema().getFirstClassSummaryProperties() : this.getOwner().getSchema().getFirstClassProperties(); return firstClassProps.contains(propertyDefinition) || this.requestedPropertySet.contains(propertyDefinition); } else { return this.requestedPropertySet.contains(propertyDefinition); } }
/** * Writes the bag's property to XML. * * @param writer The writer to write the property to. * @throws Exception the exception */ public void writeToXml(EwsServiceXmlWriter writer) throws Exception { writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getXmlElementName()); Iterator<PropertyDefinition> it = this.getOwner().getSchema() .iterator(); while (it.hasNext()) { PropertyDefinition propertyDefinition = it.next(); // The following test should not be necessary since the property bag // prevents // property to be set if they don't have the CanSet flag, but it // doesn't hurt... if (propertyDefinition .hasFlag(PropertyDefinitionFlags.CanSet, writer.getService().getRequestedServerVersion())) { if (this.contains(propertyDefinition)) { propertyDefinition.writePropertyValueToXml(writer, this, false /* isUpdateOperation */); } } } writer.writeEndElement(); }
(ICustomXmlUpdateSerializer) propertyValue; handled = updateSerializer.writeSetUpdateToXml(writer, this .getOwner(), propertyDefinition); writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getSetFieldXmlElementName()); writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getXmlElementName()); propertyDefinition
if (propertyDefinition.getVersion().ordinal() > this.getOwner() .getService().getRequestedServerVersion().ordinal()) { throw new ServiceVersionException(String.format( if (this.getOwner().isNew() && !propertyDefinition .hasFlag(PropertyDefinitionFlags.CanSet, this.getOwner() .getService().getRequestedServerVersion())) { throw new ServiceObjectPropertyException("This property is read-only and can't be set.", propertyDefinition); if (!this.getOwner().isNew()) { if ((this.getOwner() instanceof Item)) { Item ownerItem = (Item) this.getOwner(); if (ownerItem.isAttachment()) { throw new ServiceObjectPropertyException("Item attachments can't be updated.",
/** * Gets the property instance. * * @param propertyBag The property bag. * @param complexProperty The property instance. * @return True if the instance is newly created. */ private boolean getPropertyInstance( final PropertyBag propertyBag, final OutParam<ComplexProperty> complexProperty ) { final ServiceObject owner = propertyBag.getOwner(); final ExchangeService service = owner.getService(); if (!propertyBag.tryGetValue(this, complexProperty) || !hasFlag(PropertyDefinitionFlags.ReuseInstance, service.getRequestedServerVersion())) { complexProperty.setParam(createPropertyInstance(owner)); return true; } return false; }
serviceExceptionOutParam.setParam(null); if (propertyDefinition.getVersion().ordinal() > this.getOwner() .getService().getRequestedServerVersion().ordinal()) { serviceExceptionOutParam.setParam(new ServiceVersionException( (ComplexPropertyDefinitionBase) propertyDefinition; ComplexProperty propertyValue = complexPropertyDefinition .createPropertyInstance(getOwner()); if (propertyDefinition != this.getOwner() .getIdPropertyDefinition()) { if (!this.isPropertyLoaded(propertyDefinition)) {
/** * Internals the load from XML. * * @param reader The reader. * @param propertyBag The property bag. * @throws Exception the exception */ protected void internalLoadFromXml( final EwsServiceXmlReader reader, final PropertyBag propertyBag ) throws Exception { final OutParam<ComplexProperty> complexProperty = new OutParam<ComplexProperty>(); final boolean justCreated = getPropertyInstance(propertyBag, complexProperty); if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems, propertyBag.getOwner().getService().getRequestedServerVersion())) { final ComplexProperty c = complexProperty.getParam(); c.updateFromXml(reader, reader.getLocalName()); } else { final ComplexProperty c = complexProperty.getParam(); c.loadFromXml(reader, reader.getLocalName()); } propertyBag.setObjectFromPropertyDefinition(this, complexProperty .getParam()); }
/** * Sets the isDirty flag to true and triggers dispatch of the change event * to the owner of the property bag. Changed must be called whenever an * operation that changes the state of this property bag is performed (e.g. * adding or removing a property). */ public void changed() { this.isDirty = true; this.getOwner().changed(); }
/** * Initializes a ComplexProperty instance. When a property is inserted into * the bag, it needs to be initialized in order for changes that occur on * that property to be properly detected and dispatched. * * @param complexProperty The ComplexProperty instance to initialize. */ private void initComplexProperty(ComplexProperty complexProperty) { if (complexProperty != null) { complexProperty.addOnChangeEvent(this); if (complexProperty instanceof IOwnedProperty) { IOwnedProperty ownedProperty = (IOwnedProperty) complexProperty; ownedProperty.setOwner(this.getOwner()); } } }
/** * Writes the EWS update operations corresponding to the changes that * occurred in the bag to XML. * * @param writer The writer to write the updates to. * @throws Exception the exception */ public void writeToXmlForUpdate(EwsServiceXmlWriter writer) throws Exception { writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getChangeXmlElementName()); this.getOwner().getId().writeToXml(writer); writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Updates); for (PropertyDefinition propertyDefinition : this.addedProperties) { this.writeSetUpdateToXml(writer, propertyDefinition); } for (PropertyDefinition propertyDefinition : this.modifiedProperties) { this.writeSetUpdateToXml(writer, propertyDefinition); } Iterator<Entry<PropertyDefinition, Object>> it = this.deletedProperties .entrySet().iterator(); while (it.hasNext()) { Entry<PropertyDefinition, Object> property = it.next(); this.writeDeleteUpdateToXml(writer, property.getKey(), property .getValue()); } writer.writeEndElement(); writer.writeEndElement(); }
/** * Checks if is requested property. * * @param propertyDefinition the property definition * @return true, if is requested property */ private boolean isRequestedProperty(PropertyDefinition propertyDefinition) { // If no requested property set, then property wasn't requested. if (this.requestedPropertySet == null) { return false; } // If base property set is all first-class property, use the // appropriate list of // property definitions to see if this property was requested. // Otherwise, property had // to be explicitly requested and needs to be listed in // AdditionalProperties. if (this.requestedPropertySet.getBasePropertySet() == BasePropertySet.FirstClassProperties) { List<PropertyDefinition> firstClassProps = this.onlySummaryPropertiesRequested ? this .getOwner().getSchema().getFirstClassSummaryProperties() : this.getOwner().getSchema().getFirstClassProperties(); return firstClassProps.contains(propertyDefinition) || this.requestedPropertySet.contains(propertyDefinition); } else { return this.requestedPropertySet.contains(propertyDefinition); } }
/** * Writes the bag's property to XML. * * @param writer The writer to write the property to. * @throws Exception the exception */ public void writeToXml(EwsServiceXmlWriter writer) throws Exception { writer.writeStartElement(XmlNamespace.Types, this.getOwner() .getXmlElementName()); Iterator<PropertyDefinition> it = this.getOwner().getSchema() .iterator(); while (it.hasNext()) { PropertyDefinition propertyDefinition = it.next(); // The following test should not be necessary since the property bag // prevents // property to be set if they don't have the CanSet flag, but it // doesn't hurt... if (propertyDefinition .hasFlag(PropertyDefinitionFlags.CanSet, writer.getService().getRequestedServerVersion())) { if (this.contains(propertyDefinition)) { propertyDefinition.writePropertyValueToXml(writer, this, false /* isUpdateOperation */); } } } writer.writeEndElement(); }
/** * Gets the property instance. * * @param propertyBag The property bag. * @param complexProperty The property instance. * @return True if the instance is newly created. */ private boolean getPropertyInstance( final PropertyBag propertyBag, final OutParam<ComplexProperty> complexProperty ) { final ServiceObject owner = propertyBag.getOwner(); final ExchangeService service = owner.getService(); if (!propertyBag.tryGetValue(this, complexProperty) || !hasFlag(PropertyDefinitionFlags.ReuseInstance, service.getRequestedServerVersion())) { complexProperty.setParam(createPropertyInstance(owner)); return true; } return false; }
/** * Internals the load from XML. * * @param reader The reader. * @param propertyBag The property bag. * @throws Exception the exception */ protected void internalLoadFromXml( final EwsServiceXmlReader reader, final PropertyBag propertyBag ) throws Exception { final OutParam<ComplexProperty> complexProperty = new OutParam<ComplexProperty>(); final boolean justCreated = getPropertyInstance(propertyBag, complexProperty); if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems, propertyBag.getOwner().getService().getRequestedServerVersion())) { final ComplexProperty c = complexProperty.getParam(); c.updateFromXml(reader, reader.getLocalName()); } else { final ComplexProperty c = complexProperty.getParam(); c.loadFromXml(reader, reader.getLocalName()); } propertyBag.setObjectFromPropertyDefinition(this, complexProperty .getParam()); }