| 1 | package tmcsim.cadmodels; |
|---|
| 2 | |
|---|
| 3 | import java.util.Vector; |
|---|
| 4 | |
|---|
| 5 | import org.w3c.dom.Document; |
|---|
| 6 | import org.w3c.dom.Element; |
|---|
| 7 | import org.w3c.dom.Node; |
|---|
| 8 | import org.w3c.dom.NodeList; |
|---|
| 9 | |
|---|
| 10 | import tmcsim.common.ScriptException; |
|---|
| 11 | import tmcsim.common.CADEnums.CADScreenNum; |
|---|
| 12 | import tmcsim.common.CADEnums.CADScreenType; |
|---|
| 13 | import tmcsim.common.CADProtocol.CAD_COMMANDS; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * IncidentBoardModel is a CADScreenModel object containing data that is |
|---|
| 18 | * displayed in the IncidentBoard CAD Screen. The addModelObject() method |
|---|
| 19 | * is used to update the model data with new information.<br/> |
|---|
| 20 | * <br/> |
|---|
| 21 | * This element parses and creates the following XML schema in its toXML() and |
|---|
| 22 | * fromXML() methods. The ROOT element is the parameter for those methods. |
|---|
| 23 | * See the class description for the CADScreenModel and |
|---|
| 24 | * IncidentBoardModel_obj Objects for their XML schema.<br/> |
|---|
| 25 | * <ROOT> |
|---|
| 26 | * <INCIDENT_BOARD> |
|---|
| 27 | * <BASE_MODEL_INFO/> |
|---|
| 28 | * <MESSAGE/> |
|---|
| 29 | * ... |
|---|
| 30 | * <MESSAGE/> |
|---|
| 31 | * </INCIDENT_BOARD> |
|---|
| 32 | * </ROOT> |
|---|
| 33 | * |
|---|
| 34 | * @see IncidentBoardModel_obj |
|---|
| 35 | * @see CADScreenModel |
|---|
| 36 | * @author Matthew Cechini |
|---|
| 37 | * @version |
|---|
| 38 | */ |
|---|
| 39 | public class IncidentBoardModel extends CADScreenModel { |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Enumeration with XML tag names. |
|---|
| 43 | * @author Matthew Cechini |
|---|
| 44 | */ |
|---|
| 45 | private static enum XML_TAGS { |
|---|
| 46 | MESSAGE ("MESSAGE"); |
|---|
| 47 | |
|---|
| 48 | public String tag; |
|---|
| 49 | |
|---|
| 50 | private XML_TAGS(String t) { |
|---|
| 51 | tag = t; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | /** Model data. List of IncidentBoardModel_obj objects. */ |
|---|
| 56 | private Vector<IncidentBoardModel_obj> messageList = null; |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Constructor. |
|---|
| 60 | * |
|---|
| 61 | * @param num CADScreenNum for this model. |
|---|
| 62 | */ |
|---|
| 63 | public IncidentBoardModel(CADScreenNum num) { |
|---|
| 64 | super(CADScreenType.IB_INCIDENT_BOARD, num); |
|---|
| 65 | |
|---|
| 66 | messageList = new Vector<IncidentBoardModel_obj>(); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * Constructor. Create model data from parsed parameter XML node. |
|---|
| 71 | * |
|---|
| 72 | * @param newNode XML node containing model data. |
|---|
| 73 | * @throws ScriptException if there is an error in parsing the Node. |
|---|
| 74 | */ |
|---|
| 75 | public IncidentBoardModel(Node newNode) throws ScriptException { |
|---|
| 76 | super(CADScreenType.IB_INCIDENT_BOARD, CADScreenNum.ONE); |
|---|
| 77 | |
|---|
| 78 | messageList = new Vector<IncidentBoardModel_obj>(); |
|---|
| 79 | |
|---|
| 80 | fromXML(newNode); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Add a new model object to the list of messages. |
|---|
| 85 | * |
|---|
| 86 | * @param ismo IncidentBoardModel_obj |
|---|
| 87 | * @throws ClassCastException if the parameter is not an |
|---|
| 88 | * IncidentBoardModel_obj object. |
|---|
| 89 | */ |
|---|
| 90 | public void addModelObject(Object ibmo) throws ClassCastException { |
|---|
| 91 | |
|---|
| 92 | if(ibmo instanceof IncidentBoardModel_obj) |
|---|
| 93 | messageList.add((IncidentBoardModel_obj)ibmo); |
|---|
| 94 | else |
|---|
| 95 | throw new ClassCastException(); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * Get the list of messages in this model. |
|---|
| 100 | * |
|---|
| 101 | * @return Vector of IncidentBoardModel_obj objects. |
|---|
| 102 | */ |
|---|
| 103 | public Vector<IncidentBoardModel_obj> getModelObjects() { |
|---|
| 104 | return messageList; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | public void toXML(Element currElem) { |
|---|
| 108 | |
|---|
| 109 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 110 | |
|---|
| 111 | Element modelElem = theDoc.createElement(CAD_COMMANDS.INCIDENT_BOARD.fullName); |
|---|
| 112 | |
|---|
| 113 | baseToXML(modelElem); |
|---|
| 114 | |
|---|
| 115 | Element ibmoElem = null; |
|---|
| 116 | for(IncidentBoardModel_obj ibmo : messageList) { |
|---|
| 117 | ibmoElem = theDoc.createElement(XML_TAGS.MESSAGE.tag); |
|---|
| 118 | |
|---|
| 119 | ibmo.toXML(ibmoElem); |
|---|
| 120 | |
|---|
| 121 | modelElem.appendChild(ibmoElem); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | currElem.appendChild(modelElem); |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | public void fromXML(Node modelNode) throws ScriptException { |
|---|
| 129 | |
|---|
| 130 | messageList.clear(); |
|---|
| 131 | |
|---|
| 132 | modelNode = modelNode.getFirstChild(); |
|---|
| 133 | |
|---|
| 134 | baseFromXML(modelNode); |
|---|
| 135 | |
|---|
| 136 | NodeList messageNodes = ((Element)modelNode).getElementsByTagName(XML_TAGS.MESSAGE.tag); |
|---|
| 137 | |
|---|
| 138 | for(int i = 0; i < messageNodes.getLength(); i++) |
|---|
| 139 | messageList.add(new IncidentBoardModel_obj(messageNodes.item(i))); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | } |
|---|
| 143 | } |
|---|