What is a DataLoader?

As of NetBeans 6.8, it is usually not necessary to implement DataLoader directly - today it is usually an implementation detail of writing file support, and you can simply write a DataObject subclass and register it as follows:

    <folder name="Loaders">
        <folder name="text">
            <folder name="x-foo">
                <folder name="Factories">
                    <file name="FooDataLoader.instance">
                        <attr name="dataObjectClass" stringvalue=""/>
                       <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/>
                        <attr name="mimeType" stringvalue="text/x-foo"/>

This registers the DataObject subclass com.modules.foofile.FooDataObject against the MIME type text/x-foo.

DataLoader Details

DataLoaders are factories for DataObjects. A DataLoader is typically associated with one or more MIME types (such as text/x-java), and is allowed to be the system-wide factory for DataObjects for individual files of that MIME type.

MIME type is typically determined by the file extension, though it can depend on content for things like XML files. (more about how NetBeans recognizes files).

DataLoaders are factories for DataObjects. Typically there is a 1:1 mapping between file-type:DataLoader-subclass and a 1:1 mapping from file:DataObject. When a file is first encountered, and something calls DataObject.find(theFileObject), the correct DataLoader is found and used to asked to create DataObject for that file.

Modules that provide the ability the system to open (or otherwise use) files of a particular type will register DataLoaders for those types. So typically for each file type (as defined by MIME type, which in practice usually means file name extension, or XML subtype) there is a matching DataObject subclass.

Note that DataLoaders do not have to be tied to MIME types — you can still write a DataLoader subclass, registered the old-fashioned way via the JAR manifest, which gets the first chance in the system to claim any file in the system. However this is rarely wise or useful to do.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo