source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/structures/CadData.java @ 43

Revision 43, 6.0 KB checked in by bmcguffin, 9 years ago (diff)

Filled out toXML method of CadData? object.

Line 
1package scriptbuilder.structures;
2
3import java.util.ArrayList;
4
5/**
6 * Aggregation of several information fields relevant to each timeslice.
7 *
8 * @author Bryan McGuffin
9 */
10public class CadData implements I_XML_Writable
11{
12
13    public CadData()
14    {
15        locInfo = new ArrayList<Location_Info>();
16    }
17
18    public TimeSlice tSlice;
19
20    public String Header_Type = "";
21
22    public String Header_Beat = "";
23
24    public String Header_TruncLoc = "";
25
26    public String Header_FullLoc = "";
27
28    public String Master_Inc_Num = "";
29
30    public String P = "";
31
32    public String Info_Type = "";
33
34    public String Info_Type_Code = "";
35
36    public String Agy = "";
37
38    public String General_Title = "";
39
40    public String General_Text = "";
41
42    public String Location_Beat = "";
43
44    public String Location_Address = "";
45
46    public String Location_Loc = "";
47
48    public String Location_City = "";
49
50    public String Location_Area = "";
51
52    public String Location_Fire = "";
53
54    public String Location_Law = "";
55
56    public String Location_Ems = "";
57
58    public ArrayList<Location_Info> locInfo;
59
60    @Override
61    public String toXML()
62    {
63        String output = "";
64
65        if (!Master_Inc_Num.equals(""))
66        {
67            output += openTag(ELEMENT.MASTER_INC_NUM.tag);
68            output += Master_Inc_Num;
69            output += closeTag(ELEMENT.MASTER_INC_NUM.tag);
70        }
71
72        if (!P.equals(""))
73        {
74            output += openTag(ELEMENT.P.tag);
75            output += P;
76            output += closeTag(ELEMENT.P.tag);
77        }
78
79        if (hasAdditionalInfo())
80        {
81            output += openTag(ELEMENT.ADDITIONAL_INFO.tag);
82            output += openTag(ELEMENT.TYPE_CODE.tag);
83            output += Info_Type_Code;
84            output += closeTag(ELEMENT.TYPE_CODE.tag);
85            output += openTag(ELEMENT.TYPE.tag);
86            output += Info_Type;
87            output += closeTag(ELEMENT.TYPE.tag);
88            output += closeTag(ELEMENT.ADDITIONAL_INFO.tag);
89        }
90
91        if (hasLocation())
92        {
93            output += openTag(ELEMENT.LOCATION.tag);
94            if (!Location_Beat.equals(""))
95            {
96                output += openTag(ELEMENT.BEAT.tag);
97                output += Location_Beat;
98                output += closeTag(ELEMENT.BEAT.tag);
99            }
100
101            if (!Location_Address.equals(""))
102            {
103                output += openTag(ELEMENT.ADDRESS.tag);
104                output += Location_Address;
105                output += closeTag(ELEMENT.ADDRESS.tag);
106            }
107
108            if (!Location_Loc.equals(""))
109            {
110                output += openTag(ELEMENT.LOC.tag);
111                output += Location_Loc;
112                output += closeTag(ELEMENT.LOC.tag);
113            }
114
115            if (!Location_City.equals(""))
116            {
117                output += openTag(ELEMENT.CITY.tag);
118                output += Location_City;
119                output += closeTag(ELEMENT.CITY.tag);
120            }
121
122            if (!Location_Area.equals(""))
123            {
124                output += openTag(ELEMENT.AREA.tag);
125                output += Location_Area;
126                output += closeTag(ELEMENT.AREA.tag);
127            }
128
129            if (!Location_Fire.equals(""))
130            {
131                output += openTag(ELEMENT.FIRE.tag);
132                output += Location_Fire;
133                output += closeTag(ELEMENT.FIRE.tag);
134            }
135
136            if (!Location_Law.equals(""))
137            {
138                output += openTag(ELEMENT.LAW.tag);
139                output += Location_Law;
140                output += closeTag(ELEMENT.LAW.tag);
141            }
142
143            if (!Location_Ems.equals(""))
144            {
145                output += openTag(ELEMENT.EMS.tag);
146                output += Location_Ems;
147                output += closeTag(ELEMENT.EMS.tag);
148            }
149
150            output += closeTag(ELEMENT.LOCATION.tag);
151        }
152
153        if (!Agy.equals(""))
154        {
155            output += openTag(ELEMENT.GENERAL.tag);
156            output += openTag(ELEMENT.AGY.tag);
157            output += Agy;
158            output += closeTag(ELEMENT.AGY.tag);
159            output += closeTag(ELEMENT.GENERAL.tag);
160        }
161
162        if (hasHeaderInfo())
163        {
164            output += openTag(ELEMENT.HEADER_INFO.tag);
165
166            output += openTag(ELEMENT.Type.tag);
167            output += Header_Type;
168            output += closeTag(ELEMENT.Type.tag);
169
170            output += openTag(ELEMENT.Beat.tag);
171            output += Header_Beat;
172            output += closeTag(ELEMENT.Beat.tag);
173
174            output += openTag(ELEMENT.TruncLoc.tag);
175            output += Header_TruncLoc;
176            output += closeTag(ELEMENT.TruncLoc.tag);
177
178            output += openTag(ELEMENT.FullLoc.tag);
179            output += Header_FullLoc;
180            output += closeTag(ELEMENT.FullLoc.tag);
181
182            output += closeTag(ELEMENT.HEADER_INFO.tag);
183        }
184
185        if (locInfo.size() > 0)
186        {
187            for (Location_Info li : locInfo)
188            {
189                output += li.toXML();
190            }
191        }
192
193        return output;
194    }
195
196    @Override
197    public String openTag(String s)
198    {
199        return "<" + s + ">";
200    }
201
202    @Override
203    public String closeTag(String s)
204    {
205        return "</" + s + ">\n";
206    }
207
208    @Override
209    public String emptyTag(String s)
210    {
211        return "<" + s + "/>\n";
212    }
213
214    public boolean hasHeaderInfo()
215    {
216        return !Header_Type.equals("") || !Header_Beat.equals("")
217                || !Header_FullLoc.equals("") || !Header_TruncLoc.equals("");
218    }
219
220    public boolean hasLocation()
221    {
222        return !Location_Address.equals("") || !Location_Area.equals("")
223                || !Location_Beat.equals("") || !Location_City.equals("")
224                || !Location_Ems.equals("") || !Location_Fire.equals("")
225                || !Location_Law.equals("") || !Location_Loc.equals("");
226    }
227
228    public boolean hasGeneralInfo()
229    {
230        return !General_Text.equals("") || !General_Title.equals("");
231    }
232
233    public boolean hasAdditionalInfo()
234    {
235        return !Info_Type.equals("") || !Info_Type_Code.equals("");
236    }
237
238}
Note: See TracBrowser for help on using the repository browser.