/** * Deletes an entry from the document. * * @param entry */ private void invalidateEntry(E entry) { if (entry != null && activeCleanUp) { assert getDocument().getParentElement(entry).equals(container); obsoleteEntries.add(entry); } }
@Override public void onElementAdded(E element) { assert getDocument().getParentElement(element).equals(parent) : "Received event for unrelated element"; if (childTag.equals(getDocument().getTagName(element))) { T child = factory.adapt(router, element); T sibling = getPreviousKnownValue(element); orderedValues.add(sibling == null ? 0 : orderedValues.indexOf(sibling) + 1, child); elementToValue.put(element, child); valueToElement.put(child, element); fireElementAdded(child); } }
@Override public void onElementAdded(E element) { ObservableMutableDocument<? super E, E, ?> doc = getDocument(); assert container.equals(doc.getParentElement(element)); if (!WaveletBasedSupplement.CONVERSATION_TAG.equals(doc.getTagName(element))) { return; } WaveletId waveletId = valueOf(element); if (waveletId != null) { WaveletThreadState existing = waveletSupplements.get(waveletId); if (existing == null) { WaveletThreadState read = DocumentBasedWaveletThreadState.create(router, element, waveletId, listener); waveletSupplements.put(waveletId, read); } else { // // We can't mutate during callbacks yet. // Let's just ignore the latter :(. Clean up on timer? // } } else { // XML error: someone added a WAVELET element without an id. Ignore. // TODO(user): we should log this } }
/** * Handles a new element being added to the container. If it represents a new * value, that value is recorded. If it represents a value already in this * container, either the old element or the new element is marked obsolete. * The element marked obsolete is the one that appears later in the document. */ private void handleElementAdded(E newElement) { ObservableMutableDocument<? super E, E, ?> document = getDocument(); assert container.equals(document.getParentElement(newElement)); if (!entryTagName.equals(document.getTagName(newElement))) { return; } T value = valueOf(newElement); E oldEntry = valueElements.get(value); if (oldEntry == null) { // Entry is for a new value - add it to the element map and fire an event // to collection listeners valueElements.put(value, newElement); fireOnValueAdded(value); } else if (document.getLocation(oldEntry) < document.getLocation(newElement)) { // newEntry is not needed, so mark it obsolete obsoleteElements.add(newElement); } else { // oldEntry is no needed, so mark it obsoleted and use the new one instead obsoleteElements.add(oldEntry); valueElements.put(value, newElement); } }
@Override public void onElementAdded(E newElement) { ObservableMutableDocument<? super E, E, ?> document = getDocument(); assert container.equals(document.getParentElement(newElement)); if (!tag.equals(document.getTagName(newElement))) { return; } // Possibly changing an existing value? if (valueElement != null) { if (document.getLocation(newElement) < document.getLocation(valueElement)) { // New element loses. redundantElements.add(newElement); } else { // New element wins. redundantElements.add(valueElement); changeValue(newElement); } } else { // New element is the new value. changeValue(newElement); } }
/** * Updates the entry cache, if necessary, in response to an entry element * being added. * * This method also aggressively deletes any entries that are not greater * than the cached entry. */ @Override public void onElementAdded(E entry) { ObservableMutableDocument<? super E, E, ?> document = getDocument(); assert container.equals(document.getParentElement(entry)); if (!entryTagName.equals(document.getTagName(entry))) { return; } C newValue = valueOf(entry); C oldValue = get(); // If the new value should end up in the cache, delete the old one (if applicable) and update // the entry cache. // Otherwise, the new value is aggressively deleted. if (oldValue == null || oldValue.compareTo(newValue) < 0) { invalidateCacheEntry(); // This should clean up the old entry in onEntryRemoved. value = entry; triggerOnEntryChanged(oldValue, newValue); } else { invalidateEntry(entry); } }
@Override public void onElementAdded(E element) { ObservableMutableDocument<? super E, E, ?> doc = getDocument(); assert container.equals(doc.getParentElement(element)); if (!WaveletBasedSupplement.GADGET_TAG.equals(doc.getTagName(element))) { return; } String gadgetId = valueOf(element); if (gadgetId != null) { GadgetState existing = gadgetSupplements.get(gadgetId); if (existing == null) { GadgetState state = DocumentBasedGadgetState.create(router, element, gadgetId, listener); gadgetSupplements.put(gadgetId, state); // TODO(user): Follow the changes in WaveletReadStateCollection and update this class. // // NOTE(user): it is important that these events get fired after the new read-state // object is added to the map above, in order that the interface presented by this // collection object is consistent with the events being broadcast to the listener. // listener.onGadgetStateChanged(gadgetId, null, null, null); } else { // TODO(user): Follow the changes in WaveletReadStateCollection and update this class. } } else { // XML error: someone added a WAVELET element without an id. Ignore. // TODO(user): log this at error level, once loggers are injected into // these classes. // TODO(user): Follow the changes in WaveletReadStateCollection and update this class. } }
/** * Updates the entry cache, if necessary, in response to an entry element * being added. */ @Override public void onElementAdded(E entry) { assert getDocument().getParentElement(entry).equals(container) : "Received event for unrelated element"; if (!entryTagName.equals(getDocument().getTagName(entry))) { return; } K key = keyOf(entry); V newValue = valueOf(entry); E oldEntry = entries.get(key); V oldValue = oldEntry != null ? valueOf(oldEntry) : null; // If the new value should end up in the cache, delete the old one (if applicable) and update // the entry cache. // Otherwise, the new value is aggressively deleted. if (canReplace(oldEntry, entry, oldValue, newValue)) { invalidateCurrentCacheEntry(key); entries.put(key, entry); triggerOnEntryChanged(key, oldValue, newValue); } else { invalidateEntry(entry); } }
@Override public void onElementAdded(E element) { assert container == getDocument().getParentElement(element); if (!WaveletBasedSupplement.WAVELET_TAG.equals(getDocument().getTagName(element))) { return;
if (event.getType() == Type.CONTENT_INSERTED) { E inserted = ((ContentInserted<N, E, T>) event).getSubtreeElement(); E parent = doc.getParentElement(inserted); CopyOnWriteSet<ElementListener<E>> listeners = elementListenerMap.get(parent); if (listeners != null) {