source: tmcsimulator/trunk/src/tmcsim/cadmodels/IncidentInquiryHeader.java @ 2

Revision 2, 10.0 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

Line 
1package tmcsim.cadmodels;
2
3import java.io.Serializable;
4
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7import org.w3c.dom.Node;
8
9
10/**
11 * IncidentInquiryHeader contains model data containing information used to
12 * display the CAD log Header inofrmation.  Data for the header includes the
13 * following Incident data:
14 * <ul>
15 * <li>Log number</li>
16 * <li>Log status</li>
17 * <li>Priority</li>
18 * <li>Type</li>
19 * <li>Callbox Number</li>
20 * <li>Beat</li>
21 * <li>Full Location</li>
22 * <li>Truncated Location</li>
23 * <li>Origin</li>
24 * <li>Date</li>
25 * <li>Time</li>
26 * <li>Dispatcher</li>
27 * <ul>
28 * <br/>
29 * This element parses and creates the following XML schema in its toXML() and
30 * fromXML() methods.  The ROOT element is the parameter for those methods. 
31 * See the class description for the CADScreenModel and
32 * IncidentSummaryModel_obj Objects for their XML schema.<br/>
33 * <ROOT>
34 *    <LOG_NUMBER/>
35 *    <LOG_STATUS/>
36 *    <PRIORITY/>
37 *    <TYPE/>
38 *    <CALLBOX_NUM/>
39 *    <BEAT/>
40 *    <FULL_LOC/>
41 *    <TRUNC_LOC/>
42 *    <ORIGIN/>
43 *    <INCIDENT_DATE/>
44 *    <INCIDENT_TIME/>
45 *    <DISPATCHER/>
46 * </ROOT>
47 *
48 * @see IncidentSummaryModel_obj
49 * @see CADScreenModel
50 * @author Matthew Cechini
51 * @version
52 */
53@SuppressWarnings("serial")
54public class IncidentInquiryHeader implements Serializable {
55   
56    /**
57     * Enumeration with XML tag names.
58     * @author Matthew Cechini
59     */
60    private static enum XML_TAGS {
61        /** Incident log number. */ 
62        LOG_NUMBER    ("LOG_NUMBER"),
63        /** Incident log status. */ 
64        LOG_STATUS    ("LOG_STATUS"),
65        /** Incident priority. */   
66        PRIORITY      ("PRIORITY"),
67        /** Incident type. */   
68        TYPE          ("TYPE"),
69        /** Call box number. */ 
70        CALLBOX_NUM   ("CALLBOX_NUM"),
71        /** Incident beat. */   
72        BEAT          ("BEAT"),
73        /** Incident full location. */ 
74        FULL_LOC      ("FULL_LOC"),
75        /** Incident truncated location. */ 
76        TRUNC_LOC     ("TRUNC_LOC"),
77        /** Log origin. */ 
78        ORIGIN        ("ORIGIN"),
79        /** Incident date. */   
80        INCIDENT_DATE ("INCIDENT_DATE"),
81        /** Incident time. */   
82        INCIDENT_TIME ("INCIDENT_TIME"),
83        /** Assigned dispatcher. */ 
84        DISPATCHER    ("DISPATCHER");
85       
86        public String tag;
87       
88        private XML_TAGS(String t) {
89            tag = t;
90        }       
91    }
92
93    /** Incident log number.  */
94    public Integer logNumber;
95   
96    /** Incident log status.  */
97    public String logStatus;
98   
99    /** Incident log priority.  */
100    public String priority;
101   
102    /** Incident log type.  */
103    public String type;
104   
105    /** Call Box number. */
106    public String callBoxNumber;
107   
108    /** Incident beat. */
109    public String beat;
110   
111    /** Incident full location. */
112    public String fullLocation;
113   
114    /** Incident truncated location.  */
115    public String truncLocation;
116   
117    /**
118     *  Incident log origin. Format: XXAYYYYY. 
119     *  XX = log position.  YYYYY = CAD user id.
120     */
121    public String origin;
122   
123    /** Incident log creation date. Format: MMDD */
124    public String incidentDate;
125   
126    /** Incident log create time. Format: HHMM */
127    public String incidentTime;
128   
129    /**
130     *Incident log dispatcher.  Format: XXAYYYYY. 
131     *  XX = log position.  YYYYY = CAD user id.
132     */
133    public String dispatcher;
134   
135    /** Constructor.  Initialize all class variables to 0 or empty string. */
136    public IncidentInquiryHeader() {
137        logNumber     = new Integer(0);
138        logStatus     = "";
139        priority      = "";
140        type          = "";
141        callBoxNumber = "";
142        beat          = "";
143        fullLocation  = "";
144        truncLocation = "";
145        origin        = "";
146        incidentDate  = "";
147        incidentTime  = "";       
148        dispatcher    = "";     
149       
150    }   
151   
152    /**
153     * Copy constructor.
154     *
155     * @param newIIH Object containing header information used to initialize
156     *               the new instance.
157     */
158    public IncidentInquiryHeader(IncidentInquiryHeader newIIH) {
159        logNumber     = new Integer(newIIH.logNumber);
160        logStatus     = new String(newIIH.logStatus);
161        priority      = new String(newIIH.priority);
162        type          = new String(newIIH.type);
163        callBoxNumber = new String(newIIH.callBoxNumber);
164        beat          = new String(newIIH.beat);
165        fullLocation  = new String(newIIH.fullLocation);
166        truncLocation = new String(newIIH.truncLocation);
167        origin        = new String(newIIH.origin);
168        incidentDate  = new String(newIIH.incidentDate);
169        incidentTime  = new String(newIIH.incidentTime);
170        dispatcher    = new String(newIIH.dispatcher);
171    }   
172   
173    /**
174     * Parse the paramater node ad assign all member data values.
175     *
176     * @param theNode Node containing XML data to parse header information from.
177     */
178    public IncidentInquiryHeader(Node theNode) {   
179        fromXML(theNode);
180    }
181   
182   
183    /**
184     * Updates the local member data with any member data in the parameter
185     * Header object that is not 0 or an empty string.
186     *
187     * TODO look at his method
188     * @param newHeader Object containing header information for update.
189     */
190    public void update(IncidentInquiryHeader newHeader) {
191       
192        if(newHeader.logNumber != 0) 
193            logNumber     = new Integer(newHeader.logNumber);
194        if(newHeader.logStatus.trim().length() > 0) 
195            logStatus     = new String(newHeader.logStatus);
196        if(newHeader.priority.trim().length() > 0) 
197            priority      = new String(newHeader.priority);     
198        if(newHeader.type.trim().length() > 0) 
199            type          = new String(newHeader.type);
200        if(newHeader.beat.trim().length() > 0) 
201            beat          = new String(newHeader.beat);
202        if(newHeader.fullLocation.trim().length() > 0) 
203            fullLocation  = new String(newHeader.fullLocation);
204        if(newHeader.truncLocation.trim().length() > 0) 
205            truncLocation = new String(newHeader.truncLocation);
206        if(newHeader.incidentDate.trim().length() > 0) 
207            incidentDate  = new String(newHeader.incidentDate);             
208        if(newHeader.incidentTime.trim().length() > 0) 
209            incidentTime  = new String(newHeader.incidentTime);         
210   
211    }   
212   
213   
214    public void toXML(Element currElem) {
215       
216        Document theDoc    = currElem.getOwnerDocument();
217        Element  tempElem  = null;
218       
219        tempElem = theDoc.createElement(XML_TAGS.LOG_NUMBER.tag);
220        tempElem.appendChild(theDoc.createTextNode(logNumber.toString()));
221        currElem.appendChild(tempElem);
222       
223        tempElem = theDoc.createElement(XML_TAGS.LOG_STATUS.tag);
224        tempElem.appendChild(theDoc.createTextNode(logStatus));
225        currElem.appendChild(tempElem);
226       
227        tempElem = theDoc.createElement(XML_TAGS.PRIORITY.tag);
228        tempElem.appendChild(theDoc.createTextNode(priority));
229        currElem.appendChild(tempElem);
230       
231        tempElem = theDoc.createElement(XML_TAGS.TYPE.tag);
232        tempElem.appendChild(theDoc.createTextNode(type));
233        currElem.appendChild(tempElem);
234       
235        tempElem = theDoc.createElement(XML_TAGS.CALLBOX_NUM.tag);
236        tempElem.appendChild(theDoc.createTextNode(callBoxNumber));
237        currElem.appendChild(tempElem);
238       
239        tempElem = theDoc.createElement(XML_TAGS.BEAT.tag);
240        tempElem.appendChild(theDoc.createTextNode(beat));
241        currElem.appendChild(tempElem);
242       
243        tempElem = theDoc.createElement(XML_TAGS.FULL_LOC.tag);
244        tempElem.appendChild(theDoc.createTextNode(fullLocation));
245        currElem.appendChild(tempElem);
246       
247        tempElem = theDoc.createElement(XML_TAGS.TRUNC_LOC.tag);
248        tempElem.appendChild(theDoc.createTextNode(truncLocation));
249        currElem.appendChild(tempElem);
250       
251        tempElem = theDoc.createElement(XML_TAGS.ORIGIN.tag);
252        tempElem.appendChild(theDoc.createTextNode(origin));
253        currElem.appendChild(tempElem);
254       
255        tempElem = theDoc.createElement(XML_TAGS.INCIDENT_DATE.tag);
256        tempElem.appendChild(theDoc.createTextNode(incidentDate));
257        currElem.appendChild(tempElem);
258       
259        tempElem = theDoc.createElement(XML_TAGS.INCIDENT_TIME.tag);
260        tempElem.appendChild(theDoc.createTextNode(incidentTime));
261        currElem.appendChild(tempElem);
262       
263        tempElem = theDoc.createElement(XML_TAGS.DISPATCHER.tag);
264        tempElem.appendChild(theDoc.createTextNode(dispatcher));
265        currElem.appendChild(tempElem);
266    }   
267   
268    public void fromXML(Node modelNode) {   
269       
270        Node childNode = null;
271       
272        childNode = modelNode.getFirstChild();
273        logNumber = Integer.parseInt(childNode.getTextContent());
274       
275        childNode = childNode.getNextSibling();
276        logStatus = childNode.getTextContent();
277       
278        childNode = childNode.getNextSibling();
279        priority = childNode.getTextContent();
280       
281        childNode = childNode.getNextSibling();
282        type = childNode.getTextContent();
283       
284        childNode = childNode.getNextSibling();
285        callBoxNumber = childNode.getTextContent();
286       
287        childNode = childNode.getNextSibling();
288        beat = childNode.getTextContent();
289       
290        childNode = childNode.getNextSibling();
291        fullLocation = childNode.getTextContent();
292       
293        childNode = childNode.getNextSibling();
294        truncLocation = childNode.getTextContent();
295       
296        childNode = childNode.getNextSibling();
297        origin = childNode.getTextContent();
298       
299        childNode = childNode.getNextSibling();
300        incidentDate = childNode.getTextContent();
301       
302        childNode = childNode.getNextSibling();
303        incidentTime = childNode.getTextContent();
304       
305        childNode = childNode.getNextSibling();
306        dispatcher = childNode.getTextContent();
307           
308    }     
309}
Note: See TracBrowser for help on using the repository browser.