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

(-)core/registry/build.xml (-1 / +2 lines)
Lines 32-42 Link Here
32
      <pathelement location="../../openide/loaders/netbeans/lib/openide-loaders.jar"/>
32
      <pathelement location="../../openide/loaders/netbeans/lib/openide-loaders.jar"/>
33
      <pathelement location="../netbeans/lib/core.jar"/>
33
      <pathelement location="../netbeans/lib/core.jar"/>
34
      <pathelement location="../../openide/registry/netbeans/modules/org-netbeans-modules-registry.jar"/>
34
      <pathelement location="../../openide/registry/netbeans/modules/org-netbeans-modules-registry.jar"/>
35
      <pathelement location="../../openide/convertor/netbeans/modules/org-netbeans-modules-convertor.jar"/>
35
    </path>
36
    </path>
36
  </target>
37
  </target>
37
38
38
  <target name="compile" depends="init">
39
  <target name="compile" depends="init">
39
    <javac srcdir="src" destdir="src" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}">
40
    <javac srcdir="src" destdir="src" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" source="1.4">
40
      <classpath refid="cp"/>
41
      <classpath refid="cp"/>
41
    </javac>
42
    </javac>
42
  </target>
43
  </target>
(-)core/registry/manifest.mf (-2 / +3 lines)
Lines 1-8 Link Here
1
Manifest-Version: 1.0
1
OpenIDE-Module: org.netbeans.core.registry/1
2
OpenIDE-Module: org.netbeans.core.registry/1
2
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/registry/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/registry/resources/Bundle.properties
3
OpenIDE-Module-Specification-Version: 1.4
4
OpenIDE-Module-Specification-Version: 1.5
4
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
5
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
5
OpenIDE-Module-IDE-Dependencies: IDE/1 > 3.17
6
OpenIDE-Module-IDE-Dependencies: IDE/1 > 3.17
6
OpenIDE-Module-Public-Packages: org.netbeans.api.registry.fs.*
7
OpenIDE-Module-Public-Packages: org.netbeans.api.registry.fs.*
7
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.registry/1 > 1.5, org.netbeans.core/1 > 1.15
8
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.registry/1 > 1.5, org.netbeans.core/1 > 1.15, org.netbeans.modules.convertor/1 > 1.1
8
9
(-)core/registry/api/apichanges.xml (+17 lines)
Lines 75-80 Link Here
75
    <!-- ACTUAL CHANGES BEGIN HERE: -->
75
    <!-- ACTUAL CHANGES BEGIN HERE: -->
76
76
77
    <changes>
77
    <changes>
78
    
79
        <change id="use-convertor">
80
            <api name="registry"/>
81
            <summary>Enable use of Convertor SPI</summary>
82
            <version major="1" minor="1.5"/>
83
            <date day="26" month="9" year="2003"/>
84
            <author login="jglick"/>
85
            <compatibility addition="yes"/>
86
            <description>
87
                You may now use the Convertor SPI with the Registry over Filesystems.
88
                If you have a (layer) folder being used as a context, simply create a
89
                file <samp>foo.xml</samp> to create an object binding named <samp>foo</samp>.
90
                It should be a well-formed XML file whose root (document) element is
91
                namespace-qualified and registered using the Convertor SPI.
92
            </description>
93
            <issue number="36297"/>
94
        </change>
78
95
79
		<change >
96
		<change >
80
			<api name="registry"/>
97
			<api name="registry"/>
