This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 222204
Collapse All | Expand All

(-)a/openide.loaders/apichanges.xml (+17 lines)
Lines 109-114 Link Here
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
110
110
111
  <changes>
111
  <changes>
112
      <change id="DataShadow.findOriginal">
113
          <api name="loaders"/>
114
          <summary>
115
              Introduced <code>DataShadow.findOriginal</code> which extracts the original file from
116
              a FileObject representing a shadow/link.
117
          </summary>
118
          <version major="7" minor="42"/>
119
          <date day="22" month="11" year="2012"/>
120
          <author login="sdedic"/>
121
          <compatibility addition="yes"/>
122
          <description>
123
              Target FileObject can be obtained, instead of DataObject. The target may be invalid,
124
              or otherwise unsuitable for DataObject creation. Use this method to just dereference
125
              the shadow file.
126
          </description>
127
          <class package="org.openide.loaderss" name="DataShadow"/>
128
      </change>
112
      <change id="DataObjec.Registration">
129
      <change id="DataObjec.Registration">
113
          <api name="loaders"/>
130
          <api name="loaders"/>
114
          <summary>Introduced <code>DataObject.Registration</code> and <code>DataObject.Registrations</code></summary>
131
          <summary>Introduced <code>DataObject.Registration</code> and <code>DataObject.Registrations</code></summary>
(-)a/openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.41
3
OpenIDE-Module-Specification-Version: 7.42
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
(-)a/openide.loaders/src/org/openide/loaders/DataShadow.java (-6 / +27 lines)
Lines 391-407 Link Here
391
    }
391
    }
392
    
392
    
393
    /**
393
    /**
394
     * Tries to load the original file from a shadow.
394
     * Tries to locate the original file from a shadow.
395
     * Looks for file contents as well as the originalFile/originalFileSystem attributes.
395
     * Looks for file contents as well as the originalFile/originalFileSystem attributes.
396
     * Attempts to discover locations for migrated files in configuration.
396
     * Attempts to discover locations for migrated files in configuration. Returns
397
     * {@code null}, if the target file could not be found (broken link)
397
     * 
398
     * 
398
     * @param fileObject a data shadow
399
     * @param fileObject a data shadow
399
     * @return the original <code>DataObject</code> referenced by the shadow
400
     * @return the original <code>FileObject</code> referenced by the shadow
400
     * @throws IOException error during load or broken link
401
     * @throws IOException error during load 
401
     * 
402
     * 
402
     * @see Utilities#translate
403
     * @see Utilities#translate
404
     * @since 7.42
403
     */
405
     */
404
    protected static DataObject deserialize(FileObject fileObject) throws IOException {
406
    public static FileObject findOriginal(FileObject fileObject) throws IOException {
405
        String[] fileAndFileSystem = readOriginalFileAndFileSystem(fileObject);
407
        String[] fileAndFileSystem = readOriginalFileAndFileSystem(fileObject);
406
        String path = fileAndFileSystem[0];
408
        String path = fileAndFileSystem[0];
407
        assert path != null;
409
        assert path != null;
Lines 465-476 Link Here
465
                }
467
                }
466
            }
468
            }
467
        }
469
        }
470
        return target;
471
    }
472
    
473
    /**
474
     * Tries to load the original file from a shadow.
475
     * Looks for file contents as well as the originalFile/originalFileSystem attributes.
476
     * Attempts to discover locations for migrated files in configuration.
477
     * 
478
     * @param fileObject a data shadow
479
     * @return the original <code>DataObject</code> referenced by the shadow
480
     * @throws IOException error during load or broken link
481
     * 
482
     * @see Utilities#translate
483
     */
484
    protected static DataObject deserialize(FileObject fileObject) throws IOException {
485
        FileObject target = findOriginal(fileObject);
468
        if (target != null) {
486
        if (target != null) {
469
            return DataObject.find(target);
487
            return DataObject.find(target);
470
        } else {
488
        } else {
471
            throw new FileNotFoundException(path + ':' + fsname);
489
            String[] fileAndFileSystem = readOriginalFileAndFileSystem(fileObject);
490
            String path = fileAndFileSystem[0];
491
            throw new FileNotFoundException(path + ':' + fileAndFileSystem[1]);
472
        }
492
        }
473
    }
493
    }
494
    
474
    static URL readURL(FileObject fileObject) throws IOException {
495
    static URL readURL(FileObject fileObject) throws IOException {
475
        String[] fileAndFileSystem = readOriginalFileAndFileSystem(fileObject);
496
        String[] fileAndFileSystem = readOriginalFileAndFileSystem(fileObject);
476
        String path = fileAndFileSystem[0];
497
        String path = fileAndFileSystem[0];
(-)a/openide.loaders/test/unit/src/org/openide/loaders/DataShadowTest.java (+42 lines)
Lines 437-440 Link Here
437
        R action = new R();
437
        R action = new R();
438
        FileUtil.runAtomicAction(action);
438
        FileUtil.runAtomicAction(action);
439
    }
439
    }
440
    
441
    /**
442
     * Tests the method findOriginal()
443
     * @throws Exception 
444
     */
445
    public void testFindOriginal() throws Exception {
446
        FileSystem fs = FileUtil.createMemoryFileSystem();
447
        FileObject orig = FileUtil.createData(fs.getRoot(), "path/to/orig");
448
        FileObject shadow = FileUtil.createData(fs.getRoot(), "link.shadow");
449
        shadow.setAttribute("originalFile", "path/to/orig");
450
        assertEquals("found the right original file", 
451
                orig, DataShadow.findOriginal(shadow));
452
    }
453
    
454
    /**
455
     * Checks that findOriginal returns null on broken (but formally
456
     * correct) shadow
457
     * @throws Exception C
458
     */
459
    public void testFindMissingOriginal() throws Exception {
460
        FileSystem fs = FileUtil.createMemoryFileSystem();
461
        FileObject shadow = FileUtil.createData(fs.getRoot(), "link.shadow");
462
        shadow.setAttribute("originalFile", "path/to/orig");
463
        assertNull("null should be returned for missing target", DataShadow.findOriginal(shadow));
464
    }
465
    
466
    /**
467
     * Checks that findOriginal throws Exception on a malformed 
468
     * shadow
469
     * @throws Exception 
470
     */
471
    public void testFindBrokenOriginal() throws Exception {
472
        FileSystem fs = FileUtil.createMemoryFileSystem();
473
        FileObject orig = FileUtil.createData(fs.getRoot(), "path/to/orig");
474
        FileObject shadow = FileUtil.createData(fs.getRoot(), "link.shadow");
475
        try {
476
            DataShadow.findOriginal(shadow);
477
            fail("IOException should be thrown on malformed shadow");
478
        } catch (IOException ex) {
479
            // this is oK
480
        }
481
    }
440
}
482
}

Return to bug 222204