--- android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlDepartureProvider.java 2010/07/10 11:01:07 980 +++ android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlDepartureProvider.java 2010/07/10 16:03:10 981 @@ -1,8 +1,6 @@ package dk.thoerup.traininfo.provider; import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -15,6 +13,7 @@ import android.util.Log; import dk.thoerup.traininfo.DepartureBean; +import dk.thoerup.traininfo.DepartureEntry; import dk.thoerup.traininfo.util.AndroidTimeoutCache; import dk.thoerup.traininfo.util.DownloadUtil; import dk.thoerup.traininfo.util.XmlUtil; @@ -24,12 +23,12 @@ final static int CACHE_TIMEOUT = 60*1000; - AndroidTimeoutCache> departureCache = new AndroidTimeoutCache>(CACHE_TIMEOUT); + AndroidTimeoutCache departureCache = new AndroidTimeoutCache(CACHE_TIMEOUT); - List departures; + DepartureBean departures; - DepartureBean tempDeparture; + DepartureEntry tempDeparture; StringBuilder builder = new StringBuilder(512); @Override @@ -57,7 +56,7 @@ private boolean lookupDeparturesWorker(int stationID, boolean arrival) { boolean success = false; - departures = new ArrayList(); + departures = new DepartureBean(); try { int iArrival = arrival ? 1 : 0; @@ -83,17 +82,17 @@ } @Override - public List getDepartures(int station,boolean arrival) { + public DepartureBean getDepartures(int station,boolean arrival) { String key = "" + station + ":" + arrival; - List list = departureCache.get(key); + DepartureBean bean = departureCache.get(key); - if (list == null) { - list = new ArrayList(); + if (bean == null) { + bean = new DepartureBean(); } - return list; + return bean; } // this can be called several times fore the same text-node if there are many chardata / lines @@ -108,7 +107,7 @@ public void startElement (String uri, String name, String qName, Attributes atts)throws SAXException { if (name.equalsIgnoreCase("train")) - tempDeparture = new DepartureBean(); + tempDeparture = new DepartureEntry(); builder.setLength(0); //reset StringBuilder } @@ -116,8 +115,8 @@ @Override public void endElement (String uri, String name, String qName) throws SAXException { - if (name.equals("train")) { - departures.add( tempDeparture ); + if (name.equals("train")) { + departures.entries.add( tempDeparture ); } else if (name.equals("time")) { tempDeparture.setTime(builder.toString().trim()); } else if (name.equals("updated")) { @@ -136,6 +135,8 @@ tempDeparture.setNote(builder.toString().trim()); } else if (name.equals("type")) { tempDeparture.setType(builder.toString().trim()); + } else if (name.equals("notification")) { + departures.notifications.add( builder.toString().trim() ); } } }