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 175750
Collapse All | Expand All

(-)a/openide.loaders/apichanges.xml (+16 lines)
Lines 106-111 Link Here
106
<!-- ACTUAL CHANGES BEGIN HERE: -->
106
<!-- ACTUAL CHANGES BEGIN HERE: -->
107
107
108
  <changes>
108
  <changes>
109
     <change id="XMLDataObject.subclass">
110
        <api name="loaders"/>
111
        <summary>New constructor of XMLDataObject</summary>
112
        <version major="7" minor="10"/>
113
        <date day="9" month="11" year="2009"/>
114
        <author login="jtulach"/>
115
        <compatibility binary="compatible" source="compatible" addition="yes"
116
            deletion="no" deprecation="no" modification="no" semantic="compatible"/>
117
        <description>
118
            <p>
119
                New constructor for subclasses of <code>XMLDataObject</code>.
120
            </p>
121
        </description>
122
        <class package="org.openide.loaders" name="XMLDataObject"/>
123
        <issue number="175750"/>
124
    </change>
109
     <change id="DataEditorSupport.annotateName">
125
     <change id="DataEditorSupport.annotateName">
110
        <api name="editor"/>
126
        <api name="editor"/>
111
        <summary>Added <code>annotateName</code> and <code>toolTip</code> to <code>DataEditorSupport</code></summary>
127
        <summary>Added <code>annotateName</code> and <code>toolTip</code> to <code>DataEditorSupport</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.9
3
OpenIDE-Module-Specification-Version: 7.10
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Recommends: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Recommends: org.netbeans.modules.templates.v1_0
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.loaders/src/org/openide/loaders/XMLDataObject.java (-8 / +28 lines)
Lines 169-198 Link Here
169
     *
169
     *
170
     * @param fo the primary file object, never <code>null</code>
170
     * @param fo the primary file object, never <code>null</code>
171
     * @param loader loader of this data object, never <code>null</code>
171
     * @param loader loader of this data object, never <code>null</code>
172
     *
173
     */
172
     */
174
    public XMLDataObject (FileObject fo, MultiFileLoader loader)
173
    public XMLDataObject (FileObject fo, MultiFileLoader loader)
