Beispiel #1
0
 public static IIndexFragmentFile[] findFiles(
     PDOM pdom, BTree btree, IIndexFileLocation location, IIndexLocationConverter strategy)
     throws CoreException {
   String internalRepresentation = strategy.toInternalFormat(location);
   if (internalRepresentation != null) {
     Finder finder = new Finder(pdom.getDB(), internalRepresentation, -1, null);
     btree.accept(finder);
     long[] records = finder.getRecords();
     PDOMFile[] result = new PDOMFile[records.length];
     for (int i = 0; i < result.length; i++) {
       result[i] = recreateFile(pdom, records[i]);
     }
     return result;
   }
   return IIndexFragmentFile.EMPTY_ARRAY;
 }
Beispiel #2
0
 /**
  * Finds the file in index.
  *
  * @param linkage The linkage of the file.
  * @param btree The file index.
  * @param location The location of the file.
  * @param strategy The index location converter.
  * @param macroDictionary The names and definitions of the macros used to disambiguate between
  *     variants of the file contents corresponding to different inclusion points.
  * @return The found file, or <code>null</code> if the matching file was not found.
  */
 public static PDOMFile findFile(
     PDOMLinkage linkage,
     BTree btree,
     IIndexFileLocation location,
     IIndexLocationConverter strategy,
     ISignificantMacros macroDictionary)
     throws CoreException {
   String internalRepresentation = strategy.toInternalFormat(location);
   if (internalRepresentation != null) {
     Finder finder =
         new Finder(
             linkage.getDB(), internalRepresentation, linkage.getLinkageID(), macroDictionary);
     btree.accept(finder);
     long record = finder.getRecord();
     if (record != 0) {
       return new PDOMFile(linkage, record);
     }
   }
   return null;
 }
  /**
   * Uses the specified location converter to update each internal representation of a file
   * location. The file index is rebuilt with the new representations. Individual PDOMFile records
   * are unmoved so as to maintain referential integrity with other PDOM records.
   *
   * <p><b>A write-lock must be obtained before calling this method</b>
   *
   * @param newConverter the converter to use to update internal file representations
   * @throws CoreException
   */
  public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
    final List<PDOMFile> pdomfiles = new ArrayList<PDOMFile>();
    getFileIndex()
        .accept(
            new IBTreeVisitor() {
              @Override
              public int compare(long record) throws CoreException {
                return 0;
              }

              @Override
              public boolean visit(long record) throws CoreException {
                PDOMFile file = PDOMFile.recreateFile(WritablePDOM.this, record);
                pdomfiles.add(file);
                return true;
              }
            });

    clearFileIndex();
    final List<PDOMFile> notConverted = new ArrayList<PDOMFile>();
    for (PDOMFile file : pdomfiles) {
      String internalFormat = newConverter.toInternalFormat(file.getLocation());
      if (internalFormat != null) {
        file.setInternalLocation(internalFormat);
        getFileIndex().insert(file.getRecord());
      } else {
        notConverted.add(file);
      }
    }

    // remove content where converter returns null
    for (PDOMFile file : notConverted) {
      file.convertIncludersToUnresolved();
      file.clear();
    }
  }