KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > Sample60M7ProblemWithGetDataObjectTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.loaders;
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyVetoException JavaDoc;
23 import java.beans.VetoableChangeListener JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import org.openide.NotifyDescriptor;
27 import org.openide.cookies.EditorCookie;
28 import org.openide.filesystems.*;
29 import org.openide.nodes.Node;
30 import org.openide.text.DataEditorSupport;
31 import org.openide.util.Lookup;
32 import java.io.IOException JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import javax.swing.text.Document JavaDoc;
35 import org.netbeans.junit.*;
36 import org.openide.cookies.OpenCookie;
37 import org.openide.nodes.Children;
38 import org.openide.nodes.CookieSet;
39 import org.openide.util.NbBundle;
40 import org.openide.util.lookup.AbstractLookup;
41 import org.openide.util.lookup.InstanceContent;
42
43
44 /** Simulates the deadlock from issue 60917
45  * @author Jaroslav Tulach
46  */

47 public class Sample60M7ProblemWithGetDataObjectTest extends NbTestCase {
48     
49     public Sample60M7ProblemWithGetDataObjectTest(String JavaDoc name) {
50         super(name);
51     }
52     
53     
54     protected void setUp() throws Exception JavaDoc {
55         System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
56         assertEquals(Lkp.class, Lookup.getDefault().getClass());
57     }
58     
59     public void testHasDataObjectInItsLookup() throws Exception JavaDoc {
60         FileObject sample = FileUtil.createData(FileUtil.createMemoryFileSystem().getRoot(), "sample/S.sample");
61         DataObject obj = DataObject.find(sample);
62         assertEquals(Sample60M6DataLoader.class, obj.getLoader().getClass());
63         
64         assertEquals("Object is in its own node's lookup", obj, obj.getNodeDelegate().getLookup().lookup(DataObject.class));
65         assertEquals("Object is in its own lookup", obj, obj.getLookup().lookup(DataObject.class));
66         assertEquals("Object is own node's cookie", obj, obj.getNodeDelegate().getCookie(DataObject.class));
67         assertEquals("Object is own cookie", obj, obj.getCookie(DataObject.class));
68     }
69     
70     static class Sample60M6DataObject extends MultiDataObject
71     implements Lookup.Provider {
72
73         public Sample60M6DataObject(FileObject pf, Sample60M6DataLoader loader) throws DataObjectExistsException, IOException JavaDoc {
74             super(pf, loader);
75             CookieSet cookies = getCookieSet();
76             cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
77         }
78
79         protected Node createNodeDelegate() {
80             return new Sample60M6DataNode(this, getLookup());
81         }
82
83         public Lookup getLookup() {
84             return getCookieSet().getLookup();
85         }
86     }
87
88     public static class Sample60M6DataLoader extends UniFileLoader {
89
90         public static final String JavaDoc REQUIRED_MIME = "text/x-sample";
91
92         private static final long serialVersionUID = 1L;
93
94         public Sample60M6DataLoader() {
95             super("org.openide.loaders.Sample60M6DataObject");
96         }
97
98         protected String JavaDoc defaultDisplayName() {
99             return NbBundle.getMessage(Sample60M6DataLoader.class, "LBL_Sample60M6_loader_name");
100         }
101
102         protected void initialize() {
103             super.initialize();
104             getExtensions().addExtension("sample");
105         }
106
107         protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException JavaDoc {
108             return new Sample60M6DataObject(primaryFile, this);
109         }
110
111         protected String JavaDoc actionsContext() {
112             return "Loaders/" + REQUIRED_MIME + "/Actions";
113         }
114
115     }
116     static class Sample60M6DataNode extends DataNode {
117         public Sample60M6DataNode(Sample60M6DataObject obj) {
118             super(obj, Children.LEAF);
119             // setIconBaseWithExtension(IMAGE_ICON_BASE);
120
}
121         Sample60M6DataNode(Sample60M6DataObject obj, Lookup lookup) {
122             super(obj, Children.LEAF, lookup);
123             // setIconBaseWithExtension(IMAGE_ICON_BASE);
124
}
125
126         // /** Creates a property sheet. */
127
// protected Sheet createSheet() {
128
// Sheet s = super.createSheet();
129
// Sheet.Set ss = s.get(Sheet.PROPERTIES);
130
// if (ss == null) {
131
// ss = Sheet.createPropertiesSet();
132
// s.put(ss);
133
// }
134
// // TODO add some relevant properties: ss.put(...)
135
// return s;
136
// }
137

138     }
139     
140     public static final class Lkp extends AbstractLookup {
141         public Lkp() {
142             this(new InstanceContent());
143         }
144         private Lkp(InstanceContent ic) {
145             super(ic);
146             ic.add(Sample60M6DataLoader.getLoader(Sample60M6DataLoader.class));
147         }
148     }
149 }
150
Popular Tags