Esempio n. 1
0
  /**
   * 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;
  }