Index: trunk/src/tmcsim/cadsimulator/Coordinator.java
===================================================================
--- trunk/src/tmcsim/cadsimulator/Coordinator.java	(revision 44)
+++ trunk/src/tmcsim/cadsimulator/Coordinator.java	(revision 54)
@@ -38,4 +38,5 @@
 import tmcsim.client.cadclientgui.data.Incident;
 import tmcsim.client.cadclientgui.data.IncidentEvent;
+import tmcsim.client.cadclientgui.data.Unit;
 import tmcsim.client.cadclientgui.enums.CADDataEnums.CARDFILE;
 import tmcsim.client.cadclientgui.enums.CADDataEnums.EditCommand;
@@ -87,5 +88,4 @@
         implements CoordinatorInterface
 {
-
     /**
      * Error logger.
@@ -133,4 +133,10 @@
     }
 
+    /** Dependency Injection for testing */
+    void setCadData(CADData theData)
+    {
+        cadData = theData;
+    }
+    
     public void registerForCallback(CADClientInterface client) throws RemoteException
     {
@@ -914,5 +920,7 @@
         if (tag.equals(INC_TABLE.COMMENTS_NOTES))
         {
-            return cadData.getIncident(incidentId).getCommentsNotesTable();
+            Incident myIncident = cadData.getIncident(incidentId);
+            if (myIncident == null) return new DefaultTableModel();
+            return myIncident.getCommentsNotesTable();
         }
         return null;
@@ -955,43 +963,51 @@
     public Object getCadDataIncVal(INC_VAL tag, int incidentId) throws RemoteException
     {
-        if (tag.equals(INC_VAL.LOG_NUM))
-        {
-            return cadData.getIncident(incidentId).getLogNum();
-        }
-        else if (tag.equals(INC_VAL.MASTER_INC))
-        {
-            return cadData.getIncident(incidentId).getMasterInc();
-        }
-        else if (tag.equals(INC_VAL.OAU))
-        {
-            return cadData.getIncident(incidentId).getOau();
-        }
-        else if (tag.equals(INC_VAL.P))
-        {
-            return cadData.getIncident(incidentId).getP();
-        }
-        else if (tag.equals(INC_VAL.DESCRIPTION))
-        {
-            return cadData.getIncident(incidentId).getDescription();
-        }
-        else if (tag.equals(INC_VAL.RP))
-        {
-            return cadData.getIncident(incidentId).getRp();
-        }
-        else if (tag.equals(INC_VAL.RP_TYPE))
-        {
-            return cadData.getIncident(incidentId).getRpType();
-        }
-        else if (tag.equals(INC_VAL.ALI))
-        {
-            return cadData.getIncident(incidentId).getAli();
-        }
-        else if (tag.equals(INC_VAL.MEDIA))
-        {
-            return cadData.getIncident(incidentId).getMedia();
-        }
-        else
-        {
-            throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataIncVal");
+        Incident current = cadData.getIncident(incidentId);
+        if (current != null)
+        {
+            if (tag.equals(INC_VAL.LOG_NUM))
+            {
+                return current.getLogNum();
+            }
+            else if (tag.equals(INC_VAL.MASTER_INC))
+            {
+                return current.getMasterInc();
+            }
+            else if (tag.equals(INC_VAL.OAU))
+            {
+                return current.getOau();
+            }
+            else if (tag.equals(INC_VAL.P))
+            {
+                return current.getP();
+            }
+            else if (tag.equals(INC_VAL.DESCRIPTION))
+            {
+                return current.getDescription();
+            }
+            else if (tag.equals(INC_VAL.RP))
+            {
+                return current.getRp();
+            }
+            else if (tag.equals(INC_VAL.RP_TYPE))
+            {
+                return current.getRpType();
+            }
+            else if (tag.equals(INC_VAL.ALI))
+            {
+                return current.getAli();
+            }
+            else if (tag.equals(INC_VAL.MEDIA))
+            {
+                return current.getMedia();
+            }
+            else
+            {
+                throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataIncVal");
+            }
+        }
+        else
+        {
+            return null;
         }
     }
@@ -1049,75 +1065,83 @@
     public String getCadDataIncLoc(INC_LOC tag, int incidentId) throws RemoteException
     {
-        if (tag.equals(INC_LOC.ADDRESS))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getAddress();
-        }
-        else if (tag.equals(INC_LOC.LOC))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getLoc();
-        }
-        else if (tag.equals(INC_LOC.CITY))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getCity();
-        }
-        else if (tag.equals(INC_LOC.COUNTY))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getCounty();
-        }
-        else if (tag.equals(INC_LOC.STATE))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getState();
-        }
-        else if (tag.equals(INC_LOC.ZIP))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getZip();
-        }
-        else if (tag.equals(INC_LOC.BEAT))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getBeat();
-        }
-        else if (tag.equals(INC_LOC.AREA))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getArea();
-        }
-        else if (tag.equals(INC_LOC.SECTOR))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getSector();
-        }
-        else if (tag.equals(INC_LOC.SECTOR_CODE))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getSectorCode();
-        }
-        else if (tag.equals(INC_LOC.DIVISION))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getDivision();
-        }
-        else if (tag.equals(INC_LOC.APT))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getApt();
-        }
-        else if (tag.equals(INC_LOC.BUILDING))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getBuilding();
-        }
-        else if (tag.equals(INC_LOC.CROSS_ST))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getCrossSt();
-        }
-        else if (tag.equals(INC_LOC.LAW))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getLaw();
-        }
-        else if (tag.equals(INC_LOC.FIRE))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getFire();
-        }
-        else if (tag.equals(INC_LOC.EMS))
-        {
-            return cadData.getIncident(incidentId).getIncidentLocation().getEms();
-        }
-        else
-        {
-            throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataIncLoc");
+        Incident current = cadData.getIncident(incidentId);
+        if (current != null)
+        {
+            if (tag.equals(INC_LOC.ADDRESS))
+            {
+                return current.getIncidentLocation().getAddress();
+            }
+            else if (tag.equals(INC_LOC.LOC))
+            {
+                return current.getIncidentLocation().getLoc();
+            }
+            else if (tag.equals(INC_LOC.CITY))
+            {
+                return current.getIncidentLocation().getCity();
+            }
+            else if (tag.equals(INC_LOC.COUNTY))
+            {
+                return current.getIncidentLocation().getCounty();
+            }
+            else if (tag.equals(INC_LOC.STATE))
+            {
+                return current.getIncidentLocation().getState();
+            }
+            else if (tag.equals(INC_LOC.ZIP))
+            {
+                return current.getIncidentLocation().getZip();
+            }
+            else if (tag.equals(INC_LOC.BEAT))
+            {
+                return current.getIncidentLocation().getBeat();
+            }
+            else if (tag.equals(INC_LOC.AREA))
+            {
+                return current.getIncidentLocation().getArea();
+            }
+            else if (tag.equals(INC_LOC.SECTOR))
+            {
+                return current.getIncidentLocation().getSector();
+            }
+            else if (tag.equals(INC_LOC.SECTOR_CODE))
+            {
+                return current.getIncidentLocation().getSectorCode();
+            }
+            else if (tag.equals(INC_LOC.DIVISION))
+            {
+                return current.getIncidentLocation().getDivision();
+            }
+            else if (tag.equals(INC_LOC.APT))
+            {
+                return current.getIncidentLocation().getApt();
+            }
+            else if (tag.equals(INC_LOC.BUILDING))
+            {
+                return current.getIncidentLocation().getBuilding();
+            }
+            else if (tag.equals(INC_LOC.CROSS_ST))
+            {
+                return current.getIncidentLocation().getCrossSt();
+            }
+            else if (tag.equals(INC_LOC.LAW))
+            {
+                return current.getIncidentLocation().getLaw();
+            }
+            else if (tag.equals(INC_LOC.FIRE))
+            {
+                return current.getIncidentLocation().getFire();
+            }
+            else if (tag.equals(INC_LOC.EMS))
+            {
+                return current.getIncidentLocation().getEms();
+            }
+            else
+            {
+                throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataIncLoc");
+            }
+        }
+        else
+        {
+            return "";
         }
     }
