KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > text > Deadlock47515Test


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
21 package org.openide.text;
22
23
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import javax.swing.text.*;
28 import javax.swing.text.BadLocationException JavaDoc;
29 import javax.swing.text.Document JavaDoc;
30 import javax.swing.text.Position JavaDoc;
31 import javax.swing.text.StyledDocument JavaDoc;
32
33 import junit.textui.TestRunner;
34
35 import org.netbeans.junit.NbTestCase;
36 import org.netbeans.junit.NbTestSuite;
37
38 import org.openide.text.CloneableEditorSupport;
39 import org.openide.text.FilterDocument;
40 import org.openide.text.NbDocument;
41 import org.openide.util.RequestProcessor;
42
43 /**
44  * Try opening a document while holding private lock that may be needed
45  * for resolving messageName
46  *
47  * @author Petr Nejedly
48  */

49 public class Deadlock47515Test extends NbTestCase implements CloneableEditorSupport.Env {
50     private Object JavaDoc myPrivateLock = new Object JavaDoc();
51     
52     /** the support to work with */
53     private CES support;
54     // Env variables
55
private String JavaDoc content = "Hello";
56     private boolean valid = true;
57     private boolean modified = false;
58     /** if not null contains message why this document cannot be modified */
59     private java.util.Date JavaDoc date = new java.util.Date JavaDoc ();
60     private java.util.List JavaDoc/*<java.beans.PropertyChangeListener>*/ propL = new java.util.ArrayList JavaDoc ();
61     private java.beans.VetoableChangeListener JavaDoc vetoL;
62     
63     /** Creates new TextTest */
64     public Deadlock47515Test(String JavaDoc s) {
65         super(s);
66     }
67     
68     public static void main(String JavaDoc[] args) {
69         TestRunner.run(new NbTestSuite(Deadlock47515Test.class));
70     }
71
72     protected void setUp () {
73         support = new CES (this, org.openide.util.Lookup.EMPTY);
74     }
75         
76     public void testDeadlock47515() throws Exception JavaDoc {
77         synchronized(myPrivateLock) {
78             try {
79                 support.openDocument();
80             } catch (IOException JavaDoc ioe) {
81                 // OK
82
}
83         }
84     }
85     
86
87     //
88
// Implementation of the CloneableEditorSupport.Env
89
//
90

91     public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
92         propL.add (l);
93     }
94     public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
95         propL.remove (l);
96     }
97     
98     public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc l) {
99         assertNull ("This is the first veto listener", vetoL);
100         vetoL = l;
101     }
102     public void removeVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc l) {
103         assertEquals ("Removing the right veto one", vetoL, l);
104         vetoL = null;
105     }
106     
107     public org.openide.windows.CloneableOpenSupport findCloneableOpenSupport() {
108         return support;
109     }
110     
111     public String JavaDoc getMimeType() {
112         return "text/plain";
113     }
114     
115     public java.util.Date JavaDoc getTime() {
116         return date;
117     }
118     
119     public java.io.InputStream JavaDoc inputStream() throws java.io.IOException JavaDoc {
120         throw new IOException JavaDoc("Can't load");
121     }
122     public java.io.OutputStream JavaDoc outputStream() throws java.io.IOException JavaDoc {
123         return new ByteArrayOutputStream JavaDoc();
124     }
125     
126     public boolean isValid() {
127         return valid;
128     }
129     
130     public boolean isModified() {
131         return modified;
132     }
133
134     public void markModified() throws java.io.IOException JavaDoc {
135         modified = true;
136     }
137     
138     public void unmarkModified() {
139         modified = false;
140     }
141
142     /** Implementation of the CES */
143     private final class CES extends CloneableEditorSupport {
144         
145         public CES (Env env, org.openide.util.Lookup l) {
146             super (env, l);
147         }
148         
149         protected String JavaDoc messageName() {
150             synchronized(myPrivateLock) {
151                 return "Name";
152             }
153         }
154         
155         protected String JavaDoc messageOpened() {
156                 return "Opened";
157         }
158         
159         protected String JavaDoc messageOpening() {
160             return "Opening";
161         }
162         
163         protected String JavaDoc messageSave() {
164             return "Save";
165         }
166         
167         protected String JavaDoc messageToolTip() {
168             return "ToolTip";
169         }
170         
171         
172     } // end of CES
173
}
174
Popular Tags