Initial
[frank.git] / prod / net / jaekl / frank / octranspo / StopInfo.java
1 package net.jaekl.frank.octranspo;
2
3 import java.util.ArrayList;
4
5 import net.jaekl.qd.xml.ParseResult;
6 import net.jaekl.qd.xml.XmlParseException;
7
8 public class StopInfo extends ParseResult
9 {
10         // potential child tag names
11         public static String STOP_NO = "StopNo";
12         public static String DESCRIPTION = "StopDescription";   // Present in RouteSummary
13         public static String STOP_LABEL = "StopLabel";                  // What NextTrips calls StopDescription
14         public static String ERROR = "Error";
15         public static String ROUTES = "Routes";
16         public static String ROUTE = "Route";
17
18         // data returned inside our element
19         int m_stopNo;
20         String m_descr;
21         String m_error;
22         ArrayList<Route> m_routes;
23
24         // Constructor
25         public StopInfo(String rootTagName, String[] internal, Object[][] external) {
26                 super(rootTagName, internal, external);
27
28                 m_stopNo = 0;
29                 m_descr = "";
30                 m_error = "";
31                 m_routes = new ArrayList<Route>();
32         }
33
34         // -----------------------------
35         // Public methods to access data
36
37         public int getStopNo() { return m_stopNo; }
38         public String getDescr() { return m_descr; }
39         public String getError() { return m_error; }
40         public int getNumRoutes() { return m_routes.size(); }
41         public Route getRoute(int idx) { return m_routes.get(idx); }
42
43         // --------------------------
44         // ParseResult implementation
45
46         @Override
47         public void endContents(String uri, String localName, String qName, String chars) throws XmlParseException
48         {
49                 assert (null != localName);
50
51                 if (localName.equals(STOP_NO)) {
52                         m_stopNo = Integer.parseInt(chars);
53                 }
54                 else if (localName.equals(DESCRIPTION) || localName.equals(STOP_LABEL)) {
55                         m_descr = chars;
56                 }
57                 else if (localName.equals(ERROR)) {
58                         m_error = chars;
59                 }
60         }
61         
62         @Override
63         public void endExternal(String uri, String localName, String qName) throws XmlParseException
64         {
65                 if (localName.equals(ROUTE)) {
66                         ParseResult[] collected = collectParsedChildren(Route.class);
67                         for (ParseResult pr : collected) {
68                                 assert (pr instanceof Route);
69                                 m_routes.add((Route)pr);
70                         }
71                 }
72         }
73         
74         
75 }
76