You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2005/08/22 11:31:11 UTC
svn commit: r234458 - in /webservices/axis/trunk/java/modules:
saaj/src/org/apache/axis2/saaj/ saaj/test/org/apache/axis2/saaj/
xml/src/org/apache/axis2/om/impl/llom/
Author: ajith
Date: Mon Aug 22 02:30:39 2005
New Revision: 234458
URL: http://svn.apache.org/viewcvs?rev=234458&view=rev
Log:
Updated the serialization code to fix a long running bug. Now the serialization code is much cleaner and efficient
1. OMElementImpl.java,OMSerializerUtil.java,OMTextImpl.java,OMCommentImpl.java are modified to go with the new serialization
2.SOAPMessageImpl.java had a problem (some buggy code actually :))in the writeTo method. It's fixed now.
Modified:
webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
webservices/axis/trunk/java/modules/saaj/test/org/apache/axis2/saaj/EnvelopeTest.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java Mon Aug 22 02:30:39 2005
@@ -123,7 +123,7 @@
* @throws SOAPException
* @see javax.xml.soap.SOAPEnvelope#getBody()
*/
- public SOAPBody getBody() throws SOAPException {
+ public SOAPBody getBody() throws SOAPException {
org.apache.axis2.soap.SOAPBody omSOAPBody = null;
try {
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java Mon Aug 22 02:30:39 2005
@@ -201,8 +201,9 @@
public void writeTo(OutputStream out) throws SOAPException, IOException {
try {
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
+ //the writeTo method forces the elements to be built!!!
((SOAPEnvelopeImpl) mSOAPPart.getEnvelope()).getOMEnvelope()
- .serialize(writer);
+ .serializeWithCache(writer);
writer.flush();
} catch (Exception e) {
throw new SOAPException(e);
Modified: webservices/axis/trunk/java/modules/saaj/test/org/apache/axis2/saaj/EnvelopeTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/test/org/apache/axis2/saaj/EnvelopeTest.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/test/org/apache/axis2/saaj/EnvelopeTest.java (original)
+++ webservices/axis/trunk/java/modules/saaj/test/org/apache/axis2/saaj/EnvelopeTest.java Mon Aug 22 02:30:39 2005
@@ -45,11 +45,12 @@
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage smsg =
mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
- SOAPPart sp = smsg.getSOAPPart();
- SOAPEnvelope se = sp.getEnvelope();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- smsg.writeTo(baos);
- SOAPBody body = smsg.getSOAPPart().getEnvelope().getBody();
+ //It seems that the aim of this writing is to completely build the object tree. The
+ smsg.writeTo(System.out);
+
+ SOAPEnvelope envelope = smsg.getSOAPPart().getEnvelope();
+
+ SOAPBody body = envelope.getBody();
assertTrue(body != null);
}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java Mon Aug 22 02:30:39 2005
@@ -55,10 +55,6 @@
public void serializeWithCache(OMOutputImpl omOutput) throws XMLStreamException {
XMLStreamWriter writer = omOutput.getXmlStreamWriter();
writer.writeComment(this.value);
- OMNode nextSibling = this.getNextSibling();
- if (nextSibling != null) {
- nextSibling.serializeWithCache(omOutput);
- }
}
/**
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Mon Aug 22 02:30:39 2005
@@ -630,54 +630,35 @@
protected void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
- // select the builder
- short builderType = PULL_TYPE_BUILDER; // default is pull type
- if (builder != null) {
- builderType = this.builder.getBuilderType();
- }
- if ((builderType == PUSH_TYPE_BUILDER)
- && (builder.getRegisteredContentHandler() == null)) {
- builder.registerExternalContentHandler(
- new StreamWriterToContentHandlerConverter(omOutput));
- }
-
+ if (cache){
+ //in this case we don't care whether the elements are built or not
+ //we just call the serialize methods
+ OMSerializerUtil.serializeStartpart(this, omOutput);
+ //serilize children
+ Iterator children = this.getChildren();
+ while (children.hasNext()) {
+ ((OMNode)children.next()).serializeWithCache(omOutput);
+ }
+ OMSerializerUtil.serializeEndpart(omOutput);
- if (!cache) {
- //No caching
- if (this.firstChild != null) {
+ }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){
OMSerializerUtil.serializeStartpart(this, omOutput);
- firstChild.serialize(omOutput);
- OMSerializerUtil.serializeEndpart(omOutput);
- } else if (!this.done) {
- if (builderType == PULL_TYPE_BUILDER) {
- OMSerializerUtil.serializeByPullStream(this, omOutput);
- } else {
- OMSerializerUtil.serializeStartpart(this, omOutput);
- builder.setCache(cache);
- builder.next();
- OMSerializerUtil.serializeEndpart(omOutput);
+ //serialize children
+ Iterator children = this.getChildren();
+ while (children.hasNext()) {
+ ((OMNode)children.next()).serializeWithCache(omOutput);
}
- } else {
- OMSerializerUtil.serializeNormal(this, omOutput, cache);
+ OMSerializerUtil.serializeEndpart(omOutput);
+ } else{
+ //take the XMLStream reader and feed it to the stream serilizer.
+ //todo is this right ?????
+ OMSerializerUtil.serializeByPullStream(this, omOutput,cache);
}
- //serilize siblings
- if (this.nextSibling != null) {
- nextSibling.serialize(omOutput);
- } else if (this.parent != null) {
- if (!this.parent.isComplete()) {
- builder.setCache(cache);
- builder.next();
- }
- }
- } else {
- //Cached
- OMSerializerUtil.serializeNormal(this, omOutput, cache);
- // serialize the siblings
- OMNode nextSibling = this.getNextSibling();
- if (nextSibling != null) {
- nextSibling.serializeWithCache(omOutput);
- }
+
}
}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java Mon Aug 22 02:30:39 2005
@@ -33,7 +33,7 @@
/**
* Method serializeEndpart
*
- * @param writer
+ * @param omOutput
* @throws javax.xml.stream.XMLStreamException
*
*/
@@ -46,7 +46,7 @@
* Method serializeAttribute
*
* @param attr
- * @param writer
+ * @param omOutput
* @throws XMLStreamException
*/
public static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)
@@ -78,7 +78,7 @@
* Method serializeNamespace
*
* @param namespace
- * @param writer
+ * @param omOutput
* @throws XMLStreamException
*/
public static void serializeNamespace(OMNamespace namespace, org.apache.axis2.om.impl.OMOutputImpl omOutput)
@@ -100,7 +100,7 @@
/**
* Method serializeStartpart
*
- * @param writer
+ * @param omOutput
* @throws XMLStreamException
*/
public static void serializeStartpart(OMElementImpl element, OMOutputImpl omOutput)
@@ -173,7 +173,7 @@
/**
* Method serializeNormal
*
- * @param writer
+ * @param omOutput
* @param cache
* @throws XMLStreamException
*/
@@ -197,9 +197,20 @@
}
public static void serializeByPullStream(OMElementImpl element, org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+ serializeByPullStream(element,omOutput,false);
+ }
+
+ public static void serializeByPullStream(OMElementImpl element, org.apache.axis2.om.impl.OMOutputImpl omOutput,boolean cache) throws XMLStreamException {
StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
- streamingOMSerializer.serialize(element.getXMLStreamReaderWithoutCaching(),
+ if (cache){
+ streamingOMSerializer.serialize(element.getXMLStreamReader(),
+ omOutput);
+ }else{
+ streamingOMSerializer.serialize(element.getXMLStreamReaderWithoutCaching(),
omOutput);
+ }
+
+
return;
}
}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=234458&r1=234457&r2=234458&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Mon Aug 22 02:30:39 2005
@@ -164,16 +164,22 @@
public void serializeWithCache(
org.apache.axis2.om.impl.OMOutputImpl omOutput)
throws XMLStreamException {
+ writeOutput(omOutput);
+
+ }
+
+ /**
+ * Writes the relevant output
+ * @param omOutput
+ * @throws XMLStreamException
+ */
+ private void writeOutput(OMOutputImpl omOutput) throws XMLStreamException {
XMLStreamWriter writer = omOutput.getXmlStreamWriter();
int type = getType();
if (type == TEXT_NODE) {
- writer.writeCharacters(this.value);
+ writer.writeCharacters(this.getText());
} else if (type == CDATA_SECTION_NODE) {
- writer.writeCData(this.value);
- }
- OMNode nextSibling = this.getNextSibling();
- if (nextSibling != null) {
- nextSibling.serializeWithCache(omOutput);
+ writer.writeCData(this.getText());
}
}
@@ -197,7 +203,7 @@
do {
data = new byte[3];
IOUtils.readFully(inStream, data, 0, 3);
- text.append(Base64.encode(data));
+ text.append(Base64.encode(data));
}while (inStream.available()>0);
return text.toString();
} catch (Exception e) {
@@ -284,8 +290,9 @@
public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput)
throws XMLStreamException {
+
if (!this.isBinary) {
- serializeWithCache(omOutput);
+ writeOutput(omOutput);
} else {
if (omOutput.isOptimized()) {
if (contentID == null) {
@@ -300,19 +307,7 @@
} else {
omOutput.getXmlStreamWriter().writeCharacters(this.getText());
}
- // TODO do we need these
- OMNode nextSibling = this.getNextSibling();
- if (nextSibling != null) {
- // serilize next sibling
- nextSibling.serialize(omOutput);
- } else {
- // TODO : See whether following part is really needed
- if (parent != null && !parent.isComplete()) {
- // do the special serialization
- // Only the push serializer is left now
- builder.next();
- }
- }
+
}
}