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 di...@apache.org on 2004/11/07 12:26:37 UTC
cvs commit: ws-axis/java/test/saaj TestText.java PackageTests.java
dims 2004/11/07 03:26:37
Modified: java/src/org/apache/axis/message MessageElement.java
NodeImpl.java SOAPEnvelope.java
java/test/saaj PackageTests.java
Added: java/test/saaj TestText.java
Log:
Use the parent SOAPEnvelope's getOwnerDocument() before trying to use the context and before creating a brand new one. This reduces the # of instances where we have to create new documents and speeds things up.
Notes:
- I need Jarek's cooperation to figure out where he is seeing slowdown due to repeated newDocument() calls.
- With this change, Bottom line is if the SOAPPart is set for the SOAPEnvelope then we don't create newDocument's every time.
Revision Changes Path
1.187 +17 -11 ws-axis/java/src/org/apache/axis/message/MessageElement.java
Index: MessageElement.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/MessageElement.java,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -r1.186 -r1.187
--- MessageElement.java 4 Nov 2004 13:23:35 -0000 1.186
+++ MessageElement.java 7 Nov 2004 11:26:37 -0000 1.187
@@ -51,6 +51,7 @@
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
+import javax.xml.parsers.ParserConfigurationException;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
@@ -418,7 +419,7 @@
if(child != null) { // why child can be null?
NodeImpl clonedChild = (NodeImpl)child.cloneNode(deep); // deep == true
clonedChild.setParent(clonedSelf);
- clonedChild.setOwnerDocument(soapPart);
+ clonedChild.setOwnerDocument(getOwnerDocument());
clonedSelf.childDeepCloned( child, clonedChild );
}
@@ -1381,17 +1382,9 @@
* @see javax.xml.soap.SOAPElement#addTextNode(String)
*/
public SOAPElement addTextNode(String s) throws SOAPException {
- Text text = null;
- if (context != null && context.getEnvelope() != null &&
- context.getEnvelope().getOwnerDocument() != null) {
- Document doc = context.getEnvelope().getOwnerDocument();
- text = doc.createTextNode(s);
- }
- if (text == null) {
- text = new org.apache.axis.message.Text(s);
- }
try {
- appendChild(text);
+ Text text = getOwnerDocument().createTextNode(s);
+ appendChild(text);
return this;
} catch (ClassCastException e) {
throw new SOAPException(e);
@@ -2091,5 +2084,18 @@
}
}
super.setValue(value);
+ }
+
+ public Document getOwnerDocument() {
+ Document doc = super.getOwnerDocument();
+ if (doc == null) {
+ if (context != null && context.getEnvelope() != null &&
+ context.getEnvelope().getOwnerDocument() != null) {
+ doc = context.getEnvelope().getOwnerDocument();
+ } else {
+ doc = new SOAPDocumentImpl(null);
+ }
+ }
+ return doc;
}
}
1.7 +14 -5 ws-axis/java/src/org/apache/axis/message/NodeImpl.java
Index: NodeImpl.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/NodeImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NodeImpl.java 14 Oct 2004 23:37:03 -0000 1.6
+++ NodeImpl.java 7 Nov 2004 11:26:37 -0000 1.7
@@ -53,7 +53,7 @@
protected String namespaceURI;
protected transient Attributes attributes = NullAttributes.singleton;
- protected org.apache.axis.SOAPPart soapPart = null;
+ protected Document document = null;
protected NodeImpl parent = null;
protected ArrayList children = null;
@@ -281,10 +281,10 @@
/**
* Set the owner document
*
- * @param sp
+ * @param doc
*/
- public void setOwnerDocument(org.apache.axis.SOAPPart sp) {
- soapPart = sp;
+ public void setOwnerDocument(Document doc) {
+ document = doc;
}
/**
@@ -295,7 +295,16 @@
* <code>null</code>.
*/
public Document getOwnerDocument() {
- return soapPart;
+ if(document == null) {
+ NodeImpl node = getParent();
+ while(node != null) {
+ if(node.getOwnerDocument() != null) {
+ return node.getOwnerDocument();
+ }
+ node = node.getParent();
+ }
+ }
+ return document;
}
/**
1.103 +2 -2 ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java
Index: SOAPEnvelope.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- SOAPEnvelope.java 14 Sep 2004 14:52:38 -0000 1.102
+++ SOAPEnvelope.java 7 Nov 2004 11:26:37 -0000 1.103
@@ -539,7 +539,7 @@
if (body == null) {
body = new SOAPBody(this, soapConstants);
_isDirty = true;
- body.setOwnerDocument((org.apache.axis.SOAPPart) getOwnerDocument());
+ body.setOwnerDocument(getOwnerDocument());
return body;
} else {
throw new SOAPException(Messages.getMessage("bodyPresent"));
@@ -554,7 +554,7 @@
public javax.xml.soap.SOAPHeader addHeader() throws SOAPException {
if (header == null) {
header = new SOAPHeader(this, soapConstants);
- header.setOwnerDocument((org.apache.axis.SOAPPart) getOwnerDocument());
+ header.setOwnerDocument(getOwnerDocument());
return header;
} else {
throw new SOAPException(Messages.getMessage("headerPresent"));
1.12 +1 -0 ws-axis/java/test/saaj/PackageTests.java
Index: PackageTests.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/saaj/PackageTests.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- PackageTests.java 10 Aug 2004 02:36:45 -0000 1.11
+++ PackageTests.java 7 Nov 2004 11:26:37 -0000 1.12
@@ -26,6 +26,7 @@
suite.addTestSuite(test.saaj.TestSOAPFaults.class);
suite.addTestSuite(test.saaj.TestDOM.class);
suite.addTestSuite(test.saaj.TestSOAPElement.class);
+ suite.addTestSuite(test.saaj.TestText.class);
return suite;
}
}
1.1 ws-axis/java/test/saaj/TestText.java
Index: TestText.java
===================================================================
package test.saaj;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPBodyElement;
public class TestText extends junit.framework.TestCase {
public TestText(String name) {
super(name);
}
// Test SAAJ addTextNode performance
public void testAddTextNode() throws Exception {
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
// Create the base element
Name bodyName = soapFactory.createName("VBGenReceiver", "xsi",
"http://www.w3.org/2001/XMLSchema-instance");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
// Create the MetaData Tag
Name name = soapFactory.createName("MetaData");
SOAPElement metaData = bodyElement.addChildElement(name);
//Create the SKey Tag
name = soapFactory.createName("SKey");
SOAPElement sKey = metaData.addChildElement(name);
sKey.addTextNode("SKEY001");
//Create Object Tag
name = soapFactory.createName("Object");
SOAPElement object = bodyElement.addChildElement(name);
//Create Book ID Tag
name = soapFactory.createName("BookID");
SOAPElement bookID = object.addChildElement(name);
bookID.addTextNode("BookID002");
//Create OrderID tag
name = soapFactory.createName("OrderID");
SOAPElement orderID = object.addChildElement(name);
orderID.addTextNode("OrderID003");
//create PurchaseID tage
name = soapFactory.createName("PurchaseID");
SOAPElement purchaseID = object.addChildElement(name);
purchaseID.addTextNode("PurchaseID005");
//create LanguageID Tag
name = soapFactory.createName("LanguageID");
SOAPElement languageID = object.addChildElement(name);
languageID.addTextNode("LanguageID004");
//create LanguageID Tag
name = soapFactory.createName("LanguageName");
SOAPElement languageName = object.addChildElement(name);
languageName.addTextNode("LanguageName006");
//create LanguageID Tag
name = soapFactory.createName("Title");
SOAPElement title = object.addChildElement(name);
title.addTextNode("Title007");
//create LanguageID Tag
name = soapFactory.createName("Author");
SOAPElement author = object.addChildElement(name);
author.addTextNode("Author008");
//create LanguageID Tag
name = soapFactory.createName("Format");
SOAPElement format = bodyElement.addChildElement(name);
//create LanguageID Tag
name = soapFactory.createName("Type");
SOAPElement formatType = format.addChildElement(name);
formatType.addTextNode("Type009");
//create LanguageID Tag
name = soapFactory.createName("Delivery");
SOAPElement delivery = bodyElement.addChildElement(name);
//create LanguageID Tag
name = soapFactory.createName("Name");
SOAPElement delName = delivery.addChildElement(name);
delName.addTextNode("Name010");
//create LanguageID Tag
name = soapFactory.createName("Address1");
SOAPElement address1 = delivery.addChildElement(name);
address1.addTextNode("Address1011");
//create LanguageID Tag
name = soapFactory.createName("Address2");
SOAPElement address2 = delivery.addChildElement(name);
address2.addTextNode("Address2012");
//create LanguageID Tag
name = soapFactory.createName("City");
SOAPElement city = delivery.addChildElement(name);
city.addTextNode("City013");
//create LanguageID Tag
name = soapFactory.createName("State");
SOAPElement state = delivery.addChildElement(name);
state.addTextNode("State014");
//create LanguageID Tag
name = soapFactory.createName("PostalCode");
SOAPElement postalCode = delivery.addChildElement(name);
postalCode.addTextNode("PostalCode015");
System.out.println("The message is lll:\n");
message.writeTo(System.out);
}
public static void main(String[] args) throws Exception {
TestText tester = new TestText("TestEnvelope");
tester.testAddTextNode();
}
}