/** * Finds the canonical value-providing document element, which is the first * element with the expected tag name. * * @return the canonical element, or null */ private Doc.E findCanonicalElement() { // NOTE(anorth): this is correct for planned transform semantics where // colliding insertions result in document order matching temporal order. // Current (June 2010) transformation results in the opposite ordering. return DocHelper.getElementWithTagName(getDocument(), valueTagName, container); }
/** * Deletes all non-canonical elements from the document. */ private void cleanup() { Doc.E canonical = findCanonicalElement(); Doc.E toDelete = DocHelper.getLastElementWithTagName(getDocument(), valueTagName, container); while (toDelete != canonical) { getDocument().deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(getDocument(), valueTagName, container); } }
@Override public V set(I initialState) { final Map<String, String> attributes = Initializer.Helper.buildAttributes(initialState, valueFactory); // Insert a new first-child element of the container. Point<Doc.N> insertionPoint = Point.inElement(container, getDocument().getFirstChild(container)); Doc.E element = getDocument().createElement(insertionPoint, valueTagName, attributes); // onElementAdded will create the value object. assert currentElement != null; assert currentValue != null; cleanup(); return currentValue; }
@Override public void clear() { // Delete non-canonical elements first so no events are generated. cleanup(); // Then delete the canonical, which will remove currentValue. Doc.E element = findCanonicalElement(); if (element != null) { getDocument().deleteNode(element); } assert currentElement == null; assert currentValue == null; }
@Override public void setUp() { super.setUp(); target = createSingleton(); doc = target.getDocument(); router = target.getEventRouter(); listener = new Listener(); }
@Override public void setUp() { super.setUp(); target = createSingleton(); doc = target.getDocument(); router = target.getEventRouter(); listener = new Listener(); }