| 1 | package tmcsim.cadmodels; |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | import java.io.Serializable; |
|---|
| 5 | import java.util.Vector; |
|---|
| 6 | |
|---|
| 7 | import org.w3c.dom.Document; |
|---|
| 8 | import org.w3c.dom.Element; |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * CMSInfo is a container class to contain the id, postmile, initial route, |
|---|
| 12 | * and diversion information for a single changeable message sign. The |
|---|
| 13 | * isCleared() method is used to determine if all diversions for this sign are |
|---|
| 14 | * cleared. The isUpdated() methods determines if any of the diversions for |
|---|
| 15 | * this sign have been updated from user input. |
|---|
| 16 | * |
|---|
| 17 | * @author Matthew Cechini |
|---|
| 18 | * @version |
|---|
| 19 | */ |
|---|
| 20 | @SuppressWarnings("serial") |
|---|
| 21 | public class CMSInfo implements Serializable { |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * Enumeration with XML tag names. |
|---|
| 25 | * @author Matthew Cechini |
|---|
| 26 | */ |
|---|
| 27 | private static enum XML_TAGS { |
|---|
| 28 | /** Diversion info. */ |
|---|
| 29 | DIVERSION ("DIVERSION"); |
|---|
| 30 | |
|---|
| 31 | public String tag; |
|---|
| 32 | |
|---|
| 33 | private XML_TAGS(String t) { |
|---|
| 34 | tag = t; |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | /** The unique ID for this CMS. */ |
|---|
| 39 | public String cmsID; |
|---|
| 40 | |
|---|
| 41 | /** The postmile for this CMS. */ |
|---|
| 42 | public Float postmile; |
|---|
| 43 | |
|---|
| 44 | /** The initial route where this CMS is located. */ |
|---|
| 45 | public String initialRoute; |
|---|
| 46 | |
|---|
| 47 | /** Vector of all possible diversions for this CMS. */ |
|---|
| 48 | public Vector<CMSDiversion> possibleDiversions; |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Constructor. |
|---|
| 52 | */ |
|---|
| 53 | public CMSInfo() { |
|---|
| 54 | cmsID = new String(); |
|---|
| 55 | postmile = new Float(0); |
|---|
| 56 | initialRoute = new String(); |
|---|
| 57 | possibleDiversions = new Vector<CMSDiversion>(); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * Constructor. |
|---|
| 62 | * |
|---|
| 63 | * @param newID CMS ID |
|---|
| 64 | * @param newPM CMS postmile |
|---|
| 65 | * @param newInitRt CMS initial route |
|---|
| 66 | */ |
|---|
| 67 | public CMSInfo(String newID, Float newPM, String newInitRt) { |
|---|
| 68 | cmsID = newID; |
|---|
| 69 | postmile = newPM; |
|---|
| 70 | initialRoute = newInitRt; |
|---|
| 71 | possibleDiversions = new Vector<CMSDiversion>(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Add a new CMS diversion option. A new diversion includes information |
|---|
| 76 | * regarding the old and new paths that traffic will be diverted from and to. |
|---|
| 77 | * The diversion also includes the Paramics diversion string and the maximum |
|---|
| 78 | * percentage of traffic that can be diverted. |
|---|
| 79 | * |
|---|
| 80 | * @param oPath Old path. |
|---|
| 81 | * @param nPath New path. |
|---|
| 82 | * @param dPath Paramics diversion path. |
|---|
| 83 | * @param perc Maximum diversion percentage. |
|---|
| 84 | */ |
|---|
| 85 | public void addNewDiversion(String oPath, String nPath, String dPath, Integer perc) { |
|---|
| 86 | possibleDiversions.add(new CMSDiversion(oPath, nPath, dPath, perc)); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * Determines if all possible diversions for this CMS sign are clear. If |
|---|
| 91 | * so, true is returned, else false is returned. |
|---|
| 92 | * |
|---|
| 93 | * @return True if all diversions are clear, false if not. |
|---|
| 94 | */ |
|---|
| 95 | public boolean isCleared() { |
|---|
| 96 | |
|---|
| 97 | for(CMSDiversion theDiv : possibleDiversions) { |
|---|
| 98 | if(!theDiv.isCleared()) |
|---|
| 99 | return false; |
|---|
| 100 | } |
|---|
| 101 | return true; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Determines if any possible diversions for this CMS sign have |
|---|
| 106 | * been upted. If so, true is returned, else false is returned. |
|---|
| 107 | * |
|---|
| 108 | * @return True if a diversions has been updated, false if not. |
|---|
| 109 | */ |
|---|
| 110 | public boolean isUpdated() { |
|---|
| 111 | |
|---|
| 112 | for(CMSDiversion div : possibleDiversions) { |
|---|
| 113 | if(div.isUpdated()) |
|---|
| 114 | return true; |
|---|
| 115 | } |
|---|
| 116 | return false; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Reset all possible diversions. |
|---|
| 121 | */ |
|---|
| 122 | public void reset() { |
|---|
| 123 | for(CMSDiversion div : possibleDiversions) { |
|---|
| 124 | div.reset(); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | * Write the XML output for all the diversions represented |
|---|
| 130 | * in this object. The format is as follows: |
|---|
| 131 | * |
|---|
| 132 | |
|---|
| 133 | * |
|---|
| 134 | * @param xmlOut XMLWriter used for XML creation. |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * Creates XML tags with the diversion data represented in this object. |
|---|
| 138 | * The XML is creaetd with the following format. The ROOT element is the |
|---|
| 139 | * parameter for this method.<br/> |
|---|
| 140 | * <ROOT> |
|---|
| 141 | * <DIVERSION> |
|---|
| 142 | * <Diversion_path> |
|---|
| 143 | * <Identifier/> |
|---|
| 144 | * <Percentage/> |
|---|
| 145 | * </Diversion_path> |
|---|
| 146 | * ... |
|---|
| 147 | * <Diversion_path/> |
|---|
| 148 | * </DIVERSION> |
|---|
| 149 | * </ROOT> |
|---|
| 150 | * |
|---|
| 151 | * @param currElem XML Element used as a root for XML tag appending. |
|---|
| 152 | */ |
|---|
| 153 | public void toXML(Element currElem) { |
|---|
| 154 | |
|---|
| 155 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 156 | |
|---|
| 157 | Element divElem = null; |
|---|
| 158 | |
|---|
| 159 | for(CMSDiversion theDiv : possibleDiversions) { |
|---|
| 160 | |
|---|
| 161 | if(!theDiv.isCleared() && theDiv.isUpdated()) { |
|---|
| 162 | |
|---|
| 163 | divElem = theDoc.createElement(XML_TAGS.DIVERSION.tag); |
|---|
| 164 | currElem.appendChild(divElem); |
|---|
| 165 | |
|---|
| 166 | theDiv.toXML(divElem); |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | } |
|---|