You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by nd...@apache.org on 2005/06/13 23:08:07 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/dom CoreDocumentImpl.java
nddelima 2005/06/13 14:08:07
Modified: java/src/org/apache/xerces/dom CoreDocumentImpl.java
Log:
Fix to allow adoption of nodes between deferred and non-deferred Xerces DOM Documents.
Revision Changes Path
1.86 +61 -5 xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
Index: CoreDocumentImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- CoreDocumentImpl.java 2 May 2005 22:02:22 -0000 1.85
+++ CoreDocumentImpl.java 13 Jun 2005 21:08:07 -0000 1.86
@@ -1756,13 +1756,30 @@
return null;
}
- //Return null when the source node comes from a different implementation.
+ // Return null if the source is null
+
if (source == null ) {
return null;
} else if (source != null && source.getOwnerDocument() != null) {
- if (this.getImplementation() != source.getOwnerDocument()
- .getImplementation()) {
- return null;
+
+ DOMImplementation thisImpl = this.getImplementation();
+ DOMImplementation otherImpl = source.getOwnerDocument().getImplementation();
+
+ // when the source node comes from a different implementation.
+ if (thisImpl != otherImpl) {
+
+ // Adopting from a DefferedDOM to DOM
+ if (thisImpl instanceof org.apache.xerces.dom.DOMImplementationImpl &&
+ otherImpl instanceof org.apache.xerces.dom.DeferredDOMImplementationImpl) {
+ // traverse the DOM and expand deffered nodes and then allow adoption
+ undeferChildren (node);
+ } else if ( thisImpl instanceof org.apache.xerces.dom.DeferredDOMImplementationImpl
+ && otherImpl instanceof org.apache.xerces.dom.DOMImplementationImpl) {
+ // Adopting from a DOM into a DefferedDOM, this should be okay
+ } else {
+ // Adopting between two dissimilar DOM's is not allowed
+ return null;
+ }
}
}
@@ -1868,6 +1885,45 @@
return node;
}
+ /**
+ * Traverses the DOM Tree and expands deferred nodes and their
+ * children.
+ *
+ */
+ protected void undeferChildren(Node node) {
+
+ Node top = node;
+
+ while (null != node) {
+
+ if (((NodeImpl)node).needsSyncData()) {
+ ((NodeImpl)node).synchronizeData();
+ }
+
+ Node nextNode = null;
+ nextNode = node.getFirstChild();
+
+ while (null == nextNode) {
+
+ if (top.equals(node))
+ break;
+
+ nextNode = node.getNextSibling();
+
+ if (null == nextNode) {
+ node = node.getParentNode();
+
+ if ((null == node) || (top.equals(node))) {
+ nextNode = null;
+ break;
+ }
+ }
+ }
+
+ node = nextNode;
+ }
+ }
+
// identifier maintenence
/**
* Introduced in DOM Level 2
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org