source: tmcsimulator/branches/ATMSDriver/src/atmsdriver/network/model/FEPLine.java @ 76

Revision 76, 3.7 KB checked in by jtorres, 9 years ago (diff)

In network.java, LoopDetectorStation?.java and LoopDetector?.java, added network writing capabilities. The network can now be written to a specified xml file to be read by the cpp ATMS RPC program. The network reader is finished and reads in all static network data correctly

Line 
1package atmsdriver.network.model;
2
3import java.util.List;
4import org.w3c.dom.Document;
5import org.w3c.dom.Element;
6
7
8
9/** An FEPLine is a simulated line of communication from the FEP to
10 *  LoopDetectorStations in the traffic network.
11 *
12 *  An FEPLine contains static meta data and a list of LoopDetectorStations.
13 *  A single FEPLine contains multiple LoopDetectorStations.
14 *
15 * @author John A. Torres
16 * @version 09/10/2017
17 */ 
18public class FEPLine {
19    /* Static FEPLine meta data */
20    final private int lineNum;
21    final private List<LoopDetectorStation> stations;
22    final private int count;
23    // NOT SURE IF NEXT IS FINAL
24    final private int schedule;
25    final private int lineInfo;
26    final private long systemKey;
27    final private long globalSeq;
28    final private long scheduleSeq;
29   
30    public FEPLine(int lineNum, List<LoopDetectorStation> stations, int count,
31            int schedule, int lineInfo, long systemKey, long globalSeq,
32            long scheduleSeq)
33    {
34        this.lineNum = lineNum;
35        this.stations = stations;
36        this.count = count;
37        this.schedule = schedule;
38        this.lineInfo = lineInfo;
39        this.systemKey = systemKey;
40        this.globalSeq = globalSeq;
41        this.scheduleSeq = scheduleSeq;
42    }
43   
44    public void toXML(Element currElem)
45    {
46        Document theDoc = currElem.getOwnerDocument();
47       
48        Element lineElement = theDoc.createElement(XML_TAGS.LINE.tag);
49        currElem.appendChild(lineElement);
50       
51        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag);
52        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum)));
53        lineElement.appendChild(lineNumElement);
54       
55        Element countElement = theDoc.createElement(XML_TAGS.COUNT.tag);
56        countElement.appendChild(theDoc.createTextNode(String.valueOf(this.count)));
57        lineElement.appendChild(countElement);
58       
59        Element scheduleElement = theDoc.createElement(XML_TAGS.SCHEDULE.tag);
60        scheduleElement.appendChild(theDoc.createTextNode(String.valueOf(this.schedule)));
61        lineElement.appendChild(scheduleElement);
62       
63        Element lineInfoElement = theDoc.createElement(XML_TAGS.LINE_INFO.tag);
64        lineInfoElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineInfo)));
65        lineElement.appendChild(lineInfoElement);
66       
67        Element systemKeyElement = theDoc.createElement(XML_TAGS.SYSTEM_KEY.tag);
68        systemKeyElement.appendChild(theDoc.createTextNode(String.valueOf(this.systemKey)));
69        lineElement.appendChild(systemKeyElement);
70       
71        Element globalSeqElement = theDoc.createElement(XML_TAGS.GLOBAL_SEQ.tag);
72        globalSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.globalSeq)));
73        lineElement.appendChild(globalSeqElement);
74       
75        Element scheduleSeqElement = theDoc.createElement(XML_TAGS.SCHEDULE_SEQ.tag);
76        scheduleSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.scheduleSeq)));
77        lineElement.appendChild(scheduleSeqElement);
78       
79        Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag);
80        lineElement.appendChild(stationsElement);
81        for(LoopDetectorStation station : stations)
82        {
83            station.toXML(stationsElement);
84        }
85    }
86   
87    private static enum XML_TAGS
88    {
89        LINE("Line"),
90        LINE_NUM("Line_Num"),
91        STATIONS("Stations"),
92        COUNT("Count"),
93        SCHEDULE("Schedule"),
94        LINE_INFO("Line_Info"),
95        SYSTEM_KEY("System_Key"),
96        GLOBAL_SEQ("Global_Seq"),
97        SCHEDULE_SEQ("Schedule_Seq");
98       
99        String tag;
100       
101        private XML_TAGS(String n)
102        {
103            tag = n;
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.