blob: 37d82aef46e4b7e2490119573b2cf5e97ac8b41c [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= DevFaqDataLoader
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqDataLoader
:description: Apache NetBeans wiki DevFaqDataLoader
:toc: left
:toc-title:
:syntax: true
=== 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 link:DevFaqDataObject.asciidoc[DataObject] subclass and register it as follows:
[source,java]
----
<folder name="Loaders">
<folder name="text">
<folder name="x-foo">
<folder name="Factories">
<file name="FooDataLoader.instance">
<attr name="dataObjectClass" stringvalue="com.foo.modules.foofile.FooDataObject"/>
<attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/>
<attr name="mimeType" stringvalue="text/x-foo"/>
</file>
</folder>
</folder>
</folder>
</folder>
----
This registers the DataObject subclass `com.modules.foofile.FooDataObject` against the MIME type `text/x-foo`.
==== DataLoader Details
link:http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/DataLoader.html[DataLoaders] are factories for DataObjects. A DataLoader is typically associated with one or more link:http://en.wikipedia.org/wiki/MIME[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. link:DevFaqFileRecognition.asciidoc[(more about how NetBeans recognizes files)].
DataLoaders are factories for link:DevFaqDataObject.asciidoc[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 [link:http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/DataObject.html#find(org.openide.filesystems.FileObject[http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/DataObject.html#find(org.openide.filesystems.FileObject]) `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 &mdash; 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.
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqDataLoader[http://wiki.netbeans.org/DevFaqDataLoader] ,
that was last modified by NetBeans user Jtulach
on 2010-07-24T19:48:10Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.