private static void copyJSOProperties( JavaScriptObject newJso, JavaScriptObject oldJso, boolean deep) { for (Map.Entry<String, Object> entry : JavaScriptObjects.entrySet(oldJso)) { if (JsoProperties.PARENT_NODE_FIELD.equals(entry.getKey())) { // Nothing to do : new cloned node does not have any parent } else if (JsoProperties.STYLE_OBJECT_FIELD.equals(entry.getKey())) { setupStyle(newJso, (Style) entry.getValue()); } else if (JsoProperties.NODE_LIST_FIELD.equals(entry.getKey())) { Node newNode = newJso.cast(); Node oldNode = oldJso.cast(); setupChildNodes(newNode, oldNode, deep); } else if (JsoProperties.ELEM_PROPERTIES.equals(entry.getKey())) { PropertyContainer newPc = JavaScriptObjects.getObject(newJso, JsoProperties.ELEM_PROPERTIES); PropertyContainer oldPc = JavaScriptObjects.getObject(oldJso, JsoProperties.ELEM_PROPERTIES); for (Map.Entry<String, Object> entry2 : oldPc.entrySet()) { newPc.put(entry2.getKey(), entry2.getValue()); } } else if (JavaScriptObject.class.isInstance(entry.getValue())) { JavaScriptObject oldChildJso = (JavaScriptObject) entry.getValue(); JavaScriptObject newChildJso = JavaScriptObjects.newObject(oldChildJso.getClass()); copyJSOProperties(newChildJso, oldChildJso, deep); JavaScriptObjects.setProperty(newJso, entry.getKey(), newChildJso); } else { // copy the property, which should be a String or a primitive type (or // corresponding wrapper object) JavaScriptObjects.setProperty(newJso, entry.getKey(), entry.getValue()); } } }
@PatchMethod static Node cloneNode(Node node, boolean deep) { Node newNode; switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element e = node.cast(); newNode = JavaScriptObjects.newElement(e.getTagName()); break; case Node.DOCUMENT_NODE: newNode = JavaScriptObjects.newObject(Document.class); break; case Node.TEXT_NODE: newNode = JavaScriptObjects.newObject(Text.class); break; default: throw new GwtTestDomException( "Cannot create a Node of type [" + node.getClass().getName() + "]"); } copyJSOProperties(newNode, node, deep); return newNode; }