Author: chinthaka
Date: Wed Sep 13 11:41:03 2006
New Revision: 443065
URL: http://svn.apache.org/viewvc?view=rev&rev=443065
Log:
Fixes for
- http://issues.apache.org/jira/browse/WSCOMMONS-97 and
- http://issues.apache.org/jira/browse/WSCOMMONS-96.
Note this change needs to be done for DOOM as well. Will create an issue for
this to be implemented in DOOM and will do it (Ruchith, you wanna give a
helping hand ;) ) after this release.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
Wed Sep 13 11:41:03 2006
@@ -16,12 +16,7 @@
package org.apache.axiom.om.impl.llom;
-import org.apache.axiom.om.OMComment;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -37,10 +32,9 @@
*/
public OMCommentImpl(OMContainer parentNode, String contentText,
OMFactory factory) {
- super(parentNode, factory);
+ super(parentNode, factory, true);
this.value = contentText;
nodeType = OMNode.COMMENT_NODE;
- this.done = true;
}
/**
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
Wed Sep 13 11:41:03 2006
@@ -32,10 +32,9 @@
*/
public OMDocTypeImpl(OMContainer parentNode, String contentText,
OMFactory factory) {
- super(parentNode, factory);
+ super(parentNode, factory, true);
this.value = contentText;
nodeType = OMNode.DTD_NODE;
- this.done = true;
}
/**
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Wed Sep 13 11:41:03 2006
@@ -84,7 +84,7 @@
*/
public OMElementImpl(String localName, OMNamespace ns, OMContainer parent,
OMXMLParserWrapper builder, OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, false);
this.localName = localName;
if (ns != null) {
setNamespace(ns);
@@ -109,17 +109,16 @@
* @param ns - can be null
* @param parent - this should be an OMContainer
* @param factory - factory that created this OMElement
- *
- * A null namespace indicates that the default namespace in scope is used
+ * <p/>
+ * A null namespace indicates that the default namespace
in scope is used
*/
public OMElementImpl(String localName, OMNamespace ns, OMContainer parent,
OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, true);
if (localName == null || localName.trim().length() == 0) {
throw new OMException("localname can not be null or empty");
}
this.localName = localName;
- this.done = true;
if (ns != null) {
setNamespace(ns);
}
@@ -164,7 +163,7 @@
if (ns != null) {
this.ns = ns;
}
- }
+ }
return ns;
}
@@ -243,6 +242,10 @@
child.nextSibling = null;
lastChild = child;
+ if (!child.isComplete()) {
+ this.setComplete(false);
+ }
+
}
/**
@@ -252,7 +255,7 @@
* @throws OMException
*/
public OMNode getNextOMSibling() throws OMException {
- while (!done) {
+ while (!done && builder != null) {
int token = builder.next();
if (token == XMLStreamConstants.END_DOCUMENT) {
throw new OMException("Parser has already reached end of the
document. No siblings found");
@@ -363,9 +366,9 @@
}
public OMNamespace findNamespaceURI(String prefix) {
- OMNamespace ns = this.namespaces==null?
- null:
- (OMNamespace)this.namespaces.get(prefix);
+ OMNamespace ns = this.namespaces == null ?
+ null :
+ (OMNamespace) this.namespaces.get(prefix);
if (ns == null && this.parent instanceof OMElement) {
// try with the parent
@@ -377,7 +380,7 @@
// Constant
static final OMNamespaceImpl xmlns =
new OMNamespaceImpl(OMConstants.XMLNS_URI,
- OMConstants.XMLNS_PREFIX);
+ OMConstants.XMLNS_PREFIX);
/**
* Checks for the namespace <B>only</B> in the current Element.
@@ -389,8 +392,7 @@
}
//If the prefix is available and uri is available and its the xml
namespace
- if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) &&
uri.equals(OMConstants.XMLNS_URI))
- {
+ if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) &&
uri.equals(OMConstants.XMLNS_URI)) {
return xmlns;
}
@@ -483,8 +485,7 @@
this.attributes = new LinkedHashMap(5);
}
OMNamespace namespace = attr.getNamespace();
- if (namespace != null &&
this.findNamespace(namespace.getNamespaceURI(), namespace.getPrefix()) == null)
- {
+ if (namespace != null &&
this.findNamespace(namespace.getNamespaceURI(), namespace.getPrefix()) == null)
{
this.declareNamespace(namespace.getNamespaceURI(),
namespace.getPrefix());
}
@@ -543,7 +544,9 @@
* Forces the parser to proceed, if parser has not yet finished with the
XML input.
*/
public void buildNext() {
- builder.next();
+ if (builder != null) {
+ builder.next();
+ }
}
/**
@@ -597,6 +600,22 @@
return OMNode.ELEMENT_NODE;
}
+ public void build() throws OMException {
+ /**
+ * builder is null. Meaning this is a programatical created element
but it has children which are not completed
+ * Build them all.
+ */
+ if (builder == null && !done) {
+ for (Iterator childrenIterator = this.getChildren();
childrenIterator.hasNext();) {
+ OMNode omNode = (OMNode) childrenIterator.next();
+ omNode.build();
+ }
+ } else {
+ super.build();
+ }
+
+ }
+
/**
* Method getXMLStreamReader.
*
@@ -767,18 +786,19 @@
} else {
//Now the caching is supposed to be off. However caching been
switched off
//has nothing to do if the element is already built!
- if (this.done) {
+ if (this.done || (this.builder == null)) {
OMSerializerUtil.serializeStartpart(this, writer);
OMNodeImpl child = (OMNodeImpl) firstChild;
- while (child != null && ((!(child instanceof OMElement)) ||
child.isComplete())) {
- child.internalSerializeAndConsume(writer);
+ while (child != null) {
+ if ((!(child instanceof OMElement)) || child.isComplete()
|| child.builder == null) {
+ child.internalSerializeAndConsume(writer);
+ } else {
+ OMElement element = (OMElement) child;
+ element.getBuilder().setCache(false);
+ OMSerializerUtil.serializeByPullStream(element,
writer, cache);
+ }
child = child.nextSibling;
}
- if (child != null) {
- OMElement element = (OMElement) child;
- element.getBuilder().setCache(false);
- OMSerializerUtil.serializeByPullStream(element, writer,
cache);
- }
OMSerializerUtil.serializeEndpart(writer);
} else {
OMSerializerUtil.serializeByPullStream(this, writer, cache);
@@ -901,7 +921,7 @@
* @throws OMException
*/
public void discard() throws OMException {
- if (done) {
+ if (done || builder == null) {
this.detach();
} else {
builder.discard(this);
@@ -934,19 +954,34 @@
return lineNumber;
}
- /* (non-Javadoc)
- * @see org.apache.axiom.om.OMNode#buildAll()
- */
- public void buildWithAttachments() {
- if (!done)
- {
- this.build();
- }
- Iterator iterator = getChildren();
- while(iterator.hasNext())
- {
- OMNode node = (OMNode)iterator.next();
- node.buildWithAttachments();
- }
- }
+ /* (non-Javadoc)
+ * @see org.apache.axiom.om.OMNode#buildAll()
+ */
+ public void buildWithAttachments() {
+ if (!done) {
+ this.build();
+ }
+ Iterator iterator = getChildren();
+ while (iterator.hasNext()) {
+ OMNode node = (OMNode) iterator.next();
+ node.buildWithAttachments();
+ }
+ }
+
+ /**
+ * This method will be called when one of the children becomes complete.
+ */
+ protected void notifyChildComplete() {
+ if (!this.done && builder == null) {
+ Iterator iterator = getChildren();
+ while (iterator.hasNext()) {
+ OMNode node = (OMNode) iterator.next();
+ if (!node.isComplete()) {
+ return;
+ }
+ }
+ this.setComplete(true);
+ }
+ }
}
+
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
Wed Sep 13 11:41:03 2006
@@ -76,7 +76,8 @@
* @param parent Parent <code>OMContainer</code> of this node
* @param factory The <code>OMFactory</code> that created this
*/
- public OMNodeImpl(OMContainer parent, OMFactory factory) {
+ public OMNodeImpl(OMContainer parent, OMFactory factory, boolean done) {
+ this.done = done;
if ((parent != null)) {
this.parent = (OMContainerEx) parent;
parent.addChild(this);
@@ -161,6 +162,13 @@
*/
public void setComplete(boolean state) {
this.done = state;
+ if(parent != null){
+ if(!done) {
+ parent.setComplete(false);
+ }else if(parent instanceof OMElementImpl){
+ ((OMElementImpl) parent).notifyChildComplete();
+ }
+ }
}
/**
@@ -296,21 +304,21 @@
builder.next();
}
}
-
- /**
- * Parses this node and builds the object structure in memory. AXIOM
- * supports two levels of deffered building. First is deffered building
of
- * AXIOM using StAX. Second level is the deffered building of
attachments.
- * AXIOM reads in the attachements from the stream only when user asks
by
- * calling getDataHandler(). build() method builds the OM without the
- * attachments. buildAll() builds the OM together with attachement data.
- * This becomes handy when user wants to free the input stream.
- */
- public void buildWithAttachments() {
- if (!this.done) {
- this.build();
- }
- }
+
+ /**
+ * Parses this node and builds the object structure in memory. AXIOM
+ * supports two levels of deffered building. First is deffered building of
+ * AXIOM using StAX. Second level is the deffered building of attachments.
+ * AXIOM reads in the attachements from the stream only when user asks by
+ * calling getDataHandler(). build() method builds the OM without the
+ * attachments. buildAll() builds the OM together with attachement data.
+ * This becomes handy when user wants to free the input stream.
+ */
+ public void buildWithAttachments() {
+ if (!this.done) {
+ this.build();
+ }
+ }
/**
* Serializes the node with caching.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
Wed Sep 13 11:41:03 2006
@@ -16,12 +16,7 @@
package org.apache.axiom.om.impl.llom;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMProcessingInstruction;
+import org.apache.axiom.om.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -39,7 +34,7 @@
*/
public OMProcessingInstructionImpl(OMContainer parentNode, String target,
String value, OMFactory factory) {
- super(parentNode, factory);
+ super(parentNode, factory, true);
this.target = (target == null) ? null : target.trim();
this.value = (value == null) ? null : value.trim();
nodeType = OMNode.PI_NODE;
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Wed Sep 13 11:41:03 2006
@@ -16,15 +16,7 @@
package org.apache.axiom.om.impl.llom;
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMDataSource;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.*;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -724,4 +716,12 @@
node.buildWithAttachments();
}
}
+
+ public void build() throws OMException {
+ super.build();
+ }
+
+ protected void notifyChildComplete() {
+ super.notifyChildComplete();
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
Wed Sep 13 11:41:03 2006
@@ -88,9 +88,7 @@
* Constants for this can be found in OMNode.
*/
public OMTextImpl(String s, int nodeType, OMFactory factory) {
- super(factory);
- this.value = s == null ? EMTPY_STRING : s;
- this.nodeType = nodeType;
+ this(null, s, nodeType, factory);
}
/**
@@ -105,17 +103,15 @@
public OMTextImpl(OMContainer parent, String text, int nodeType,
OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, true);
this.value = text == null ? EMTPY_STRING : text;
- done = true;
this.nodeType = nodeType;
}
public OMTextImpl(OMContainer parent, char[] charArray, int nodeType,
OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, true);
this.charArray = charArray;
- done = true;
this.nodeType = nodeType;
}
@@ -126,10 +122,9 @@
public OMTextImpl(OMContainer parent, QName text, int nodeType,
OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, true);
this.textNS = ((OMElementImpl) parent).handleNamespace(text);
this.value = text == null ? EMTPY_STRING : text.getLocalPart();
- done = true;
this.nodeType = nodeType;
}
@@ -187,7 +182,7 @@
*/
public OMTextImpl(String contentID, OMContainer parent,
OMXMLParserWrapper builder, OMFactory factory) {
- super(parent, factory);
+ super(parent, factory, false);
this.contentID = contentID;
this.optimize = true;
this.isBinary = true;
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java?view=diff&rev=443065&r1=443064&r2=443065
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
Wed Sep 13 11:41:03 2006
@@ -17,6 +17,11 @@
package org.apache.axiom.om;
import junit.framework.TestCase;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayInputStream;
/**
* Each of the following tests have a parent "person" and children "name",
"age", "weight".
@@ -34,253 +39,253 @@
*/
public class SerializationTest extends TestCase {
- private static final String NS =
"http://ws.apache.org/axis2/apacheconasia/06";
- private static final String PREFIX = "prefix";
-
+ private static final String NS =
"http://ws.apache.org/axis2/apacheconasia/06";
+ private static final String PREFIX = "prefix";
+
public void testDParentDChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, "");
OMNamespace nsChildren = fac.createOMNamespace(NS, "");
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",2,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
}
-
+
public void testDParentUChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, "");
OMNamespace nsChildren = fac.createOMNamespace("", "");
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",2,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect namespace serialization",4,
xml.split("\"\"").length);
}
-
+
public void testDParentQChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, "");
OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",5,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
}
-
-
+
+
public void testQParentQChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",2,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
}
-
+
public void testQParentUChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
OMNamespace nsChildren = fac.createOMNamespace("", "");
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect default namespace serialization",2,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect namespace serialization",1,
xml.split("\"\"").length);
}
-
+
public void testQParentDChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
OMNamespace nsChildren = fac.createOMNamespace(NS, "");
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect default namespace serialization",5,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
}
-
+
public void testUParentUChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace("", "");
OMNamespace nsChildren = fac.createOMNamespace("", "");
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect default namespace serialization",1,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect namespace serialization",1,
xml.split("\"\"").length);
}
-
+
public void testUParentQChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace("", "");
OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect default namespace serialization",4,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect namespace serialization",1,
xml.split("\"\"").length);
}
-
+
public void testUParentDChildren() {
OMFactory fac = OMAbstractFactory.getOMFactory();
-
+
OMNamespace nsParent = fac.createOMNamespace("", "");
OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
+
OMElement personElem = fac.createOMElement("person", nsParent);
OMElement nameElem = fac.createOMElement("name", nsChildren);
nameElem.setText("John");
-
+
OMElement ageElem = fac.createOMElement("age", nsChildren);
ageElem.setText("34");
-
+
OMElement weightElem = fac.createOMElement("weight", nsChildren);
weightElem.setText("50");
-
+
//Add children to the person element
personElem.addChild(nameElem);
personElem.addChild(ageElem);
personElem.addChild(weightElem);
-
+
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",4,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect namespace serialization",1,
xml.split("\"\"").length);
}
-
-
-
-
-
+
+
+
+
+
/**
* Special case when OMElement is created with a null OMNamespace.
* In this case, that element must always belongs to the default, default
namespace
@@ -296,10 +301,32 @@
personElem.addChild(nameElem);
String xml = personElem.toString();
-
+
assertEquals("Incorrect namespace serialization",2,
xml.split("http://ws.apache.org/axis2/apacheconasia/06").length);
assertEquals("Incorrect serialization", 2,
xml.split("xmlns=\"\"").length);
-
+
+ }
+
+ public void testOMSerializationWithTwoNonBuiltOMElements(){
+ try {
+ String sampleXMLOne =
"<ChildOne><Name>ChildName</Name></ChildOne>";
+ String sampleXMLTwo =
"<ChildTwo><Name>ChildName</Name></ChildTwo>";
+
+ String expectedXML =
"<Root><ChildOne><Name>ChildName</Name></ChildOne><ChildTwo><Name>ChildName</Name></ChildTwo></Root>";
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+
+ OMElement rootElement = omFactory.createOMElement("Root", null);
+ OMElement childOne = new StAXOMBuilder(new
ByteArrayInputStream(sampleXMLOne.getBytes())).getDocumentElement();
+ ((OMNodeEx) childOne).setParent(null);
+ rootElement.addChild(childOne);
+ OMElement childTwo = new StAXOMBuilder(new
ByteArrayInputStream(sampleXMLTwo.getBytes())).getDocumentElement();
+ ((OMNodeEx) childTwo).setParent(null);
+ rootElement.addChild(childTwo);
+
+ assertTrue(expectedXML.equals(rootElement.toString()));
+ } catch (XMLStreamException e) {
+ e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ }
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]