# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /doma/jarda/netbeans-src/openide/loaders # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/org/openide/loaders/DataShadow.java *** /doma/jarda/netbeans-src/openide/loaders/src/org/openide/loaders/DataShadow.java Base (1.25) --- /doma/jarda/netbeans-src/openide/loaders/src/org/openide/loaders/DataShadow.java Locally Modified (Based On 1.25) *************** *** 57,67 **** --- 57,70 ---- import org.openide.nodes.PropertySupport; import org.openide.nodes.Sheet; import org.openide.util.HelpCtx; + import org.openide.util.Lookup; import org.openide.util.Mutex; import org.openide.util.MutexException; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.datatransfer.ExTransferable; + import org.openide.util.lookup.Lookups; + import org.openide.util.lookup.ProxyLookup; import org.openide.xml.XMLUtil; /** Default implementation of a shortcut to another data object. *************** *** 720,726 **** /** Initializes it */ private ShadowNode (DataShadow shadow, Node node) { ! super (node); this.obj = shadow; synchronized (this.obj.nodes) { this.obj.nodes.add (this); --- 723,729 ---- /** Initializes it */ private ShadowNode (DataShadow shadow, Node node) { ! super (node, new Children(node), new ProxyLookup(new Lookup[] { Lookups.singleton(shadow), node.getLookup() })); this.obj = shadow; synchronized (this.obj.nodes) { this.obj.nodes.add (this); *************** *** 913,919 **** * method is returned. * * @return the cookie or null - */ public Node.Cookie getCookie (Class cl) { Node.Cookie c = obj.getCookie (cl); if (c != null) { --- 916,921 ---- Index: test/unit/src/org/openide/loaders/DataShadowLookupTest.java *** /doma/jarda/netbeans-src/openide/loaders/test/unit/src/org/openide/loaders/DataShadowLookupTest.java No Base Revision --- /doma/jarda/netbeans-src/openide/loaders/test/unit/src/org/openide/loaders/DataShadowLookupTest.java Locally New *************** *** 1,0 **** --- 1,143 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.openide.loaders; + + import java.io.File; + import java.io.IOException; + import java.lang.ref.WeakReference; + import java.net.URI; + import java.net.URL; + import java.util.Enumeration; + import java.util.logging.Level; + import java.util.logging.Logger; + import junit.framework.AssertionFailedError; + import org.netbeans.junit.MockServices; + import org.netbeans.junit.NbTestCase; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileStateInvalidException; + import org.openide.filesystems.FileSystem; + import org.openide.filesystems.FileUtil; + import org.openide.filesystems.LocalFileSystem; + import org.openide.filesystems.Repository; + import org.openide.nodes.Children; + import org.openide.nodes.Node; + import org.openide.util.Enumerations; + import org.openide.util.Utilities; + import org.openide.util.lookup.Lookups; + + /** Test things about shadows and broken shadows, etc. + * @author Jaroslav Tulach + */ + public class DataShadowLookupTest extends NbTestCase + implements java.net.URLStreamHandlerFactory { + /** original object */ + private DataObject original; + /** folder to work with */ + private DataFolder folder; + /** fs we work on */ + private FileSystem lfs; + + private Logger err; + + static { + // to handle nbfs urls... + // java.net.URL.setURLStreamHandlerFactory (new DataShadowLookupTest(null)); + MockServices.setServices(new Class[] { Pool.class }); + } + + public DataShadowLookupTest (String name) { + super(name); + } + + protected Level logLevel() { + return Level.INFO; + } + + protected void setUp() throws Exception { + + lfs = Repository.getDefault ().getDefaultFileSystem (); + + FileObject[] delete = lfs.getRoot().getChildren(); + for (int i = 0; i < delete.length; i++) { + delete[i].delete(); + } + + + FileObject fo = FileUtil.createData (lfs.getRoot (), getName () + "/folder/original.string"); + assertNotNull(fo); + original = DataObject.find (fo); + assertFalse ("Just to be sure that this is not shadow", original instanceof DataShadow); + assertEquals ("It is the right class", StringObject.class, original.getClass ()); + fo = FileUtil.createFolder (lfs.getRoot (), getName () + "/modify"); + assertNotNull(fo); + assertTrue (fo.isFolder ()); + folder = DataFolder.findFolder (fo); + + Repository.getDefault ().addFileSystem (lfs); + + err = Logger.getLogger(getName()); + } + + public java.net.URLStreamHandler createURLStreamHandler(String protocol) { + if (protocol.equals ("nbfs")) { + return FileUtil.nbfsURLStreamHandler (); + } + return null; + } + + public void testStringIsInLookupOfDataShadow() throws Exception { + DataShadow shade = original.createShadow(folder); + + { + String s = (String)original.getNodeDelegate().getLookup().lookup(String.class); + assertNotNull("String is in the original's lookup", s); + } + + assertSame(shade.getOriginal(), original); + String s = (String)shade.getNodeDelegate().getLookup().lookup(String.class); + assertNotNull("String is in the lookup", s); + assertEquals("It is the name of the original", original.getName(), s); + } + + public static final class Pool extends DataLoaderPool { + protected Enumeration loaders() { + return Enumerations.singleton(StringLoader.findObject(StringLoader.class, true)); + } + + } + + private static final class StringLoader extends UniFileLoader { + public StringLoader() { + super("org.openide.loaders.StringObject"); + getExtensions().addExtension("string"); + } + + protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + return new StringObject(this, primaryFile); + } + + } // end of StringLoader + + private static final class StringObject extends MultiDataObject { + public StringObject(StringLoader l, FileObject fo) throws DataObjectExistsException { + super(fo, l); + } + + protected Node createNodeDelegate() { + return new DataNode(this, Children.LEAF, Lookups.singleton(getName())); + } + } // end of StringObject + + + } Index: X.diff *** /doma/jarda/netbeans-src/openide/loaders/X.diff No Base Revision --- /doma/jarda/netbeans-src/openide/loaders/X.diff Locally New Index: test/unit/src/org/openide/loaders/DataShadowBrokenSlownessTest.java *** /doma/jarda/netbeans-src/openide/loaders/test/unit/src/org/openide/loaders/DataShadowBrokenSlownessTest.java Base (1.4) --- /doma/jarda/netbeans-src/openide/loaders/test/unit/src/org/openide/loaders/DataShadowBrokenSlownessTest.java Locally Modified (Based On 1.4) *************** *** 76,82 **** ListIterator it = brokenShadows.listIterator (); while (it.hasNext ()) { DataObject obj = (DataObject)it.next (); ! assertFalse ("Is not valid", obj.isValid ()); assertTrue ("Used to be shadow", obj instanceof DataShadow); DataObject newObj = DataObject.find (obj.getPrimaryFile ()); assertTrue ("They are different", newObj != obj); --- 76,82 ---- ListIterator it = brokenShadows.listIterator (); while (it.hasNext ()) { DataObject obj = (DataObject)it.next (); ! assertFalse ("Is not valid: " + obj, obj.isValid ()); assertTrue ("Used to be shadow", obj instanceof DataShadow); DataObject newObj = DataObject.find (obj.getPrimaryFile ()); assertTrue ("They are different", newObj != obj);