Author: alessio.soldano(a)jboss.com
Date: 2009-09-16 13:21:07 -0400 (Wed, 16 Sep 2009)
New Revision: 10708
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/NodeImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
Log:
[JBWS-2763] Prevent multiple computations of stop-value in "for" loops, remove
useless traces, misc optimizations
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/NodeImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/NodeImpl.java 2009-09-16
17:20:16 UTC (rev 10707)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/NodeImpl.java 2009-09-16
17:21:07 UTC (rev 10708)
@@ -30,7 +30,6 @@
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
-import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.wsf.common.DOMUtils;
import org.jboss.wsf.common.DOMWriter;
@@ -58,9 +57,6 @@
*/
public class NodeImpl implements javax.xml.soap.Node
{
- // provide logging
- private static Logger log = Logger.getLogger(NodeImpl.class);
-
// The parent of this Node
protected SOAPElementImpl soapParent;
// This org.w3c.dom.Node
@@ -318,7 +314,8 @@
if (soapParent != null)
{
List children = ((NodeImpl)soapParent).soapChildren;
- for (int i = 0; i < children.size(); i++)
+ int len = children.size();
+ for (int i = 0; i < len; i++)
{
NodeImpl node = (NodeImpl)children.get(i);
if (node == this && i > 0)
@@ -343,10 +340,11 @@
if (soapParent != null)
{
List children = ((NodeImpl)soapParent).soapChildren;
- for (int i = 0; i < children.size(); i++)
+ int len = children.size();
+ for (int i = 0; i < len; i++)
{
NodeImpl node = (NodeImpl)children.get(i);
- if (node == this && (i + 1) < children.size())
+ if (node == this && (i + 1) < len)
{
sibling = (NodeImpl)children.get(i + 1);
break;
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2009-09-16
17:20:16 UTC (rev 10707)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2009-09-16
17:21:07 UTC (rev 10708)
@@ -36,7 +36,6 @@
import javax.xml.soap.SOAPException;
import javax.xml.soap.Text;
-import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.wsf.common.DOMUtils;
@@ -60,9 +59,6 @@
*/
public class SOAPElementImpl extends NodeImpl implements SOAPElement, SAAJVisitable
{
- // provide logging
- private static Logger log = Logger.getLogger(SOAPElementImpl.class);
-
// The org.w3c.dom.Element
private Element element;
// The element name
@@ -73,7 +69,6 @@
{
super(DOMUtils.createElement(localPart, null, null));
this.element = (Element)domNode;
- log.trace("new SOAPElementImpl: " + getElementName());
}
/** Called by SOAPFactory */
@@ -81,7 +76,6 @@
{
super(DOMUtils.createElement(localPart, prefix, nsURI));
this.element = (Element)domNode;
- log.trace("new SOAPElementImpl: " + getElementName());
}
/** Called by SOAPFactory */
@@ -102,7 +96,6 @@
{
super(element);
this.element = (Element)domNode;
- log.trace("new SOAPElementImpl: " + getElementName());
}
/** Get the SOAPEnvelope for this SOAPElement */
@@ -267,7 +260,6 @@
*/
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
{
- log.trace("addChildElement: " + getElementName() + " -> " +
child.getElementName());
SOAPElementImpl soapElement = (SOAPElementImpl)child;
soapElement = (SOAPElementImpl)appendChild(soapElement);
return soapElement.completeNamespaceDeclaration();
@@ -292,7 +284,6 @@
if (prefix != null && prefix.length() > 0)
qualifiedName += ":" + prefix;
- log.trace("addNamespaceDeclaration: " + qualifiedName +
"='" + nsURI + "'");
element.setAttributeNS("http://www.w3.org/2000/xmlns/", qualifiedName,
nsURI);
return this;
}
@@ -321,7 +312,6 @@
*/
public SOAPElement addTextNode(String value) throws SOAPException
{
- log.trace("addTextNode: " + value);
org.w3c.dom.Node domNode;
if (value.startsWith("<!--") &&
value.endsWith("-->"))
{
@@ -349,7 +339,8 @@
{
ArrayList list = new ArrayList();
NamedNodeMap nnm = getAttributes();
- for (int i = 0; i < nnm.getLength(); i++)
+ int len = nnm.getLength();
+ for (int i = 0; i < len; i++)
{
org.w3c.dom.Node node = (org.w3c.dom.Node)nnm.item(i);
String local = node.getLocalName();
@@ -376,7 +367,8 @@
{
ArrayList list = new ArrayList();
NamedNodeMap nnm = getAttributes();
- for (int i = 0; i < nnm.getLength(); i++)
+ int len = nnm.getLength();
+ for (int i = 0; i < len; i++)
{
org.w3c.dom.Node node = (org.w3c.dom.Node)nnm.item(i);
String local = node.getLocalName();
@@ -462,7 +454,8 @@
{
List list = new ArrayList();
NodeList nodeList = getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++)
+ int len = nodeList.getLength();
+ for (int i = 0; i < len; i++)
{
org.w3c.dom.Node node = nodeList.item(i);
if (node instanceof SOAPElement)
@@ -476,6 +469,27 @@
}
return list.iterator();
}
+
+ protected SOAPElement getFirstChildElementByLocalName(String localName)
+ {
+ if (localName == null)
+ throw new IllegalArgumentException("localName cannot be null");
+ NodeList nodeList = getChildNodes();
+ int len = nodeList.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ org.w3c.dom.Node node = nodeList.item(i);
+ if (localName.equals(node.getLocalName()))
+ {
+ if (node instanceof SOAPElement)
+ {
+ return (SOAPElement)node;
+ }
+ }
+ }
+ return null;
+ }
+
/**
* Returns an Iterator over all the immediate child Nodes of this element with the
specified name.
@@ -554,7 +568,8 @@
{
ArrayList list = new ArrayList();
NamedNodeMap attrMap = element.getAttributes();
- for (int i = 0; i < attrMap.getLength(); i++)
+ int len = attrMap.getLength();
+ for (int i = 0; i < len; i++)
{
Attr attr = (Attr)attrMap.item(i);
String attrName = attr.getNodeName();
@@ -629,7 +644,6 @@
*/
public void removeContents()
{
- log.trace("removeContents");
Iterator it = getChildElements();
while (it.hasNext())
{
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java 2009-09-16
17:20:16 UTC (rev 10707)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java 2009-09-16
17:21:07 UTC (rev 10708)
@@ -153,26 +153,12 @@
public SOAPBody getBody() throws SOAPException
{
- Iterator it = getChildElements();
- while (it.hasNext())
- {
- Node node = (Node)it.next();
- if ("Body".equals(node.getLocalName()))
- return (SOAPBody)node;
- }
- return null;
+ return (SOAPBody)getFirstChildElementByLocalName("Body");
}
public SOAPHeader getHeader() throws SOAPException
{
- Iterator it = getChildElements();
- while (it.hasNext())
- {
- Node node = (Node)it.next();
- if ("Header".equals(node.getLocalName()))
- return (SOAPHeader)node;
- }
- return null;
+ return (SOAPHeader)getFirstChildElementByLocalName("Header");
}
/**