(-)core/registry/src/org/netbeans/core/registry/olddsimpl/DSUtils.java (-12 / +101 lines)
Lines 13-38 Link Here
13
13
14
package org.netbeans.core.registry.olddsimpl;
14
package org.netbeans.core.registry.olddsimpl;
15
15
16
16
import java.io.IOException;
17
import java.io.OutputStream;
17
import java.util.Arrays;
18
import java.util.Arrays;
18
import java.util.Enumeration;
19
import java.util.Hashtable;
20
import java.util.Iterator;
19
import java.util.Iterator;
21
import java.util.List;
20
import java.util.List;
21
import org.w3c.dom.Document;
22
import org.w3c.dom.Element;
23
import org.xml.sax.SAXException;
24
22
import org.netbeans.api.registry.ContextException;
25
import org.netbeans.api.registry.ContextException;
23
import org.netbeans.core.registry.ContextImpl;
24
import org.netbeans.spi.registry.BasicContext;
26
import org.netbeans.spi.registry.BasicContext;
25
import org.netbeans.spi.registry.SpiUtils;
27
import org.netbeans.spi.registry.SpiUtils;
26
import org.openide.ErrorManager;
27
28
29
import org.netbeans.core.registry.ContextImpl;
30
31
import org.openide.ErrorManager;
28
import org.openide.cookies.InstanceCookie;
32
import org.openide.cookies.InstanceCookie;
29
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.*;
30
import org.openide.loaders.DataObject;
34
import org.openide.loaders.*;
31
import org.openide.loaders.DataObjectNotFoundException;
32
35
36
import org.netbeans.api.convertor.ConvertorException;
37
import org.netbeans.api.convertor.Convertors;
33
38
34
/**
39
/**
35
 *
36
 * @author Peter Zavadsky
40
 * @author Peter Zavadsky
37
 */
41
 */
38
public class DSUtils {
42
public class DSUtils {
Lines 41-46 Link Here
41
    private DSUtils() {
45
    private DSUtils() {
42
    }
46
    }
43
    
47
    
48
    /**
49
     * Try to get an object binding from a file.
50
     * @param ctx the basic context being used
51
     * @param folder the folder in which to look
52
     * @param name the file name (like a binding, no ext)
53
     * @return an object bound to it, or null
54
     * @throws ContextException if the binding exists but there is a problem loading it
55
     */
44
    public static Object getObjectForFile(BasicContext ctx, FileObject folder, String name) throws ContextException {
56
    public static Object getObjectForFile(BasicContext ctx, FileObject folder, String name) throws ContextException {
45
        FileObject fo = findInstanceFile(folder, name);
57
        FileObject fo = findInstanceFile(folder, name);
46
        if (fo == null) {
58
        if (fo == null) {
Lines 70-79 Link Here
70
        return instanceCreate (obj);
82
        return instanceCreate (obj);
71
    }
83
    }
72
    
84
    
73
    public static Object instanceCreate (DataObject obj) throws ContextException {
85
    private static Object instanceCreate (DataObject obj) throws ContextException {
74
        InstanceCookie ic = (InstanceCookie)obj.getCookie (InstanceCookie.class);
86
        InstanceCookie ic = (InstanceCookie)obj.getCookie (InstanceCookie.class);
75
        if (ic == null) {
87
        if (ic == null) {
76
            return null;
88
            return instanceCreateViaConvertors(obj);
77
        }
89
        }
78
        
90
        
79
        try {
91
        try {
Lines 112-118 Link Here
112
        return null;
124
        return null;
113
    }
125
    }
114
126
115
    public static List getInstanceExtensions() {
127
    private static List getInstanceExtensions() {
116
        return Arrays.asList(new String[] {
128
        return Arrays.asList(new String[] {
117
                    "instance", "xml", "settings", "shadow", "link"}); // NOI18N
129
                    "instance", "xml", "settings", "shadow", "link"}); // NOI18N
118
    }
130
    }
Lines 164-169 Link Here
164
            }
176
            }
165
        }
177
        }
166
        return escaped.toString ();
178
        return escaped.toString ();
179
    }
180
181
    /**
182
     * Try to create an instance via the Convertors API.
183
     * @param _d a data object, which may be an XMLDataObject
184
     * @return an instance if its root element can be converted, or null if it is not a .xml file, or it has no convertor
185
     * @throws ContextException if it is a .xml file that cannot be parsed, or the convertor fails
186
     */
187
    private static Object instanceCreateViaConvertors(DataObject _d) throws ContextException {
188
        if (!(_d instanceof XMLDataObject)) {
189
            return null;
190
        }
191
        XMLDataObject d = (XMLDataObject)_d;
192
        Document doc;
193
        try {
194
            doc = d.getDocument();
195
        } catch (IOException ex) {
196
            ContextException e = SpiUtils.createContextException(null, null);
197
            ErrorManager.getDefault().annotate(e, ex);
198
            throw e;
199
        } catch (SAXException ex) {
200
            ContextException e = SpiUtils.createContextException(null, null);
201
            ErrorManager.getDefault().annotate(e, ex);
202
            throw e;
203
        }
204
        Element el = doc.getDocumentElement();
205
        assert el.getNodeName() != null;
206
        if (el.getNamespaceURI() != null && Convertors.canRead(el)) {
207
            try {
208
                return Convertors.read(el);
209
            } catch (ConvertorException ex) {
210
                ContextException e = SpiUtils.createContextException(null, null);
211
                ErrorManager.getDefault().annotate(e, ErrorManager.UNKNOWN, "From " + d.getPrimaryFile(), null, ex, null);
212
                throw e;
213
            } catch (Exception e) {
214
                assert false : e + " from " + d.getPrimaryFile();
215
                return null;
216
            }
217
        } else {
218
            return null;
219
        }
220
    }
221
    
222
    /**
223
     * Make a binding for an object to a file.
224
     * @param folder the folder to store it in
225
     * @param name the name of the binding (file basename)
226
     * @param o a structured object to store
227
     * @throws IOException if there is a problem storing it
228
     */
229
    public static void bindObjectToFile(DataFolder folder, final String name, final Object o) throws IOException {
230
        if (Convertors.canWrite(o)) {
231
            // XXX delete other kinds of bindings first? very unlikely to matter...
232
            final FileObject fileFolder = folder.getPrimaryFile();
233
            fileFolder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
234
                public void run() throws IOException {
235
                    FileObject xml = fileFolder.getFileObject(name, "xml");
236
                    if (xml == null) {
237
                        xml = fileFolder.createData(name, "xml");
238
                    }
239
                    FileLock l = xml.lock();
240
                    try {
241
                        OutputStream os = xml.getOutputStream(l);
242
                        try {
243
                            Convertors.write(os, o);
244
                        } finally {
245
                            os.close();
246
                        }
247
                    } finally {
248
                        l.releaseLock();
249
                    }
250
                }
251
            });
252
        } else {
253
            // Fallback to old-style storage, e.g. .settings with <serialdata>.
254
            InstanceDataObject.create(folder, name, o, null);
255
        }
