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

Revision 2, 4.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 * IncidentInquiryUnitsAssigned extends from IncidentInquiryLogEntry
11 * to provide a model object containing information used to display an assigned
12 * unit.  Data for an assigned unit includes a flag designating whether
13 * the unit is primary, the beat number, the unit's status, and a flag
14 * designating whether the unit is active or not.<br/>
15 * <br/>
16 * This element parses and creates the following XML schema in its toXML() and
17 * fromXML() methods.  The ROOT element is the parameter for those methods.<br/>
18 * <ROOT><br/>
19 *    <IS_PRIMARY/><br/>
20 *    <BEAT>/<br/>
21 *    <STATUS_TYPE/><br/>
22 *    <IS_ACTIVE/><br/>
23 *    <POSITION_INFO/><br/>
24 *    <TIMESTAMP/><br/>
25 * </ROOT><br/>
26 *
27 * @author Matthew Cechini
28 * @version
29 */
30@SuppressWarnings("serial")
31public class IncidentInquiryUnitsAssigned extends IncidentInquiryLogEntry
32    implements Serializable {
33   
34    private static enum XML_TAGS {
35        /** Unit's primary flag. */
36        IS_PRIMARY  ("IS_PRIMARY"),     
37        /** Unit's beat. */
38        BEAT        ("BEAT"),
39        /** Unit's status type. */
40        STATUS_TYPE ("STATUS_TYPE"),
41        /** Unit's active flag. */
42        IS_ACTIVE   ("IS_ACTIVE");
43       
44        public String tag;
45       
46        private XML_TAGS(String t) {
47            tag = t;
48        }
49       
50    }
51
52    /** Unit is primary flag. */
53    public boolean isPrimary;   
54
55    /** Unit's beat. */
56    public String  beat;   
57 
58    /** Unit's current status. */
59    public String  statusType; 
60
61    /** Unit's current active flag. */
62    public boolean isActive;
63   
64   
65    /**
66     * Constructor.  Initialize all unit data to empty strings or false.
67     *
68     *  @param newPosInfo String containing position info for this log entry
69     */
70    public IncidentInquiryUnitsAssigned(String newPosInfo) {
71        super(newPosInfo, "0000");
72       
73        isPrimary  = false;
74        beat       = "";
75        statusType = "";
76        isActive   = false;     
77    }
78 
79    /**
80     * Constructor.  Parse parameter node for Unit log entry data.
81     *
82     * @param theNode Node containing data for this Unit log entry
83     */
84    public IncidentInquiryUnitsAssigned(Node theNode) { 
85        fromXML(theNode);
86    }   
87
88    public void toXML(Element currElem) {
89       
90        Document theDoc    = currElem.getOwnerDocument();
91        Element  tempElem  = null;
92       
93        tempElem = theDoc.createElement(XML_TAGS.IS_PRIMARY.tag);
94        tempElem.appendChild(theDoc.createTextNode(String.valueOf(isPrimary)));
95        currElem.appendChild(tempElem);
96       
97        tempElem = theDoc.createElement(XML_TAGS.BEAT.tag);
98        tempElem.appendChild(theDoc.createTextNode(beat));
99        currElem.appendChild(tempElem);
100       
101        tempElem = theDoc.createElement(XML_TAGS.STATUS_TYPE.tag);
102        tempElem.appendChild(theDoc.createTextNode(statusType));
103        currElem.appendChild(tempElem);
104       
105        tempElem = theDoc.createElement(XML_TAGS.IS_ACTIVE.tag);
106        tempElem.appendChild(theDoc.createTextNode(String.valueOf(isActive)));
107        currElem.appendChild(tempElem);
108
109        super.toXML(currElem);
110    }   
111   
112    public void fromXML(Node modelNode) {   
113       
114        Node childNode = null;
115       
116        childNode = modelNode.getFirstChild();
117        isPrimary = Boolean.parseBoolean(childNode.getTextContent());
118       
119        childNode = childNode.getNextSibling();
120        beat = childNode.getTextContent();
121       
122        childNode = childNode.getNextSibling();
123        statusType = childNode.getTextContent();
124       
125        childNode = childNode.getNextSibling();
126        isActive = Boolean.parseBoolean(childNode.getTextContent());
127
128        childNode = childNode.getNextSibling();
129        super.fromXML(childNode);
130       
131    }     
132   
133   
134    /** Determines equality based on beat */
135    public boolean equals(Object o) {
136        return beat.equals(((IncidentInquiryUnitsAssigned)o).beat);
137    }
138}
Note: See TracBrowser for help on using the repository browser.