@@ -1132,75 +1156,83 @@
     public void setCadDataIncLoc(INC_LOC tag, int incidentId, String value) throws RemoteException
     {
-        if (tag.equals(INC_LOC.ADDRESS))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setAddress(value);
-        }
-        else if (tag.equals(INC_LOC.LOC))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setLoc(value);
-        }
-        else if (tag.equals(INC_LOC.CITY))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setCity(value);
-        }
-        else if (tag.equals(INC_LOC.COUNTY))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setCounty(value);
-        }
-        else if (tag.equals(INC_LOC.STATE))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setState(value);
-        }
-        else if (tag.equals(INC_LOC.ZIP))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setZip(value);
-        }
-        else if (tag.equals(INC_LOC.BEAT))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setBeat(value);
-        }
-        else if (tag.equals(INC_LOC.AREA))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setArea(value);
-        }
-        else if (tag.equals(INC_LOC.SECTOR))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setSector(value);
-        }
-        else if (tag.equals(INC_LOC.SECTOR_CODE))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setSectorCode(value);
-        }
-        else if (tag.equals(INC_LOC.DIVISION))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setDivision(value);
-        }
-        else if (tag.equals(INC_LOC.APT))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setApt(value);
-        }
-        else if (tag.equals(INC_LOC.BUILDING))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setBuilding(value);
-        }
-        else if (tag.equals(INC_LOC.CROSS_ST))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setCrossSt(value);
-        }
-        else if (tag.equals(INC_LOC.LAW))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setLaw(value);
-        }
-        else if (tag.equals(INC_LOC.FIRE))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setFire(value);
-        }
-        else if (tag.equals(INC_LOC.EMS))
-        {
-            cadData.getIncident(incidentId).getIncidentLocation().setEms(value);
-        }
-        else
-        {
-            throw new RemoteException("Wrong Enum sent into Coordinator.setCadDataIncLoc");
+        Incident current = cadData.getIncident(incidentId);
+        if (current != null)
+        {
+            if (tag.equals(INC_LOC.ADDRESS))
+            {
+                current.getIncidentLocation().setAddress(value);
+            }
+            else if (tag.equals(INC_LOC.LOC))
+            {
+                current.getIncidentLocation().setLoc(value);
+            }
+            else if (tag.equals(INC_LOC.CITY))
+            {
+                current.getIncidentLocation().setCity(value);
+            }
+            else if (tag.equals(INC_LOC.COUNTY))
+            {
+                current.getIncidentLocation().setCounty(value);
+            }
+            else if (tag.equals(INC_LOC.STATE))
+            {
+                current.getIncidentLocation().setState(value);
+            }
+            else if (tag.equals(INC_LOC.ZIP))
+            {
+                current.getIncidentLocation().setZip(value);
+            }
+            else if (tag.equals(INC_LOC.BEAT))
+            {
+                current.getIncidentLocation().setBeat(value);
+            }
+            else if (tag.equals(INC_LOC.AREA))
+            {
+                current.getIncidentLocation().setArea(value);
+            }
+            else if (tag.equals(INC_LOC.SECTOR))
+            {
+                current.getIncidentLocation().setSector(value);
+            }
+            else if (tag.equals(INC_LOC.SECTOR_CODE))
+            {
+                current.getIncidentLocation().setSectorCode(value);
+            }
+            else if (tag.equals(INC_LOC.DIVISION))
+            {
+                current.getIncidentLocation().setDivision(value);
+            }
+            else if (tag.equals(INC_LOC.APT))
+            {
+                current.getIncidentLocation().setApt(value);
+            }
+            else if (tag.equals(INC_LOC.BUILDING))
+            {
+                current.getIncidentLocation().setBuilding(value);
+            }
+            else if (tag.equals(INC_LOC.CROSS_ST))
+            {
+                current.getIncidentLocation().setCrossSt(value);
+            }
+            else if (tag.equals(INC_LOC.LAW))
+            {
+                current.getIncidentLocation().setLaw(value);
+            }
+            else if (tag.equals(INC_LOC.FIRE))
+            {
+                current.getIncidentLocation().setFire(value);
+            }
+            else if (tag.equals(INC_LOC.EMS))
+            {
+                current.getIncidentLocation().setEms(value);
+            }
+            else
+            {
+                throw new RemoteException("Wrong Enum sent into Coordinator.setCadDataIncLoc");
+            }
+        }
+        else
+        {
+            return;
         }
     }
