Exemplo n.º 1
0
 /**
  * Deletes the specified interface from a model-gateway mapping. Should take care of consistency
  * issues such as: a) updating the default interface for the mapping (if we are deleting a default
  * interface then the interface that will be set as default will be the one with the minimum id)
  * and b) deleting the entire mapping, and the gateway entry from the Model3dIndexEntry if this is
  * the last interface for the specified model-gateway mapping.
  *
  * @param givModelFilename the filename of the model in the mapping
  * @param gwId the id of the gateway in the mapping
  * @param givIntefaceId the id of the interface to be deleted
  * @return true if successful, otherwise false. (To do )(Add code here)
  */
 public static synchronized boolean deleteInterfaceEntry(
     String givModelFilename, String gwId, long givIntefaceId) {
   boolean successFlag = false;
   Model3dIndexEntry existingEntry = checkforGivenEntry(givModelFilename);
   if (existingEntry != null) {
     //
     // Remove the specified interface from the Metafile
     //
     existingEntry.removeInterfaceForGw(gwId, givIntefaceId);
     //
     // IF its the only interface then delete the gateway entry from the Model3dIndexEntry as well.
     //
     Vector<Model3dInterfaceEntry> tmpInterfaceVector =
         existingEntry.getInterfacesVecForGwId(gwId);
     if (tmpInterfaceVector != null && tmpInterfaceVector.isEmpty()) {
       existingEntry.deleteGatewayEntry(gwId);
       if (existingEntry.getMetaGatewaysVec().isEmpty()) {
         // then delete Metafile AND the entry from the Model3dIndex
         existingEntry.deleteMetafile();
         Model3dIndex.deleteEntry(givModelFilename);
         existingEntry = null;
       }
     } else if (givIntefaceId == existingEntry.getDefaultInterfaceIdForGwId(gwId)) {
       //
       // IF its the default interface then, change the default interface to a remaining interface
       // with minimum id.
       //
       long newDefaultId = existingEntry.getMinInterfaceIdForGwId(gwId);
       existingEntry.setDefaultInterfaceIdForGwId(gwId, newDefaultId);
     }
     //
     // save changes to files.
     //
     Model3dIndex.writeIndexBackToFile();
     return true;
   }
   return false;
 }