| 1 | package tmcsim.cadmodels; |
|---|
| 2 | |
|---|
| 3 | import java.io.Serializable; |
|---|
| 4 | |
|---|
| 5 | import org.w3c.dom.Document; |
|---|
| 6 | import org.w3c.dom.Element; |
|---|
| 7 | import org.w3c.dom.Node; |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * IncidentInquiryLogEntry is the base model object used for IncidentInquiry |
|---|
| 11 | * log entries. Every log entry has an associated position and timestamp for |
|---|
| 12 | * where the data originated. <br/> |
|---|
| 13 | * <br/> |
|---|
| 14 | * This element parses and creates the following XML schema in its toXML() and |
|---|
| 15 | * fromXML() methods. The ROOT element is the parameter for those methods.<br/> |
|---|
| 16 | * <ROOT><br/> |
|---|
| 17 | * <POSITION_INFO/><br/> |
|---|
| 18 | * <TIMESTAMP/><br/> |
|---|
| 19 | * </ROOT><br/> |
|---|
| 20 | * |
|---|
| 21 | * @author Matthew Cechini |
|---|
| 22 | * @version |
|---|
| 23 | */ |
|---|
| 24 | @SuppressWarnings("serial") |
|---|
| 25 | public class IncidentInquiryLogEntry implements Serializable { |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * Enumeration with XML tag names. |
|---|
| 29 | * @author Matthew Cechini |
|---|
| 30 | */ |
|---|
| 31 | private static enum XML_TAGS { |
|---|
| 32 | /** Log entry position info. */ |
|---|
| 33 | POSITION_INFO ("POSITION_INFO"), |
|---|
| 34 | /** Log entry timestamp. */ |
|---|
| 35 | TIMESTAMP ("TIMESTAMP"); |
|---|
| 36 | |
|---|
| 37 | public String tag; |
|---|
| 38 | |
|---|
| 39 | private XML_TAGS(String t) { |
|---|
| 40 | tag = t; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /** Position information for this log entry. */ |
|---|
| 45 | protected String positionInfo; |
|---|
| 46 | |
|---|
| 47 | /** Time stamp value for this log entry. */ |
|---|
| 48 | protected String timeStamp; |
|---|
| 49 | |
|---|
| 50 | /** Default Constructor. Initialize local data. */ |
|---|
| 51 | public IncidentInquiryLogEntry() { |
|---|
| 52 | positionInfo = ""; |
|---|
| 53 | timeStamp = "0000"; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | /** |
|---|
| 57 | * Constructor. Set position info and time stamp. |
|---|
| 58 | * |
|---|
| 59 | * @param newPosInfo Position info for this log entry |
|---|
| 60 | * @param newTimeStamp Time stamp for this log entry |
|---|
| 61 | */ |
|---|
| 62 | public IncidentInquiryLogEntry(String newPosInfo, String newTimeStamp) { |
|---|
| 63 | positionInfo = newPosInfo; |
|---|
| 64 | timeStamp = newTimeStamp; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Creates XML tags with the model data and adds them to the parameter |
|---|
| 69 | * Element. See clss description for XML schema. |
|---|
| 70 | * |
|---|
| 71 | * @param currElem XML Element used as a root for XML tag appending. |
|---|
| 72 | */ |
|---|
| 73 | public void toXML(Element currElem) { |
|---|
| 74 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 75 | Element tempElem = null; |
|---|
| 76 | |
|---|
| 77 | tempElem = theDoc.createElement(XML_TAGS.POSITION_INFO.tag); |
|---|
| 78 | tempElem.appendChild(theDoc.createTextNode(positionInfo)); |
|---|
| 79 | currElem.appendChild(tempElem); |
|---|
| 80 | |
|---|
| 81 | tempElem = theDoc.createElement(XML_TAGS.TIMESTAMP.tag); |
|---|
| 82 | tempElem.appendChild(theDoc.createTextNode(timeStamp)); |
|---|
| 83 | currElem.appendChild(tempElem); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * Parses model data from the parameter Node. See clss description for |
|---|
| 88 | * XML schema. |
|---|
| 89 | * |
|---|
| 90 | * @param modelNode XML Node containing model information. |
|---|
| 91 | */ |
|---|
| 92 | public void fromXML(Node modelNode) { |
|---|
| 93 | Node childNode = null; |
|---|
| 94 | |
|---|
| 95 | //childNode = modelNode.getFirstChild(); |
|---|
| 96 | positionInfo = modelNode.getTextContent(); |
|---|
| 97 | |
|---|
| 98 | childNode = modelNode.getNextSibling(); |
|---|
| 99 | timeStamp = childNode.getTextContent(); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * Sets the time stamp for this log entry. |
|---|
| 105 | * |
|---|
| 106 | * @param newStamp The timestamp value. |
|---|
| 107 | */ |
|---|
| 108 | public void timeStamp(String newStamp) { |
|---|
| 109 | timeStamp = newStamp; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * Returns the log information for this log entry. The log information |
|---|
| 114 | * is the concatenation of the entering position info and timestamp. |
|---|
| 115 | * |
|---|
| 116 | * @return Log entry's log information |
|---|
| 117 | */ |
|---|
| 118 | public String getLogInfo() { |
|---|
| 119 | return positionInfo += timeStamp; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|