167
    }
256
    }
168
    
257
    
169
}
258
}
(-)core/registry/src/org/netbeans/core/registry/olddsimpl/ObjectBindings.java (-4 / +1 lines)
Lines 25-39 Link Here
25
import org.netbeans.api.registry.Context;
25
import org.netbeans.api.registry.Context;
26
import org.netbeans.api.registry.ContextException;
26
import org.netbeans.api.registry.ContextException;
27
import org.netbeans.api.registry.ObjectRef;
27
import org.netbeans.api.registry.ObjectRef;
28
import org.netbeans.core.projects.SessionManager;
29
import org.netbeans.core.registry.ContextImpl;
30
import org.netbeans.spi.registry.BasicContext;
28
import org.netbeans.spi.registry.BasicContext;
31
import org.netbeans.spi.registry.SpiUtils;
29
import org.netbeans.spi.registry.SpiUtils;
32
import org.openide.ErrorManager;
30
import org.openide.ErrorManager;
33
import org.openide.filesystems.FileObject;
31
import org.openide.filesystems.FileObject;
34
import org.openide.filesystems.FileSystem;
32
import org.openide.filesystems.FileSystem;
35
import org.openide.loaders.DataFolder;
33
import org.openide.loaders.DataFolder;
36
import org.openide.loaders.InstanceDataObject;
37
34
38
public class ObjectBindings {
35
public class ObjectBindings {
39
36
Lines 198-204 Link Here
198
                    folder.setAttribute(PRIMITIVE_BINDING_PREFIX+name, null);
195
                    folder.setAttribute(PRIMITIVE_BINDING_PREFIX+name, null);
199
                }
196
                }
200
                // and now creating object binding:
197
                // and now creating object binding:
201
                InstanceDataObject.create(dataFolder, name, object, null);
198
                DSUtils.bindObjectToFile(dataFolder, name, object);
202
            }
199
            }
203
        }
200
        }
204
    }
201
    }

Return to bug 36297