Index: trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java	(revision 4518)
+++ trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java	(revision 4520)
@@ -11,13 +11,10 @@
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Map;
-import java.util.NoSuchElementException;
 import java.util.Stack;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
@@ -95,5 +92,5 @@
         private Iterator<Object> iterator;
         /**
-         * @param klass This has to be specified since generics are ereased from
+         * @param klass This has to be specified since generics are erased from
          * class files so the JVM cannot deduce T itself.
          */
@@ -135,5 +132,5 @@
     private class Parser extends DefaultHandler {
         Stack<Object> current = new Stack<Object>();
-        String characters = "";
+        StringBuilder characters = new StringBuilder(64);
 
         private Locator locator;
@@ -162,10 +159,6 @@
                     report();
                 }
-                if (mapping.get(qname).both)
-                {
-                    try {
-                        queue.put(current.peek());
-                    } catch (InterruptedException e) {
-                    }
+                if (mapping.get(qname).both) {
+                    queue.add(current.peek());
                 }
             }
@@ -175,19 +168,15 @@
                 report();
             } else if (characters != null && !current.isEmpty()) {
-                setValue(qname, characters.trim());
-                characters = "";
+                setValue(qname, characters.toString().trim());
+                characters  = new StringBuilder(64);
             }
         }
         @Override public void characters(char[] ch, int start, int length) {
-            String s = new String(ch, start, length);
-            characters += s;
+            characters.append(ch, start, length);
         }
 
         private void report() {
-            try {
-                queue.put(current.pop());
-            } catch (InterruptedException e) {
-            }
-            characters = "";
+            queue.add(current.pop());
+            characters  = new StringBuilder(64);
         }
 
@@ -249,9 +238,9 @@
 
         private boolean parseBoolean(String s) {
-            return s != null &&
-            !s.equals("0") &&
-            !s.startsWith("off") &&
-            !s.startsWith("false") &&
-            !s.startsWith("no");
+            return s != null
+                    && !s.equals("0")
+                    && !s.startsWith("off")
+                    && !s.startsWith("false")
+                    && !s.startsWith("no");
         }
 
@@ -285,17 +274,6 @@
      * The queue of already parsed items from the parsing thread.
      */
-    private BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(10);
-
-    /**
-     * This stores one item retrieved from the queue to give hasNext a chance.
-     * So this is also the object that will be returned on the next call to next().
-     */
-    private Object lookAhead = null;
-
-    /**
-     * This object represent the end of the stream (null is not allowed as
-     * member in class Queue).
-     */
-    private Object EOS = new Object();
+    private LinkedList<Object> queue = new LinkedList<Object>();
+    private Iterator<Object> queueIterator = null;
 
     public XmlObjectParser() {
@@ -308,25 +286,15 @@
 
     private Iterable<Object> start(final Reader in, final ContentHandler contentHandler) {
-        new Thread("XML Reader"){
-            @Override public void run() {
-                try {
-                    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-                    parserFactory.setNamespaceAware(true);
-                    SAXParser parser = parserFactory.newSAXParser();
-                    XMLReader reader = parser.getXMLReader();
-                    reader.setContentHandler(contentHandler);
-                    reader.parse(new InputSource(in));
-                } catch (Exception e) {
-                    try {
-                        queue.put(e);
-                    } catch (InterruptedException e1) {
-                    }
-                }
-                try {
-                    queue.put(EOS);
-                } catch (InterruptedException e) {
-                }
-            }
-        }.start();
+        try {
+            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+            parserFactory.setNamespaceAware(true);
+            SAXParser saxParser = parserFactory.newSAXParser();
+            XMLReader reader = saxParser.getXMLReader();
+            reader.setContentHandler(contentHandler);
+            reader.parse(new InputSource(in));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        queueIterator = queue.iterator();
         return this;
     }
@@ -364,60 +332,15 @@
     }
 
-    /**
-     * @return The next object from the xml stream or <code>null</code>,
-     * if no more objects.
-     */
-    public Object next() throws SAXException {
-        fillLookAhead();
-        if (lookAhead == EOS)
-            throw new NoSuchElementException();
-        Object o = lookAhead;
-        lookAhead = null;
-        return o;
-    }
-
-    private void fillLookAhead() throws SAXException {
-        if (lookAhead != null)
-            return;
-        try {
-            lookAhead = queue.take();
-            if (lookAhead instanceof SAXException)
-                throw (SAXException)lookAhead;
-            else if (lookAhead instanceof RuntimeException)
-                throw (RuntimeException)lookAhead;
-            else if (lookAhead instanceof Exception)
-                throw new SAXException((Exception)lookAhead);
-        } catch (InterruptedException e) {
-            throw new RuntimeException("XmlObjectParser must not be interrupted.", e);
-        }
-    }
-
-    public boolean hasNext() throws SAXException {
-        fillLookAhead();
-        return lookAhead != EOS;
-    }
-
+    public Object next() {
+        return queueIterator.next();
+    }
+
+    public boolean hasNext() {
+        return queueIterator.hasNext();
+    }
+
+    @Override
     public Iterator<Object> iterator() {
-        return new Iterator<Object>(){
-            public boolean hasNext() {
-                try {
-                    return XmlObjectParser.this.hasNext();
-                } catch (SAXException e) {
-                    e.printStackTrace();
-                    throw new RuntimeException(e);
-                }
-            }
-            public Object next() {
-                try {
-                    return XmlObjectParser.this.next();
-                } catch (SAXException e) {
-                    e.printStackTrace();
-                    throw new RuntimeException(e);
-                }
-            }
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-        };
+        return queue.iterator();
     }
 }
