Changeset 4726 in josm for trunk


Ignore:
Timestamp:
2011-12-27T18:25:55+01:00 (13 years ago)
Author:
jttt
Message:

Fix exception handling (xml file not valid against xsd can't cause RuntimeException, see #6795), remove unused inner class

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r4724 r4726  
    306306     * All data sources of this DataSet.
    307307     */
    308     public Collection<DataSource> dataSources = new LinkedList<DataSource>();
     308    public final Collection<DataSource> dataSources = new LinkedList<DataSource>();
    309309
    310310    /**
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r4520 r4726  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.io.Reader;
    7 import java.io.IOException;
    88import java.lang.reflect.Field;
    99import java.lang.reflect.Method;
     
    1515import java.util.Stack;
    1616
     17import javax.xml.parsers.ParserConfigurationException;
    1718import javax.xml.parsers.SAXParser;
    1819import javax.xml.parsers.SAXParserFactory;
     
    2324
    2425import org.openstreetmap.josm.io.MirroredInputStream;
    25 
    2626import org.xml.sax.Attributes;
    2727import org.xml.sax.ContentHandler;
     
    8989
    9090    public static final String lang = LanguageInfo.getLanguageCodeXML();
    91     public static class Uniform<T> implements Iterable<T>{
    92         private Iterator<Object> iterator;
    93         /**
    94          * @param klass This has to be specified since generics are erased from
    95          * class files so the JVM cannot deduce T itself.
    96          */
    97         public Uniform(Reader input, String tagname, Class<T> klass) {
    98             XmlObjectParser parser = new XmlObjectParser();
    99             parser.map(tagname, klass);
    100             parser.start(input);
    101             iterator = parser.iterator();
    102         }
    103         public Iterator<T> iterator() {
    104             return new Iterator<T>(){
    105                 public boolean hasNext() {return iterator.hasNext();}
    106                 @SuppressWarnings("unchecked") public T next() {return (T)iterator.next();}
    107                 public void remove() {iterator.remove();}
    108             };
    109         }
    110     }
    11191
    11292    private static class AddNamespaceFilter extends XMLFilterImpl {
     
    204184                    {
    205185                        String locfieldName = "locale_" +
    206                         fieldName.substring(lang.length());
     186                                fieldName.substring(lang.length());
    207187                        try {
    208188                            f = c.getClass().getField(locfieldName);
     
    285265    }
    286266
    287     private Iterable<Object> start(final Reader in, final ContentHandler contentHandler) {
     267    private Iterable<Object> start(final Reader in, final ContentHandler contentHandler) throws SAXException, IOException {
    288268        try {
    289269            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     
    293273            reader.setContentHandler(contentHandler);
    294274            reader.parse(new InputSource(in));
    295         } catch (Exception e) {
     275            queueIterator = queue.iterator();
     276            return this;
     277        } catch (ParserConfigurationException e) {
     278            // This should never happen ;-)
    296279            throw new RuntimeException(e);
    297280        }
    298         queueIterator = queue.iterator();
    299         return this;
    300     }
    301 
    302     public Iterable<Object> start(final Reader in) {
    303         return start(in, parser);
     281    }
     282
     283    public Iterable<Object> start(final Reader in) throws SAXException {
     284        try {
     285            return start(in, parser);
     286        } catch (IOException e) {
     287            throw new SAXException(e);
     288        }
    304289    }
    305290
Note: See TracChangeset for help on using the changeset viewer.