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