source: tmcsimulator/trunk/src/tmcsim/cadmodels/IncidentInquiryModel_obj.java @ 2

Revision 2, 14.1 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

Line 
1package tmcsim.cadmodels;
2
3
4import java.io.Serializable;
5import java.util.Vector;
6
7import org.w3c.dom.Document;
8import org.w3c.dom.Element;
9import org.w3c.dom.Node;
10
11
12/**
13 * IncidentInquiryModel_obj is the model object containing all model
14 * information for an IncidentInquiry CAD Screen.  The model data includes
15 * a single IncidentInquiryHeader, and lists of IncidentInquiryDetails,
16 * IncidentInquiryAssignedUnits, IncidentInquiryTows, IncidentInquiryWitnesses,
17 * and IncidentInquiryServices.  The add???() methods append a new
18 * IncidentInquiry model object to the associated internal list.<br/>
19 * <br/>
20 * This element parses and creates the following XML schema in its toXML() and
21 * fromXML() methods.  The ROOT element is the parameter for those methods.  The
22 * specific XML schema for each IncidentInquiry model can be found in its
23 * class header.<br/>
24 * <ROOT>
25 *    <HEADER>
26 *    <DETAIL/>
27 *    ...
28 *    <DETAIL/>
29 *    <UNIT/>
30 *    ...
31 *    <UNIT/>
32 *    <WITNESS/>
33 *    ...
34 *    <WITNESS/>
35 *    <TOW/>
36 *    ...
37 *    <TOW/>
38 *    <SERVICE/>
39 *    ...
40 *    <SERVICE/>
41 * </ROOT>
42 *
43 * @see IncidentInquiryHeader
44 * @see IncidentInquiryDetails
45 * @see IncidentInquiryAssignedUnits
46 * @see IncidentInquiryTows
47 * @see IncidentInquiryWitnesses
48 * @see IncidentInquiryServices
49 * @author Matthew Cechini
50 * @version
51 */
52@SuppressWarnings("serial")
53public class IncidentInquiryModel_obj implements Serializable {
54   
55    /** Log position info for a log entry.  */
56    public static final String SCRIPT_POS_INFO   = "000A17661";     
57   
58    /**
59     * Enumeration with XML tag names.
60     * @author Matthew Cechini
61     */
62    private static enum XML_TAGS {
63        /** Header information. */
64        HEADER  ("HEADER"),
65        /** Detail log entry. */
66        DETAIL  ("DETAIL"),
67        /** Unit log entry. */
68        UNIT    ("UNIT"),
69        /** Witness log entry. */
70        WITNESS ("WITNESS"),
71        /** Tow log entry. */
72        TOW     ("TOW"),
73        /** Service log entry. */
74        SERVICE ("SERVICE"),
75        /** Updated entries. */
76        UPDATES  ("UPDATES");
77   
78        public String tag;
79       
80        private XML_TAGS(String t) {
81            tag = t;
82        }       
83    }
84   
85    /**  Header data. */
86    private IncidentInquiryHeader                header    = null;
87   
88    /** List of Detail objects. */
89    private Vector<IncidentInquiryDetails>       details   = null;
90   
91    /** List of UnitsAssigned objects. */
92    private Vector<IncidentInquiryUnitsAssigned> units     = null;
93   
94    /** List of Detail objects. */
95    private Vector<IncidentInquiryWitnesses>     witnesses = null;
96   
97    /** List of Tow objects. */
98    private Vector<IncidentInquiryTows>          tows      = null;
99   
100    /** List of Service objects. */
101    private Vector<IncidentInquiryServices>      services  = null; 
102   
103    /*
104    private boolean detailsUpdated   = false;
105    private boolean unitsUpdated     = false;
106    private boolean towsUpdated      = false;
107    private boolean witnessesUpdated = false;
108    private boolean servicesUpdated  = false;
109    */
110   
111    /**
112     * Origin of this object's data.  Options include "Script" or "CAD #",
113     * where # is a CAD position
114     */
115    private String source = "";           
116   
117    /**
118     * Construtor.  Initialize all local lists of IncidentInquiry objects. 
119     * Set source to "Script".
120     */
121    public IncidentInquiryModel_obj() {
122        source        = "Script";
123
124        header        = new IncidentInquiryHeader();
125        details       = new Vector<IncidentInquiryDetails>();
126        units         = new Vector<IncidentInquiryUnitsAssigned>();
127        witnesses     = new Vector<IncidentInquiryWitnesses>();
128        tows          = new Vector<IncidentInquiryTows>();
129        services      = new Vector<IncidentInquiryServices>(); 
130                     
131    }
132   
133    /** 
134     * Constructor.  Initialie all local lists of IncidentInquiry objects.
135     * Set srouce to "CAD #".
136     *
137     * @param CADPosition Integer value for the originating CAD position of this object's data.
138     */
139    public IncidentInquiryModel_obj(int CADPosition) {
140        source        = "CAD " + CADPosition;
141
142        header        = new IncidentInquiryHeader();
143        details       = new Vector<IncidentInquiryDetails>();
144        units         = new Vector<IncidentInquiryUnitsAssigned>();
145        witnesses     = new Vector<IncidentInquiryWitnesses>();
146        tows          = new Vector<IncidentInquiryTows>();
147        services      = new Vector<IncidentInquiryServices>(); 
148                     
149    }   
150
151    /** 
152     * Copy Constructor.
153     *
154     * @param newIIMO Object containing data to be copied into constructed object.
155     */
156    public IncidentInquiryModel_obj(IncidentInquiryModel_obj newIIMO) {
157        source        = newIIMO.source;
158       
159        header        = new IncidentInquiryHeader(newIIMO.header);
160        details       = new Vector<IncidentInquiryDetails>(newIIMO.details);
161        units         = new Vector<IncidentInquiryUnitsAssigned>(newIIMO.units);
162        witnesses     = new Vector<IncidentInquiryWitnesses>(newIIMO.witnesses);
163        tows          = new Vector<IncidentInquiryTows>(newIIMO.tows);
164        services      = new Vector<IncidentInquiryServices>(newIIMO.services); 
165    }
166
167    /**
168     * This method updates the private lists of IncidentInquiry data with `
169     * data contained in the parameter object. 
170     *
171     * @param newObject Object containing IncidentInquiry data that will
172     *                  be used to update local IncidentInquiry lists.
173     */
174    public void update(IncidentInquiryModel_obj newObject) {
175                       
176        header.update(newObject.header);       
177        details.addAll(newObject.getDetails());
178       
179        //Do not want duplicate units in the vector
180        for(IncidentInquiryUnitsAssigned unit : newObject.getUnits()) {
181            if(units.contains(unit)) {
182                IncidentInquiryUnitsAssigned oldUnit = units.get(units.indexOf(unit));
183                /*
184                if(oldUnit.isActive != unit.isActive ||
185                   oldUnit.isPrimary != unit.isPrimary ||
186                   oldUnit.statusType != unit.statusType)
187                {
188                    unitsUpdated |= true;
189                }   
190                */
191                units.remove(oldUnit);
192            }           
193            units.add(unit);           
194        }
195       
196        witnesses.addAll(newObject.getWitnesses());
197        tows.addAll(newObject.getTows());
198        services.addAll(newObject.getServices());       
199
200        /*
201        detailsUpdated   |= newObject.getDetails().size() > 0;
202        witnessesUpdated |= newObject.getWitnesses().size() > 0;
203        towsUpdated      |= newObject.getTows().size() > 0;
204        servicesUpdated  |= newObject.getServices().size() > 0;
205        */
206       
207    }
208   
209    public void toXML(Element currElem) {
210       
211        Document theDoc = currElem.getOwnerDocument();
212        /*
213        Element updatesElem = theDoc.createElement(UPDATES);
214        currElem.appendChild(updatesElem);
215       
216        Element updateElem  = theDoc.createElement(DETAIL);
217        updateElem.appendChild(theDoc.createTextNode(String.valueOf(detailsUpdated)));
218        updatesElem.appendChild(updateElem);
219       
220        updateElem  = theDoc.createElement(UNIT);
221        updateElem.appendChild(theDoc.createTextNode(String.valueOf(unitsUpdated)));
222        updatesElem.appendChild(updateElem);
223       
224        updateElem  = theDoc.createElement(WITNESS);
225        updateElem.appendChild(theDoc.createTextNode(String.valueOf(witnessesUpdated)));
226        updatesElem.appendChild(updateElem);
227       
228        updateElem  = theDoc.createElement(TOW);
229        updateElem.appendChild(theDoc.createTextNode(String.valueOf(towsUpdated)));
230        updatesElem.appendChild(updateElem);
231       
232        updateElem  = theDoc.createElement(SERVICE);
233        updateElem.appendChild(theDoc.createTextNode(String.valueOf(servicesUpdated)));
234        updatesElem.appendChild(updateElem);
235        */
236               
237        Element headerElem = theDoc.createElement(XML_TAGS.HEADER.tag);
238        header.toXML(headerElem);
239        currElem.appendChild(headerElem);
240       
241        Element detailElem = null;
242        for(IncidentInquiryDetails detail : details) {
243            detailElem = theDoc.createElement(XML_TAGS.DETAIL.tag);
244            detail.toXML(detailElem);
245            currElem.appendChild(detailElem);
246        }
247       
248        Element unitElem = null;       
249        for(IncidentInquiryUnitsAssigned unit : units) {
250            unitElem = theDoc.createElement(XML_TAGS.UNIT.tag);         
251            unit.toXML(unitElem);
252            currElem.appendChild(unitElem);
253        }
254       
255        Element witnessElem = null;     
256        for(IncidentInquiryWitnesses witness : witnesses) {
257            witnessElem = theDoc.createElement(XML_TAGS.WITNESS.tag);
258            witness.toXML(witnessElem);
259            currElem.appendChild(witnessElem);
260        }
261       
262        Element towElem = null;     
263        for(IncidentInquiryTows tow : tows) {
264            towElem = theDoc.createElement(XML_TAGS.TOW.tag);           
265            tow.toXML(towElem);
266            currElem.appendChild(towElem);         
267        }
268       
269        Element serviceElem = null;     
270        for(IncidentInquiryServices service : services) {
271            serviceElem = theDoc.createElement(XML_TAGS.SERVICE.tag);               
272            service.toXML(serviceElem);
273            currElem.appendChild(serviceElem);
274        } 
275       
276    }
277   
278    public void fromXML(Node modelNode) {
279
280        Node     currentNode = modelNode;
281        //Node     updateNode  = null;
282        String   nodeName    = null;
283       
284        details.clear();
285        units.clear();
286        witnesses.clear();
287        tows.clear();
288        services.clear();
289       
290        /*
291        updateNode = currentNode.getFirstChild();
292        detailsUpdated = Boolean.parseBoolean(updateNode.getTextContent());
293        updateNode = updateNode.getNextSibling();
294        unitsUpdated = Boolean.parseBoolean(updateNode.getTextContent());
295        updateNode = updateNode.getNextSibling();
296        witnessesUpdated = Boolean.parseBoolean(updateNode.getTextContent());
297        updateNode = updateNode.getNextSibling();
298        towsUpdated = Boolean.parseBoolean(updateNode.getTextContent());
299        updateNode = updateNode.getNextSibling();
300        servicesUpdated = Boolean.parseBoolean(updateNode.getTextContent());
301        */
302       
303        header = new IncidentInquiryHeader(currentNode);
304       
305        while((currentNode = currentNode.getNextSibling()) != null) {
306            nodeName    = currentNode.getNodeName();   
307           
308            if(nodeName.equals(XML_TAGS.DETAIL.tag)) { 
309                details.add(new IncidentInquiryDetails(currentNode));
310            }
311            else if(nodeName.equals(XML_TAGS.UNIT.tag)) { 
312                units.add(new IncidentInquiryUnitsAssigned(currentNode));
313            }
314            else if(nodeName.equals(XML_TAGS.WITNESS.tag)) { 
315                witnesses.add(new IncidentInquiryWitnesses(currentNode));
316            }
317            else if(nodeName.equals(XML_TAGS.TOW.tag)) { 
318                tows.add(new IncidentInquiryTows(currentNode));
319            }
320            else if(nodeName.equals(XML_TAGS.SERVICE.tag)) { 
321                services.add(new IncidentInquiryServices(currentNode));
322            }
323       }       
324    }
325   
326    /**
327     * Applies the parameter timestamp to all IncidentInquiry objects.
328     *
329     * @param timeStamp String containing timestamp
330     */
331    public void timeStamp(String timeStamp) {
332        for(IncidentInquiryDetails detail : details)
333            detail.timeStamp(timeStamp);
334       
335        for(IncidentInquiryUnitsAssigned unit : units) {           
336            unit.timeStamp(timeStamp);
337        }
338       
339        for(IncidentInquiryWitnesses witness : witnesses) {
340            witness.timeStamp(timeStamp);
341        }       
342        for(IncidentInquiryTows tow : tows) {           
343            tow.timeStamp(timeStamp);           
344        }
345        for(IncidentInquiryServices service : services) {               
346            service.timeStamp(timeStamp);
347        }
348    }
349
350    /**
351     * Gets the log number value for this IncidentInquiry object.
352     *
353     * @return Integer Log number value
354     */
355    public Integer getLogNumber() {
356        return header.logNumber;
357    }
358   
359    /**
360     * Sets this objects log number to a new value.
361     *
362     * @param logNum New log number.
363     */
364    public void setLogNumber(Integer logNum) {
365        header.logNumber = logNum;
366    }
367       
368    public IncidentInquiryHeader                getHeader()    {return header;}
369    public Vector<IncidentInquiryDetails>       getDetails()   {return details;}
370    public Vector<IncidentInquiryUnitsAssigned> getUnits()     {return units;} 
371    public Vector<IncidentInquiryWitnesses>     getWitnesses() {return witnesses;}
372    public Vector<IncidentInquiryTows>          getTows()      {return tows;}
373    public Vector<IncidentInquiryServices>      getServices()  {return services;}   
374   
375    public void setHeader(IncidentInquiryHeader newHeader)      {header = newHeader;}
376    public void addDetail(IncidentInquiryDetails newDetail)     {details.add(newDetail);}
377    public void addUnit(IncidentInquiryUnitsAssigned newUnit)   {
378        if(units.contains(newUnit)) {
379            units.remove(newUnit);
380        }
381       
382        units.add(newUnit); 
383    } 
384    public void addWitness(IncidentInquiryWitnesses newWitness) {witnesses.add(newWitness);}
385    public void addTow(IncidentInquiryTows newTow)              {tows.add(newTow);}
386    public void addService(IncidentInquiryServices newService)  {services.add(newService);}
387   
388    /*
389    public boolean getDetailsUpdated()   { return detailsUpdated; }
390    public boolean getUnitsUpdated()     { return unitsUpdated; }
391    public boolean getTowsUpdated()      { return towsUpdated; }
392    public boolean getWitnessesUpdated() { return witnessesUpdated; }
393    public boolean getServicesUpdated()  { return servicesUpdated; }
394    */ 
395   
396    public String getSource() {
397        return source;
398    }   
399}
Note: See TracBrowser for help on using the repository browser.