1 19 20 package org.openide.loaders; 21 22 import org.openide.filesystems.*; 23 import org.openide.filesystems.FileSystem; import org.openide.loaders.*; 25 import org.openide.cookies.*; 26 import org.openide.util.*; 27 28 import java.beans.*; 29 import java.io.*; 30 import java.util.*; 31 32 import org.netbeans.junit.*; 33 34 38 public class InstanceDataObjecIssue47707Test extends NbTestCase { 39 40 private DataObject inst; 41 42 private FileSystem lfs; 43 44 45 public InstanceDataObjecIssue47707Test(String name) { 46 super (name); 47 } 48 49 51 protected void setUp () throws Exception { 52 System.setProperty ("org.openide.util.Lookup", "org.openide.loaders.InstanceDataObjecIssue47707Test$Lkp"); 53 54 String fsstruct [] = new String [] { 55 "A.settings", 56 }; 57 58 TestUtilHid.destroyLocalFileSystem (getName()); 59 lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct); 60 61 FileObject bb = lfs.findResource("A.settings"); 62 63 inst = DataObject.find (bb); 64 } 65 66 public void testGetCookieCanBeCalledTwice () throws Exception { 67 Object cookie = inst.getCookie (org.openide.cookies.InstanceCookie.class); 68 69 assertNotNull ("There is at least data object", cookie); 70 assertEquals ("Of right type", LkpForDO.class, cookie.getClass ()); 71 72 } 73 74 public static final class Lkp extends org.openide.util.lookup.AbstractLookup 75 implements Environment.Provider { 76 public Lkp () { 77 this (new org.openide.util.lookup.InstanceContent ()); 78 } 79 80 private Lkp (org.openide.util.lookup.InstanceContent ic) { 81 super (ic); 82 ic.add (this); 83 } 84 85 public org.openide.util.Lookup getEnvironment (DataObject obj) { 86 return new LkpForDO (new org.openide.util.lookup.InstanceContent (), obj); 87 } 88 } 90 public static final class LkpForDO extends org.openide.util.lookup.AbstractLookup 91 implements org.openide.cookies.InstanceCookie, Runnable { 92 private boolean triedToDeadlock; 93 private DataObject obj; 94 95 private LkpForDO (org.openide.util.lookup.InstanceContent ic, DataObject obj) { 96 super (ic); 97 ic.add (this); 98 this.obj = obj; 99 } 100 101 public void run () { 102 Object o = obj.getCookie (InstanceCookie.class); 104 assertNotNull ("Cookie is there", o); 105 } 106 107 protected void beforeLookup(Template template) { 108 if (!triedToDeadlock) { 109 triedToDeadlock = true; 110 org.openide.util.RequestProcessor.getDefault ().post (this).waitFinished (); 111 } 112 } 113 114 115 public String instanceName () { 116 return getClass ().getName (); 117 } 118 119 public Class instanceClass () 120 throws java.io.IOException , ClassNotFoundException { 121 return getClass (); 122 } 123 124 public Object instanceCreate () 125 throws java.io.IOException , ClassNotFoundException { 126 return this; 127 } 128 129 public String toString() { 130 return getClass().getName(); 131 } 132 } 134 } 135 | Popular Tags |