| 1 | package tmcsim.cadmodels; |
|---|
| 2 | |
|---|
| 3 | import org.w3c.dom.Document; |
|---|
| 4 | import org.w3c.dom.Element; |
|---|
| 5 | import org.w3c.dom.Node; |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * IncidentBoardModel_obj is the model object containing all model |
|---|
| 10 | * information for an IncidentBoard CAD Screen. The model data includes |
|---|
| 11 | * a unique number, creation date and time, and message text.<br/> |
|---|
| 12 | * <br/> |
|---|
| 13 | * This element parses and creates the following XML schema in its toXML() and |
|---|
| 14 | * fromXML() methods. The ROOT element is the parameter for those methods. The |
|---|
| 15 | * specific XML schema for each IncidentInquiry model can be found in its |
|---|
| 16 | * class header.<br/> |
|---|
| 17 | * <ROOT> |
|---|
| 18 | * <NUM/> |
|---|
| 19 | * <DATE/> |
|---|
| 20 | * <TIME/> |
|---|
| 21 | * <MESSAGE/> |
|---|
| 22 | * </ROOT> |
|---|
| 23 | * |
|---|
| 24 | * @author Matthew Cechini |
|---|
| 25 | * @version |
|---|
| 26 | */ |
|---|
| 27 | public class IncidentBoardModel_obj { |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Enumeration with XML tag names. |
|---|
| 31 | * @author Matthew Cechini |
|---|
| 32 | */ |
|---|
| 33 | private static enum XML_TAGS { |
|---|
| 34 | /** Bulletin's number. */ |
|---|
| 35 | BULLETIN_NUM ("NUM"), |
|---|
| 36 | /** Bulletin's create date. */ |
|---|
| 37 | DATE ("DATE"), |
|---|
| 38 | /** Bulletin's creation time. */ |
|---|
| 39 | TIME ("TIME"), |
|---|
| 40 | /** Bulletin's message text. */ |
|---|
| 41 | MESSAGE ("MESSAGE"); |
|---|
| 42 | |
|---|
| 43 | public String tag; |
|---|
| 44 | |
|---|
| 45 | private XML_TAGS(String t) { |
|---|
| 46 | tag = t; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** Bulletin number. */ |
|---|
| 52 | public int bulletinNum; |
|---|
| 53 | |
|---|
| 54 | /** Bulletin creation date. */ |
|---|
| 55 | public String date; |
|---|
| 56 | |
|---|
| 57 | /** Bulletin creation time. */ |
|---|
| 58 | public String time; |
|---|
| 59 | |
|---|
| 60 | /** Bulletin message text. */ |
|---|
| 61 | public String message; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * Constructor. |
|---|
| 66 | */ |
|---|
| 67 | public IncidentBoardModel_obj() { |
|---|
| 68 | bulletinNum = 0; |
|---|
| 69 | date = null; |
|---|
| 70 | time = null; |
|---|
| 71 | message = null; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Constructor. |
|---|
| 76 | * |
|---|
| 77 | * @param newBulletinNum Bulletin number. |
|---|
| 78 | * @param newDate Bulletin creation date. |
|---|
| 79 | * @param newTime Bulletin create time. |
|---|
| 80 | * @param newMessage Bulletin message text. |
|---|
| 81 | */ |
|---|
| 82 | public IncidentBoardModel_obj(int newBulletinNum, |
|---|
| 83 | String newDate, |
|---|
| 84 | String newTime, |
|---|
| 85 | String newMessage) { |
|---|
| 86 | bulletinNum = newBulletinNum; |
|---|
| 87 | date = newDate; |
|---|
| 88 | time = newTime; |
|---|
| 89 | message = newMessage; |
|---|
| 90 | |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | public IncidentBoardModel_obj(Node modelNode) { |
|---|
| 94 | fromXML(modelNode); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | public void toXML(Element currElem) { |
|---|
| 98 | |
|---|
| 99 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 100 | Element tempElem = null; |
|---|
| 101 | |
|---|
| 102 | tempElem = theDoc.createElement(XML_TAGS.BULLETIN_NUM.tag); |
|---|
| 103 | tempElem.appendChild(theDoc.createTextNode(String.valueOf(bulletinNum))); |
|---|
| 104 | currElem.appendChild(tempElem); |
|---|
| 105 | |
|---|
| 106 | tempElem = theDoc.createElement(XML_TAGS.DATE.tag); |
|---|
| 107 | tempElem.appendChild(theDoc.createTextNode(date)); |
|---|
| 108 | currElem.appendChild(tempElem); |
|---|
| 109 | |
|---|
| 110 | tempElem = theDoc.createElement(XML_TAGS.TIME.tag); |
|---|
| 111 | tempElem.appendChild(theDoc.createTextNode(time)); |
|---|
| 112 | currElem.appendChild(tempElem); |
|---|
| 113 | |
|---|
| 114 | tempElem = theDoc.createElement(XML_TAGS.MESSAGE.tag); |
|---|
| 115 | tempElem.appendChild(theDoc.createTextNode(message)); |
|---|
| 116 | currElem.appendChild(tempElem); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | public void fromXML(Node modelNode) { |
|---|
| 120 | |
|---|
| 121 | Node childNode = null; |
|---|
| 122 | |
|---|
| 123 | childNode = modelNode.getFirstChild(); |
|---|
| 124 | bulletinNum = Integer.parseInt(childNode.getTextContent()); |
|---|
| 125 | |
|---|
| 126 | childNode = childNode.getNextSibling(); |
|---|
| 127 | date = childNode.getTextContent(); |
|---|
| 128 | |
|---|
| 129 | childNode = childNode.getNextSibling(); |
|---|
| 130 | time = childNode.getTextContent(); |
|---|
| 131 | |
|---|
| 132 | childNode = childNode.getNextSibling(); |
|---|
| 133 | message = childNode.getTextContent(); |
|---|
| 134 | |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | } |
|---|