public class FileTypeFactory extends ManagedFactory implements TypeProvider
Hashtable
).
Whenever possible, this factory will hand out references to shared instances. Use this if you
need many, many file types objects while running your application and it is
acceptable for you to continously use a certain amount of memory for the cached object. If you
only use instances once then you should either install an object as usual (by calling
new
), or let this factory create a shared instance and flush the factory after
you're finished with the object. The garbage collector will then release memory on-the-fly
as the objects are no longer referenced so the overall memory footprint can be very small.
You can pass either File
or FileObject
objects to be checked here.
A temporary directory with exclusive access is needed to get the system file types for
URLs. Whenever a network resource is processed, a local file is being renamed and the
respective value is requested from the FileSystemView
class.
If a temporary directory is specified then also non-existing local file references can be
checked with this class which is not possible when using FileSystemView
.
Modifier and Type | Field and Description |
---|---|
protected boolean |
caching
Put file data into fast (managed) cache (enabled by default)?
|
protected static FileTypeFactory |
sharedInstance
Shared
FileTypeFactory instance. |
protected java.io.File |
tempdir
Temporary directory to simulate local files (optional).
|
cacheObjectByID
KEY_DISPLAY_NAME, KEY_ICON, KEY_TYPE_DESCRIPTION
Constructor and Description |
---|
FileTypeFactory()
Constructs an instance of this factory.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRelease(java.lang.String id)
Checks whether a factory shared object can be released or not.
|
void |
cleanup(java.lang.String id)
Perform optional cleanup tasks like closing database connections or disposing dialogs.
|
protected java.io.File |
createTemporaryFile(java.lang.Object resource)
Tries to create a local file named after the given resource.
|
java.lang.String |
getDisplayName(java.lang.Object resource)
Provides the display name of the given resource.
|
javax.swing.Icon |
getIcon(java.lang.Object resource)
Provides the icon of the given resource.
|
java.util.Hashtable<java.lang.String,java.lang.Object> |
getInfo(java.lang.Object resource)
Provides the info on the given resource.
|
static FileTypeFactory |
getSharedInstance()
Provides the shared instance of the factory implementation.
|
java.io.File |
getTemporaryDirectory()
Provides the temporary directory..
|
java.lang.String |
getTypeDescription(java.lang.Object resource)
Provides the type description of the given resource.
|
java.lang.Object |
request(java.lang.String id)
Create the factory shared object, recycle if already existing.
|
void |
setCaching(boolean enable)
Enables caching (enabled by default).
|
void |
setTemporaryDirectory(java.io.File tempdir)
Constructor method setting the temporary directory for network file simulation.
|
getRegisteredObjects, hasSharedInstance, release, releaseByStrategy, releaseForced, set
protected static FileTypeFactory sharedInstance
FileTypeFactory
instance.protected java.io.File tempdir
protected boolean caching
public FileTypeFactory()
public static FileTypeFactory getSharedInstance()
public void setTemporaryDirectory(java.io.File tempdir)
tempdir
- Temporary directoryjava.lang.NullPointerException
- Error indicationjava.lang.IllegalArgumentException
- Error indicationpublic java.io.File getTemporaryDirectory()
null
if not availablepublic void setCaching(boolean enable)
enable
- The statepublic java.lang.Object request(java.lang.String id)
setCaching(false)
.
request
in class ManagedFactory
id
- The factory-unique identifier of the shared objectnull
if none could be createdpublic boolean canRelease(java.lang.String id)
canRelease
in class ManagedFactory
id
- The factory-unique identifier of the shared objectpublic void cleanup(java.lang.String id)
cleanup
in class ManagedFactory
id
- The factory-unique identifier of the shared objectprotected java.io.File createTemporaryFile(java.lang.Object resource)
File
and
FileObject
objects.
resource
- The resourcenull
if not availablepublic java.lang.String getDisplayName(java.lang.Object resource)
getDisplayName
in interface TypeProvider
resource
- The resourcenull
if not availablepublic java.lang.String getTypeDescription(java.lang.Object resource)
getTypeDescription
in interface TypeProvider
resource
- The resourcenull
if not availablepublic javax.swing.Icon getIcon(java.lang.Object resource)
getIcon
in interface TypeProvider
resource
- The resourcenull
if not availablepublic java.util.Hashtable<java.lang.String,java.lang.Object> getInfo(java.lang.Object resource)
getInfo
in interface TypeProvider
resource
- The resourceCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.