/** * Sets the specified interface entry as the default for the involved 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. */ public static synchronized boolean setDefaultInterfaceEntry( String givModelFilename, String gwId, long givIntefaceId) { boolean successFlag = false; Model3dIndexEntry existingEntry = checkforGivenEntry(givModelFilename); if (existingEntry != null) { // // get the vector with the interfaces for this gateway/model AND check if the specified // interface (to be set as default) exists or not! // Vector<Model3dInterfaceEntry> tmpInterfaceVector = existingEntry.getInterfacesVecForGwId(gwId); if (givIntefaceId != existingEntry.getDefaultInterfaceIdForGwId(gwId)) { for (int i = 0; i < tmpInterfaceVector.size(); i++) { if (tmpInterfaceVector.elementAt(i).getIntefaceId() == givIntefaceId) { existingEntry.setDefaultInterfaceIdForGwId(gwId, givIntefaceId); // // save changes to Index. // Model3dIndex.writeIndexBackToFile(); successFlag = true; break; } } } else { successFlag = true; } } return successFlag; }
/** * 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; }
/** * Handles creating a new entry for a modelfile-to-gateway mapping in the Model3dIndex and a new * model metafile for this mapping (which contains all interfaces for the mapping) If this is the * first time this entry is created, the Model3dIndex is updated with the new entry and the newly * created metafile will contain only one interface with id 0. If this mapping already exists in * the Model3dIndex, only the existing metafile will be updated, by adding a new interface with id * equal to the maximum existing id increased by 1. * * @param givModelFilename the filename for the mapped 3d Model * @param gwId the id for the mapped gateway * @param gwName the name of the gateway (mostly needed for description purposes) * @param givInterfaceDesc a description string for the interface (namely the mapping instance) * @param givLineOfRef the line of reference in the 3d Model, as to which all rooms will be * aligned * @param givRoomsVec the vector with the defined rooms * @param updatemode a switch which defines out action. Can be Model3dIndex.updateModeInsert (for * inserting a new interface), or Model3dIndex.updateModeUpdate (for editing an existing * interface) * @return true if successful, false otherwise. */ public static synchronized boolean addNewModelIndexEntry( String givModelFilename, String gwId, String gwName, String givInterfaceDesc, Model3dLineOfReference givLineOfRef, Vector<Model3dRoomEntry> givRoomsVec, int updatemode) { /** * Two possible things could happen: if insert_mode { check if already exists if not: create * entry, create metafilename, create metafile, write info to metafile, update this vector, * write back to index file. if it does ------> append a new interface! <----- } if * update_replace_mode { (To do) Future work. When "edit interface" is implemented. check if * already exists if not: revert to insert_mode if it does: parse entry, edit info in entry * (gateway, kml file) (if kml filename is changed check for conflicts (if already exists in * another entry etc), open metafile, edit metafile (interfaces), write back metafile, write * back index file. } */ boolean successFlag = false; Model3dIndexEntry existingEntry = checkforGivenEntry(givModelFilename); switch (updatemode) { case Model3dIndex.updateModeInsert: { String metaFileName = Model3dIndexEntry.getUndefinedMetaFilename(); long newInterfaceId = Model3dInterfaceEntry.getUnknownInterfaceId(); if (existingEntry != null) { // check if this gateway has an entry in the Model3dIndex. If it has none then add one, // and set the above interface as default. if (existingEntry.findGatewayEntry(gwId) == null) { // append a new GatewayEntry to this Model3dIndexEntry newInterfaceId = 0; Model3dMetaGatewayEntry tmpGwEntry = new Model3dMetaGatewayEntry(gwId, gwName, newInterfaceId); existingEntry.getMetaGatewaysVec().addElement(tmpGwEntry); Model3dIndex.writeIndexBackToFile(); } else { newInterfaceId = Model3dInterfaceEntry .getUnknownInterfaceId(); // this will trigger a search for a proper new // interface id in the appendInterfaceForGwId() // method } successFlag = existingEntry.appendInterfaceForGwId( gwId, new Model3dInterfaceEntry( gwId, newInterfaceId, givInterfaceDesc, givLineOfRef, givRoomsVec)); } else { // create metafileName from ModelFilename (add a suffix "meta" AND change the extension // to .xml // remove any path info from modelfilename int lastslash = givModelFilename.lastIndexOf(File.separator); if (lastslash != -1) { if (givModelFilename.length() > lastslash + 1) givModelFilename = givModelFilename.substring(lastslash + 1); else return successFlag; // no filename was given, just a path } String justTheName = ""; // get purefilename - no extension int lastdot = givModelFilename.lastIndexOf('.'); if (lastdot != -1) { if (lastdot == 0) // if it is the first char then ignore it and copy the entire // givModelFilename string to the justthename string { justTheName = givModelFilename; } else justTheName = givModelFilename.substring(0, lastdot); } else // no extension is given { justTheName = givModelFilename; } metaFileName = /*Model3dIndex.getIndexPath() + */ justTheName + "Meta.xml"; // update the Model3dIndex newInterfaceId = 0; Vector<Model3dMetaGatewayEntry> tmpMappedGateways = new Vector<Model3dMetaGatewayEntry>(); long defaultInterfaceSetForGw = newInterfaceId; tmpMappedGateways.add( new Model3dMetaGatewayEntry(gwId, gwName, defaultInterfaceSetForGw)); Model3dIndexEntry theNewlyMadeEntry = new Model3dIndexEntry(metaFileName, givModelFilename, tmpMappedGateways); Model3dIndex.getListofAllMetaEntries().add(theNewlyMadeEntry); Model3dIndex.writeIndexBackToFile(); // we want the default interface id for the gateway // if it's the first entry the interface index will be 0. // else it will be the largest interface number + 1. successFlag = theNewlyMadeEntry.appendInterfaceForGwId( gwId, new Model3dInterfaceEntry( gwId, newInterfaceId, givInterfaceDesc, givLineOfRef, givRoomsVec)); } break; } case Model3dIndex.updateModeUpdate: { // (To do) (add code) future work. When "edit interface" is implemented. break; } default: return successFlag; } return successFlag; }