source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/structures/units/Unit.java @ 46

Revision 46, 4.1 KB checked in by bmcguffin, 9 years ago (diff)

Added file: XMLWriter, in package Scriptbuilder.structures. It holds static methods which ither classes that implement I_XML_Writable may find useful. Also restructured the toXML method of many classes to utilize this new class.

Line 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package scriptbuilder.structures.units;
7
8import scriptbuilder.structures.ELEMENT;
9import scriptbuilder.structures.I_XML_Writable;
10import scriptbuilder.structures.XMLWriter;
11
12/**
13 * Placeholder until I add some functionality. Represents an officer in a
14 * vehicle on the map. Has a name, ID, position, and status, as well as several
15 * other identifying factors.
16 *
17 * @author Bryan McGuffin
18 */
19public class Unit implements I_XML_Writable
20{
21
22    public String UnitNum;
23
24    public String ID;
25
26    public String Status;
27
28    public String Master_Inc_Num;
29
30    public String Primary;
31
32    public String OOS;
33
34    public String Type;
35
36    public String Curr_Loc;
37
38    public String Destination;
39
40    public String Misc_Info;
41
42    public String Stack;
43
44    public String Area;
45
46    public String Officer;
47
48    public String Badge_Num;
49
50    public String Timer;
51
52    public String Office;
53
54    public String P;
55
56    public String Agy;
57
58    public String Alias;
59
60    public String Unit_Status;
61
62    public Unit()
63    {
64        UnitNum = "";
65
66        ID = "";
67
68        Status = "";
69
70        Master_Inc_Num = "";
71
72        Primary = "";
73
74        OOS = "";
75
76        Type = "";
77
78        Curr_Loc = "";
79
80        Destination = "";
81
82        Misc_Info = "";
83
84        Stack = "";
85
86        Area = "";
87
88        Officer = "";
89
90        Badge_Num = "";
91
92        Timer = "";
93
94        Office = "";
95
96        P = "";
97
98        Agy = "";
99
100        Alias = "";
101
102        Unit_Status = "";
103    }
104
105    @Override
106    public String toXML()
107    {
108        String output = XMLWriter.openTag(ELEMENT.NEW_UNIT.tag + " UnitNum=\"" + UnitNum + "\"");
109
110        if (!ID.equals(""))
111        {
112            output += XMLWriter.simpleTag(ID, ELEMENT.ID);
113        }
114
115        if (!Status.equals(""))
116        {
117            output += XMLWriter.simpleTag(Status, ELEMENT.STATUS);
118        }
119
120        if (!Master_Inc_Num.equals(""))
121        {
122            output += XMLWriter.simpleTag(Master_Inc_Num, ELEMENT.MASTER_INC_NUM);
123        }
124
125        if (!Primary.equals(""))
126        {
127            output += XMLWriter.simpleTag(Primary, ELEMENT.PRIMARY);
128        }
129
130        if (!OOS.equals(""))
131        {
132            output += XMLWriter.simpleTag(OOS, ELEMENT.OOS);
133        }
134
135        if (!Type.equals(""))
136        {
137            output += XMLWriter.simpleTag(Type, ELEMENT.TYPE);
138        }
139
140        //All units have a current location field, even if it's blank
141        output += XMLWriter.simpleTag(Curr_Loc, ELEMENT.CURR_LOC);
142
143        //All units have a destination field, even if it's blank
144        output += XMLWriter.simpleTag(Destination, ELEMENT.DESTINATION);
145
146        if (!Misc_Info.equals(""))
147        {
148            output += XMLWriter.simpleTag(Misc_Info, ELEMENT.MISC_INFO);
149        }
150
151        if (!Stack.equals(""))
152        {
153            output += XMLWriter.simpleTag(Stack, ELEMENT.STACK);
154        }
155
156        if (!Area.equals(""))
157        {
158            output += XMLWriter.simpleTag(Area, ELEMENT.AREA);
159        }
160
161        if (!Badge_Num.equals(""))
162        {
163            output += XMLWriter.simpleTag(Badge_Num, ELEMENT.BADGE_NUM);
164        }
165
166        if (!Officer.equals(""))
167        {
168            output += XMLWriter.simpleTag(Officer, ELEMENT.OFFICER);
169        }
170
171        if (!Office.equals(""))
172        {
173            output += XMLWriter.simpleTag(Office, ELEMENT.OFFICE);
174        }
175
176        if (!Timer.equals(""))
177        {
178            output += XMLWriter.simpleTag(Timer, ELEMENT.TIMER);
179        }
180
181        if (!P.equals(""))
182        {
183            output += XMLWriter.simpleTag(P, ELEMENT.P);
184        }
185
186        if (!Agy.equals(""))
187        {
188            output += XMLWriter.simpleTag(Agy, ELEMENT.AGY);
189        }
190
191        if (!Alias.equals(""))
192        {
193            output += XMLWriter.simpleTag(Alias, ELEMENT.ALIAS);
194        }
195
196        if (!Unit_Status.equals(""))
197        {
198            output += XMLWriter.simpleTag(Unit_Status, ELEMENT.UNIT_STATUS);
199        }
200
201        output += XMLWriter.closeTag(ELEMENT.NEW_UNIT.tag);
202        return output;
203    }
204}
Note: See TracBrowser for help on using the repository browser.