@@ -2076,5 +2108,25 @@
     public UnitStatusEnums getCadDataUnitStatus(String unitNum) throws RemoteException
     {
-        return cadData.getUnit(unitNum).getUnitStatus();
+        // Validate input parameter
+        if (unitNum.equals(""))
+        {
+            coorLogger.logp(Level.INFO, "Coordinator", "getCadDataUnitStatus",
+                        "Unitnum parameter is blank.", "Error");
+            return UnitStatusEnums.NotAssignable;
+        }
+        else
+        {
+            Unit desiredUnit = cadData.getUnit(unitNum);
+            // If it exists
+            if (desiredUnit != null)
+            {
+                // Fetch and return its status (an enum)
+                return desiredUnit.getUnitStatus();
+            }
+            else
+            {
+                return UnitStatusEnums.NotAssignable;
+            }
+        }
     }
 
@@ -2089,71 +2141,84 @@
     public String getCadDataUnitValue(String unitNum, UNIT_TAGS tag) throws RemoteException
     {
-        if (tag.equals(UNIT_TAGS.MASTER_INC_NUM))
-        {
-            return cadData.getUnit(unitNum).getMasterInc();
-        }
-        else if (tag.equals(UNIT_TAGS.STATUS))
-        {
-            return cadData.getUnit(unitNum).getStatus();
-        }
-        else if (tag.equals(UNIT_TAGS.OOS))
-        {
-            return cadData.getUnit(unitNum).getOos();
-        }
-        else if (tag.equals(UNIT_TAGS.TYPE))
-        {
-            return cadData.getUnit(unitNum).getType();
-        }
-        else if (tag.equals(UNIT_TAGS.CURR_LOC))
-        {
-            return cadData.getUnit(unitNum).getCurrentLocation();
-        }
-        else if (tag.equals(UNIT_TAGS.DESTINATION))
-        {
-            return cadData.getUnit(unitNum).getDestination();
-        }
-        else if (tag.equals(UNIT_TAGS.MISC_INFO))
-        {
-            return cadData.getUnit(unitNum).getMisc();
-        }
-        else if (tag.equals(UNIT_TAGS.STACK))
-        {
-            return cadData.getUnit(unitNum).getStack();
-        }
-        else if (tag.equals(UNIT_TAGS.AREA))
-        {
-            return cadData.getUnit(unitNum).getArea();
-        }
-        else if (tag.equals(UNIT_TAGS.OFFICER))
-        {
-            return cadData.getUnit(unitNum).getOfficer();
-        }
-        else if (tag.equals(UNIT_TAGS.BADGE_NUM))
-        {
-            return cadData.getUnit(unitNum).getBadge();
-        }
-        else if (tag.equals(UNIT_TAGS.TIMER))
-        {
-            return cadData.getUnit(unitNum).getTimerInString();
-        }
-        else if (tag.equals(UNIT_TAGS.OFFICE))
-        {
-            return cadData.getUnit(unitNum).getOffice();
-        }
-        else if (tag.equals(UNIT_TAGS.P))
-        {
-            return cadData.getUnit(unitNum).getP();
-        }
-        else if (tag.equals(UNIT_TAGS.AGY))
-        {
-            return cadData.getUnit(unitNum).getAgy();
-        }
-        else if (tag.equals(UNIT_TAGS.ALIAS))
-        {
-            return cadData.getUnit(unitNum).getAlias();
-        }
-        else
-        {
-            throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataUnitValue");
+        // Fetch unit, given it's string representation
+        Unit desiredUnit = cadData.getUnit(unitNum);
+        // If it exists
+        if (desiredUnit != null)
+        {
+            if (tag.equals(UNIT_TAGS.MASTER_INC_NUM))
+            {
+                return desiredUnit.getMasterInc();
+            }
+            else if (tag.equals(UNIT_TAGS.STATUS))
+            {
+                return desiredUnit.getStatus();
+            }
+            else if (tag.equals(UNIT_TAGS.OOS))
+            {
+                return desiredUnit.getOos();
+            }
+            else if (tag.equals(UNIT_TAGS.TYPE))
+            {
+                return desiredUnit.getType();
+            }
+            else if (tag.equals(UNIT_TAGS.CURR_LOC))
+            {
+                return desiredUnit.getCurrentLocation();
+            }
+            else if (tag.equals(UNIT_TAGS.DESTINATION))
+            {
+                return desiredUnit.getDestination();
+            }
+            else if (tag.equals(UNIT_TAGS.MISC_INFO))
+            {
+                return desiredUnit.getMisc();
+            }
+            else if (tag.equals(UNIT_TAGS.STACK))
+            {
+                return desiredUnit.getStack();
+            }
+            else if (tag.equals(UNIT_TAGS.AREA))
+            {
+                return desiredUnit.getArea();
+            }
+            else if (tag.equals(UNIT_TAGS.OFFICER))
+            {
+                return desiredUnit.getOfficer();
+            }
+            else if (tag.equals(UNIT_TAGS.BADGE_NUM))
+            {
+                return desiredUnit.getBadge();
+            }
+            else if (tag.equals(UNIT_TAGS.TIMER))
+            {
+                return desiredUnit.getTimerInString();
+            }
+            else if (tag.equals(UNIT_TAGS.OFFICE))
+            {
+                return desiredUnit.getOffice();
+            }
+            else if (tag.equals(UNIT_TAGS.P))
+            {
+                return desiredUnit.getP();
+            }
+            else if (tag.equals(UNIT_TAGS.AGY))
+            {
+                return desiredUnit.getAgy();
+            }
+            else if (tag.equals(UNIT_TAGS.ALIAS))
+            {
+                return desiredUnit.getAlias();
+            }
+            else
+            {
+                throw new RemoteException("Wrong Enum sent into Coordinator.getCadDataUnitValue");
+            }
+        }
+        else
+        {
+            coorLogger.logp(Level.INFO, "Coordinator", "getCadDataUnitValue",
+                    "Desired unit not found: " + unitNum
+                    + ". Proceeding with empty string value.", "Error");
+            return "";
         }
     }