175
    throws DataObjectExistsException {
174
    throws DataObjectExistsException {
175
        this(fo, loader, true);
176
    }
177
178
    /**
179
     * Constructs XMLDataObject without any registered cookies (for editor,
180
     * open, etc.). Useful for subclasses.
181
     *
182
     * @param fo the primary file object, never <code>null</code>
183
     * @param loader loader of this data object, never <code>null</code>
184
     * @param registerEditor call with false to skip registrations of various
185
     *   editor related cookies
186
     * @since 7.10
187
     */
188
    protected XMLDataObject (FileObject fo, MultiFileLoader loader, boolean registerEditor)
189
    throws DataObjectExistsException {
176
        super (fo, loader);
190
        super (fo, loader);
177
        
191
        
178
        fo.addFileChangeListener (FileUtil.weakFileChangeListener (getIP (), fo));
192
        fo.addFileChangeListener (FileUtil.weakFileChangeListener (getIP (), fo));
179
193
180
        status = STATUS_NOT;
194
        status = STATUS_NOT;
181
195
196
        if (registerEditor) {
197
            registerEditor();
198
        }
199
    }
200
201
    private void registerEditor() {
182
        // register provided cookies
202
        // register provided cookies
183
        // EditorCookie must be for back compatability consulted with subclasses
203
        // EditorCookie must be for back compatability consulted with subclasses
184
        //
204
        //
185
        // In new model subclasses should directly provide its CookieSet.Factory that
205
        // In new model subclasses should directly provide its CookieSet.Factory that
186
        // uses last prevails order instead of old CookieSet first prevails order.
206
        // uses last prevails order instead of old CookieSet first prevails order.
187
        // It completely prevails over this factory :-)
207
        // It completely prevails over this factory :-)
188
        
208
189
        CookieSet.Factory factory = new CookieSet.Factory() {
209
        CookieSet.Factory factory = new CookieSet.Factory() {
190
            public <T extends Node.Cookie> T createCookie(Class<T> klass) {
210
            public <T extends Node.Cookie> T createCookie(Class<T> klass) {
191
                if (klass.isAssignableFrom(EditorCookie.class)
211
                if (klass.isAssignableFrom(EditorCookie.class)
192
                   || klass.isAssignableFrom(OpenCookie.class) 
212
                   || klass.isAssignableFrom(OpenCookie.class)
193
                   || klass.isAssignableFrom(CloseCookie.class) 
213
                   || klass.isAssignableFrom(CloseCookie.class)
194
                   || klass.isAssignableFrom(PrintCookie.class) ) {
214
                   || klass.isAssignableFrom(PrintCookie.class) ) {
195
                
215
196
                    if (editor == null) editor = createEditorCookie();  // the first pass
216
                    if (editor == null) editor = createEditorCookie();  // the first pass
197
                    if (editor == null) return null;                    //??? gc unfriendly
217
                    if (editor == null) return null;                    //??? gc unfriendly
198
218
Lines 202-216 Link Here
202
                }
222
                }
203
            }
223
            }
204
        };
224
        };
205
                
225
206
        CookieSet cookies = getCookieSet();
226
        CookieSet cookies = getCookieSet();
207
        // EditorCookie.class must be synchronized with 
227
        // EditorCookie.class must be synchronized with
208
        // XMLEditor.Env->findCloneableOpenSupport
228
        // XMLEditor.Env->findCloneableOpenSupport
209
        cookies.add(EditorCookie.class, factory);
229
        cookies.add(EditorCookie.class, factory);
210
        cookies.add(OpenCookie.class, factory);
230
        cookies.add(OpenCookie.class, factory);
211
        cookies.add(CloseCookie.class, factory);
231
        cookies.add(CloseCookie.class, factory);
212
        cookies.add(PrintCookie.class, factory);
232
        cookies.add(PrintCookie.class, factory);
213
        
233
214
        // set info for this file
234
        // set info for this file
215
        //getIP ().resolveInfo ();        #16045
235
        //getIP ().resolveInfo ();        #16045
216
        cookies.assign( SaveAsCapable.class, new SaveAsCapable() {
236
        cookies.assign( SaveAsCapable.class, new SaveAsCapable() {
(-)9136c35a2fd8 (+149 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.openide.loaders;
43
44
import java.util.Enumeration;
45
import org.openide.filesystems.*;
46
import java.io.*;
47
import java.lang.ref.Reference;
48
import java.lang.ref.WeakReference;
49
import java.security.Permission;
50
import java.util.Arrays;
51
import java.util.Collection;
52
import java.util.Collections;
53
import java.util.HashMap;
54
import java.util.Map;
55
import java.util.Set;
56
import java.util.TreeSet;
57
import java.util.logging.Level;
58
import junit.framework.Assert;
59
import org.netbeans.junit.Log;
60
import org.netbeans.junit.MockServices;
61
import org.netbeans.junit.RandomlyFails;
62
import org.openide.cookies.*;
63
import org.openide.loaders.MultiDataObject.Entry;
64
import org.openide.nodes.Node;
65
import org.openide.util.Enumerations;
66
import org.openide.util.RequestProcessor;
67
import org.openide.xml.XMLUtil;
68
import org.xml.sax.InputSource;
69
import org.xml.sax.SAXParseException;
70
71
/**
72
 *
73
 * @author  Jaroslav Tulach
74
 */
75
public class XMLDataObjectSubclassTest extends org.netbeans.junit.NbTestCase {
76
    private FileObject data;
77
    private CharSequence log;
78
79
    public XMLDataObjectSubclassTest (String name) {
80
        super (name);
81
    }
82
83
    @Override
84
    protected void setUp () throws Exception {
85
        clearWorkDir();
86
        MockServices.setServices(Pool.class);
87
        
88
        log = Log.enable("org.openide.loaders", Level.WARNING);
89
        
90
        super.setUp ();
91
        String fsstruct [] = new String [] {
92
        };
93
        FileSystem fs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
94
        data = FileUtil.createData (
95
            fs.getRoot (),
96
            "kuk/test/my.xml"
97
        );
98
        FileLock lock = data.lock ();
99
        OutputStream os = data.getOutputStream (lock);
100
        PrintStream p = new PrintStream (os);
101
        
102
        p.println ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
103
        p.println ("<root>");
104
        p.println ("</root>");
105
        
106
        p.close ();
107
        lock.releaseLock ();
108
109
    }
110
111
    public void testCheckNoCookies() throws Exception {
112
        DataObject obj = DataObject.find(data);
113
        assertEquals("Correct obj type", MyXMLObject.class, obj.getClass());
114
115
        assertNull("No open cookie", obj.getLookup().lookup(OpenCookie.class));
116
        assertNull("No edit cookie", obj.getLookup().lookup(EditCookie.class));
117
        assertNull("No print cookie", obj.getLookup().lookup(PrintCookie.class));
118
        assertNull("No close cookie", obj.getLookup().lookup(CloseCookie.class));
119
    }
120
121
    public static final class Pool extends DataLoaderPool {
122
123
        @Override
124
        protected Enumeration<? extends DataLoader> loaders() {
125
            return Enumerations.singleton(DataLoader.getLoader(MyXMLLoader.class));
126
        }
127
    }
128
129
    public static final class MyXMLLoader extends UniFileLoader {
130
131
        public MyXMLLoader() {
132
            super(MyXMLObject.class.getName());
133
            getExtensions().addExtension("xml");
134
        }
135
136
        @Override
137
        protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
138
            return new MyXMLObject(primaryFile, this);
139
        }
140
    }
141
142
    public static final class MyXMLObject extends XMLDataObject {
143
144
        public MyXMLObject(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
145
            super(fo, loader, false);
146
        }
147
148
    }
149
}
(-)a/openide.nodes/test/unit/src/org/openide/nodes/CookieSetTest.java (+33 lines)
Lines 90-95 Link Here
90
    }
90
    }
91
    static interface Cook extends Node.Cookie {
91
    static interface Cook extends Node.Cookie {
92
    }
92
    }
93
    public void testInconsistencyWhenDoubleCookie175750() {
94
        CookieSet cs = CookieSet.createGeneric(null);
95
96
97
        class Factory implements CookieSet.Factory {
98
            public <T extends Cookie> T createCookie(Class<T> klass) {
99
                if (klass == Cook.class || klass == Hook.class) {
100
                    return klass.cast(new Hook() { });
101
                }
102
                return null;
103
            }
104
        }
105
        final Factory f = new Factory();
106
        cs.add(new Class[] { Cook.class, Hook.class }, f);
107
108
        Cook one = cs.getCookie(Hook.class);
109
        Cook two = cs.getCookie(Cook.class);
110
        Cook three = cs.getLookup().lookup(Cook.class);
111
        Cook four = cs.getLookup().lookup(Hook.class);
112
113
        assertSame("One and two", one, two);
114
        assertSame("3 and two", three, two);
115
        assertSame("One and 4", one, four);
116
117
        cs.remove(new Class[] { Hook.class, Cook.class }, f);
118
119
        assertNull("No cookie now ", cs.getCookie(Cook.class));
120
        assertNull("No lkp now ", cs.getLookup().lookup(Cook.class));
121
        assertNull("No h cookie now ", cs.getCookie(Hook.class));
122
        assertNull("No h lkp now ", cs.getLookup().lookup(Hook.class));
123
    }
124
    static interface Hook extends Cook {
125
    }
93
126
94
    
127
    
95
    public void testAddRemove () throws Exception {
128
    public void testAddRemove () throws Exception {
(-)a/xml/nbproject/project.xml (-1 / +1 lines)
Lines 206-212 Link Here
206
                    <build-prerequisite/>
206
                    <build-prerequisite/>
207
                    <compile-dependency/>
207
                    <compile-dependency/>
208
                    <run-dependency>
208
                    <run-dependency>
209
                        <specification-version>7.0</specification-version>
209
                        <specification-version>7.10</specification-version>
210
                    </run-dependency>
210
                    </run-dependency>
211
                </dependency>
211
                </dependency>
212
                <dependency>
212
                <dependency>
(-)a/xml/src/org/netbeans/modules/xml/XMLDataObject.java (-1 / +1 lines)
Lines 84-90 Link Here
84
     * @param loader loader of this data object
84
     * @param loader loader of this data object
85
     */
85
     */
86
    public XMLDataObject (final FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
86
    public XMLDataObject (final FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
87
        super (fo, loader);
87
        super (fo, loader, false);
88
        
88
        
89
        CookieSet set = getCookieSet();
89
        CookieSet set = getCookieSet();
90
        set.add (cookieManager = new DataObjectCookieManager (this, set));
90
        set.add (cookieManager = new DataObjectCookieManager (this, set));
(-)a/xml/test/unit/src/org/netbeans/modules/xml/XMLDataObjectTest.java (-3 / +26 lines)
Lines 40-59 Link Here
40
 */
40
 */
41
package org.netbeans.modules.xml;
41
package org.netbeans.modules.xml;
42
42
43
import java.io.IOException;
43
import java.util.Set;
44
import org.netbeans.junit.NbTestCase;
44
import org.netbeans.junit.NbTestCase;
45
import org.openide.cookies.EditCookie;
45
import org.openide.cookies.EditCookie;
46
import org.openide.cookies.OpenCookie;
46
import org.openide.filesystems.FileObject;
47
import org.openide.filesystems.FileObject;
47
import org.openide.filesystems.FileUtil;
48
import org.openide.filesystems.FileUtil;
48
import org.openide.loaders.DataObject;
49
import org.openide.loaders.DataObject;
49
import org.openide.loaders.DataObjectNotFoundException;
50
import org.openide.util.test.MockLookup;
50
import org.openide.util.test.MockLookup;
51
import org.openide.windows.WindowManager;
51
52
52
/**
53
/**
53
 *
54
 *
54
 * @author Petr Hejl
55
 * @author Petr Hejl
55
 */
56
 */
56
public class XMLDataObjectTest extends NbTestCase {
57
public class XMLDataObjectTest extends NbTestCase {
58
    static {
59
        System.setProperty ("org.openide.util.Lookup", "org.openide.text.DataEditorSupportTest$Lkp");
60
        System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false");
61
    }
57
62
58
    public XMLDataObjectTest(String name) {
63
    public XMLDataObjectTest(String name) {
59
        super(name);
64
        super(name);
Lines 64-70 Link Here
64
        MockLookup.init();
69
        MockLookup.init();
65
    }
70
    }
66
71
67
    public void testLookup() throws DataObjectNotFoundException, IOException {
72
    public void testLookup() throws Exception {
68
        MockLookup.setInstances(XMLDataLoader.getLoader(XMLDataLoader.class));
73
        MockLookup.setInstances(XMLDataLoader.getLoader(XMLDataLoader.class));
69
74
70
        FileObject document = FileUtil.toFileObject(
75
        FileObject document = FileUtil.toFileObject(
Lines 83-87 Link Here
83
88
84
        EditCookie lkp = dataObject.getLookup().lookup(EditCookie.class);
89
        EditCookie lkp = dataObject.getLookup().lookup(EditCookie.class);
85
        assertEquals("Cookies are the same", ec, lkp);
90
        assertEquals("Cookies are the same", ec, lkp);
91
92
        OpenCookie lkp2 = dataObject.getLookup().lookup(OpenCookie.class);
93
94
        lkp.edit();
95
        lkp2.open();
96
97
        Set<?> all = null;
98
        for (int i = 0; i < 10; i++) {
99
            Thread.sleep(1000);
100
            all = WindowManager.getDefault().getRegistry().getOpened();
101
            if (all.size() > 0) {
102
                break;
103
            }
104
        }
105
106
        assertEquals("There is just one TC: " + all, 1, all.size());
107
108
        assertEquals("Cookies are the same", lkp, lkp2);
86
    }
109
    }
87
}
110
}

Return to bug 175750