Author: veithen
Date: Sat Dec 6 10:46:11 2008
New Revision: 724027
URL: http://svn.apache.org/viewvc?rev=724027&view=rev
Log:
OMDOMFactory: Support creating a text node as a child of a Document node. This
should be allowed (at least if the text node contains whitespace only), but the
code made the assumption that the parent of a text node is always an element.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=724027&r1=724026&r2=724027&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Sat Dec 6 10:46:11 2008
@@ -216,10 +216,11 @@
* @see org.apache.axiom.om.OMFactory#createOMText(
org.apache.axiom.om.OMElement,String)
*/
public OMText createOMText(OMContainer parent, String text) {
- ElementImpl parentElem = (ElementImpl) parent;
- TextImpl txt = new TextImpl((DocumentImpl) parentElem
- .getOwnerDocument(), text, this);
- parentElem.addChild(txt);
+ // A text node can also be added as the child of a Document node (at
least if
+ // it contains whitespace only). Therefore we can't assume that the
parent is
+ // an element and we need to use getDocumentFromParent instead.
+ TextImpl txt = new TextImpl(getDocumentFromParent(parent), text, this);
+ parent.addChild(txt);
return txt;
}
@@ -337,14 +338,7 @@
}
public OMComment createOMComment(OMContainer parent, String content) {
- DocumentImpl doc;
- if (parent instanceof DocumentImpl) {
- doc = (DocumentImpl) parent;
- } else {
- doc = (DocumentImpl) ((ParentNode) parent).getOwnerDocument();
- }
-
- CommentImpl comment = new CommentImpl(doc, content, this);
+ CommentImpl comment = new CommentImpl(getDocumentFromParent(parent),
content, this);
parent.addChild(comment);
return comment;
}
@@ -358,4 +352,11 @@
return this.document;
}
+ private DocumentImpl getDocumentFromParent(OMContainer parent) {
+ if (parent instanceof DocumentImpl) {
+ return (DocumentImpl) parent;
+ } else {
+ return (DocumentImpl) ((ParentNode) parent).getOwnerDocument();
+ }
+ }
}