Author: richard.opalka(a)jboss.com
Date: 2007-09-12 12:10:57 -0400 (Wed, 12 Sep 2007)
New Revision: 4556
Modified:
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
Log:
small optimization
Modified: common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
---
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-09-12
13:20:47 UTC (rev 4555)
+++
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-09-12
16:10:57 UTC (rev 4556)
@@ -28,7 +28,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -70,10 +70,10 @@
private static Logger log = Logger.getLogger(DOMUtils.class);
// All elements created by the same thread are created by the same builder and belong
to the same doc
- private static ThreadLocal documentThreadLocal = new ThreadLocal();
- private static ThreadLocal builderThreadLocal = new ThreadLocal()
+ private static ThreadLocal<Document> documentThreadLocal = new
ThreadLocal<Document>();
+ private static ThreadLocal<DocumentBuilder> builderThreadLocal = new
ThreadLocal<DocumentBuilder>()
{
- protected Object initialValue()
+ protected DocumentBuilder initialValue()
{
try
{
@@ -119,12 +119,11 @@
{
}
- /** Initialise the the DocumentBuilder
+ /** Initialize the DocumentBuilder
*/
public static DocumentBuilder getDocumentBuilder()
{
- DocumentBuilder builder = (DocumentBuilder)builderThreadLocal.get();
- return builder;
+ return builderThreadLocal.get();
}
/** Parse the given XML string and return the root Element
@@ -148,13 +147,11 @@
{
try
{
- Document doc = getDocumentBuilder().parse(xmlStream);
- Element root = doc.getDocumentElement();
- return root;
+ return getDocumentBuilder().parse(xmlStream).getDocumentElement();
}
- catch (SAXException e)
+ catch (SAXException se)
{
- throw new IOException(e.toString());
+ throw new IOException(se.toString());
}
}
@@ -164,13 +161,11 @@
{
try
{
- Document doc = getDocumentBuilder().parse(source);
- Element root = doc.getDocumentElement();
- return root;
+ return getDocumentBuilder().parse(source).getDocumentElement();
}
- catch (SAXException e)
+ catch (SAXException se)
{
- throw new IOException(e.toString());
+ throw new IOException(se.toString());
}
}
@@ -436,15 +431,15 @@
/** Gets child elements
*/
- public static Iterator getChildElements(Node node)
+ public static Iterator<Element> getChildElements(Node node)
{
- ArrayList list = new ArrayList();
+ List<Element> list = new LinkedList<Element>();
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Node child = nlist.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE)
- list.add(child);
+ list.add((Element)child);
}
return list.iterator();
}
@@ -526,7 +521,7 @@
private static List<Element> getChildElementsAsListIntern(Node node, QName
nodeName)
{
- List<Element> list = new ArrayList<Element>();
+ List<Element> list = new LinkedList<Element>();
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
@@ -574,7 +569,7 @@
/** Get the owner document that is associated with the current thread */
public static Document getOwnerDocument()
{
- Document doc = (Document)documentThreadLocal.get();
+ Document doc = documentThreadLocal.get();
if (doc == null)
{
doc = getDocumentBuilder().newDocument();
Show replies by date