/** * Inserts a new {@link Dom} node right after the given DOM element. * * @param reference If null, the new element will be inserted at the very beginning. * @param name The element name of the newly inserted item. "*" to indicate that the element name * be determined by the model of the new node. */ public synchronized void insertAfter(Dom reference, String name, Dom newNode) { // TODO: reparent newNode if (name.equals("*")) name = newNode.model.tagName; NodeChild newChild = new NodeChild(name, newNode); if (children.size() == 0) { children = new ArrayList<Child>(); } if (reference == null) { children.add(0, newChild); newNode.domDescriptor = addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey()); return; } ListIterator<Child> itr = children.listIterator(); while (itr.hasNext()) { Child child = itr.next(); if (child instanceof NodeChild) { NodeChild nc = (NodeChild) child; if (nc.dom == reference) { itr.add(newChild); newNode.domDescriptor = addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey()); return; } } } throw new IllegalArgumentException( reference + " is not a valid child of " + this + ". Children=" + children); }
@Test public void rawAttributeTest() throws NoSuchMethodException { String address = listener.getAddress(); Dom raw = Dom.unwrap(listener); Attribute attr = raw.getProxyType().getMethod("getAddress").getAnnotation(Attribute.class); assertEquals(attr.defaultValue(), address); assertEquals(raw.attribute("address"), address); assertEquals(raw.rawAttribute("address"), address); }
/** * Replaces an existing {@link NodeChild} with another one. * * @see #insertAfter(Dom, String, Dom) */ public synchronized void replaceChild(Dom reference, String name, Dom newNode) { ListIterator<Child> itr = children.listIterator(); while (itr.hasNext()) { Child child = itr.next(); if (child instanceof NodeChild) { NodeChild nc = (NodeChild) child; if (nc.dom == reference) { reference.release(); newNode.domDescriptor = addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey()); itr.set(new NodeChild(name, newNode)); return; } } } throw new IllegalArgumentException( reference + " is not a valid child of " + this + ". Children=" + children); }